-
cat
: concatenate commandcat filename
: shows content of the filecat file1 file2
: Shows both of the files as one
-
wc
: word countwc -l file
: returns line count of the file
-
less
: you can be page through big file withless
- use
pageup
andpagedown
- use
/
to search for word, hitn
to go through the next matches - use
?
to search for word backward, hitn
to go through the next matches - use
q
to quit less.
- use
-
head
: shows the top of the filehead filename
head -n 3 filename
: shows the first 3 lines of the file
-
tail
: shows the bottom of the filetail filename
tail -n 3 filename
: shows the last 3 lines of the file
-
sed
: to edit filessed -i
: edit files in place- Example:
sed -i '/^#/d;/^$/d' filename
: remove (d) comments and empty lines from file - clean_file function takes the first arugment as the file name
function clean_file { sed -i '/^#/d;/^$/d' $1}
- Example:
-
Comparing Files:
diff
: Compare two files- Example:
diff file1 file2
, show the difference betweenfile1
andfile2
- You can't compare binary files with
diff
- Example:
- We can compare binary files using
checksums
-
Finding Files:
find
: used to fine files- Example:
find /usr/share/doc/ -name '*.pdf'
search recursively forpdf
files - We can execute a commands on found files
find /usr/share/doc/ -name '*.pdf' -exec cp {} . \;
, copiespdf
file found to current dirfind -name '*.pdf' -delete
: delete all found files in the current directory (default dir).
- We can search by file type:
find /etc/ -type l
: Searches for files of type symbolic link
- We can specify level of the search with
-maxdepth
find /etc/ -maxdepth 1 -type l
- We can search by size
find /boot -size +10000k -type f -exec du -h {} \;
: find files bigger than10mb
of regular type and show disk usage in human readable format
- Example: