Thursday, July 24, 2008

Linux command

Edit commands:
  • tr - translate or delete characters eg, "tr [A-Z] [a-z] filename" change all the upper case to lowercase in the file called filename.

Display commands:
  • cut - display specific columns of file. -f specifies field or column, -d specifies field delimiter(Default is TAB), -c cuts by characters. eg: "cut -f3 -d: /etc/passwd" The example passwd file entry is user2:x:501:501::/home/user2:/bin/bash." cut -c4-8 file " will display from the fourth character to the eighth character in each line of the "file".
  • sort - sort text to standard out - original file unchanged. "sort [option] file(s) " Common options: -r Reverses sort to sort descending, -f ignor(fold) case of characters in strings, -u unique(remove duplicate lines in output), -t 'x'-use x as field separator, -n Numeric sort, -k sort from set the field, -K sort using two difference field when there are duplicate in field 1 sort using field 2. eg: sort -t: -k3 -n /et/passwd
Pipes:
  • tee sort command output in a file between pipes. eg: "cut -f1 -d: /etc/passwd | tee cut.out | less"


No comments: