Wednesday, March 30, 2011

Find Files

find files from current directory downfind . -name filename
find files from home directory using wildcardsfind ~ -name filenam*

Directory Listing

show subdirectorypwd
list files and directoriesls
list files and directories (one per line)ls -l
list files beginning with 'Adams'ls adams*
list files by screenfulls | more

Delete Files

delete files with promptingrm existingfile

Counts

count files in a directoryls | wc -l filename
count lines fileswc -l filename
count lines words and byteswc filename
count words fileswc -w filename
write a file count to a filels | wc -l > file.ext

Copy / Move

concatenate files together in new filecat oldfile1.ext oldfile2.ext > bothfiles.ext
copy a file and prompt before overwritingcp -i existingfile newfile
copy top # lines of a file to a new filehead -# filename > newfilename
move a file and prompt before overwritingmv -i existingfile newfile

Compare Files and Directories

compare two directoriesdiff /directory1 /directory2
compare two filescmp file1 file2
compare two files and show specific differences-i=ignore case-b=ignore blanks-w=ignore spaces and tabsdiff -iwb file1 file2
compare two files side-by-side| lines are the same< line is in first file only> line is in second file onlysdiff file1 file2
compare two files side-by-side showing only differencessdiff -s file1 file2

Change / Make Directory

make a directorymkdir subdir
change to a subdirectory beneath where you arecd subdir
change to a subdirectory of the rootcd /subdir
change to a subdirectory under your home directorycd ~/subdir
change to home directorycd
change up one levelcd ..