who
- all users currently logged in to the system
cat
- examine the contents of a file
wc -l
wc -w
wc -c
- get a count of the total number of lines, words, and characters of information contained in a file
cut
cut -cchars file
$ who
root console Feb 24 08:54
steve tty02 Feb 24 12:55
george tty08 Feb 24 09:15
dawn tty10 Feb 24 15:55
$ who | cut -c1-8 Extract the first 8 characters
root
steve
george
dawn
$
$ who | cut -c1-8,18-
root Feb 24 08:54
steve Feb 24 12:55
george Feb 24 09:15
dawn Feb 24 15:55
$
-d and -f options
以-d指定分界符將參數分成多個field,-f指定哪幾個field
不指定分界符,則以tab為分界符
$ cat /etc/passwd
root:*:0:0:The Super User:/:/usr/bin/ksh
cron:*:1:1:Cron Daemon for periodic tasks:/:
bin:*:3:3:The owner of system files:/:
uucp:*:5:5::/usr/spool/uucp:/usr/lib/uucp/uucico
asg:*:6:6:The Owner of Assignable Devices:/:
steve:*:203:100::/users/steve:/usr/bin/ksh
other:*:4:4:Needed by secure program:/:
$ cut -d: -f1 /etc/passwd Extract field 1
root
cron
bin
uucp
asg
steve
other
$ cut -d: -f1,6 /etc/passwd Extract fields 1 and 6
root:/
cron:/
bin:/
uucp:/usr/spool/uucp
asg:/
steve:/users/steve
other:/
$
grep
grep pattern files 搜尋模式串
*, ?都可運用到模式串和檔案名稱
Regex例子:
grep '[A-Z]' list |
Lines from list containing a capital letter |
grep '[0-9]' data |
Lines from data containing a number |
grep '[A-Z]...[0-9]' list |
Lines from list containing five-character patterns that start with a capital letter and end with a digit |
grep '\.pic$' filelist |
Lines from filelist that end in .pic |
grep –i 忽略匹配大小寫
grep -v 找出不匹配模式串的行
grep -l 僅列出包含模式串的檔案
grep -n 額外給出匹配的行號
sort
排序
sort -u 去除重複項
sort -r 逆向排序
sort -o 重新導向到檔案 sort names -o sorted_names 等價於 sort names -o > sorted_names
sort -n 算術排序,而非字元排序
sort +1n 跳過第1個field,然後算術排序
sort -t 指定分界符來分隔field,通常sort +1n這類都預設以space或tab為分隔字元