Saturday, January 29, 2011

BASH commands : cat, tac, wc, ls

1. cat --help ; dispalys a file; concatenate file(s) or standard input to standard output
2. tac ; oposite of cat displays a file oposite
3. touch data1 - create a file with 0 byte file
4. nano data1 - utilitar to write data to a file
Example:
cat data1 - dispalys the file data1
cat < data1 - displays the file data1
cat -A data1 - displays all caracters : $-"end of file", ^I-"tab"
cat -s data1 - if the file contains more than one line the "cat -s" displays only one line
nano data1a - creates a file 
cat data1 data1a > data1b - data1 and data1b are concatenated into data1b
tac data1b - prints everithig from behind
5. which cat - /bin/cat - finds the location of cat
6. which tac - /usr/bin/tac
7. cat /var/log/messages | grep MESSAGE- display system messages containing MESSAGE in file 'messages'
8. wc data1 - counts the number of lines, words, characters
9. wc - l data1 - returns the number of lines
Example:
linecount='wc -l fileName';echo $linecount - return the number of lines in the fileName and the fileName it self
wc -l fileName | cut -d ' ' -f position - this is used to retrive only the number, the fileName is deleted using option "-f"
10. ls -ali ; shows everithing in a directory
ls -A | wc -l - retrives the number of files in the directory
ls --help
ls --time=atime -ltr data1 - get the last access time of a file
ls --time=ctime -ltr data1 - get the last modification time of a file

ls -lh file - display the file with the size in mega bytes
watch ls -l file.data - watch how the file grows in time

No comments:

Post a Comment