ls -l filename 列出文件rwx權(quán)限
du -h . disk use helper - 列出各個(gè)文件大小
ls -ltr list all files by modification time, sorting(t) reverse(r)
/ – search for a pattern which will take you to the next occurrence.
find folder/ -name aaa.txt Find files. You can use regex after -name.
find folder/ -type f Find all files.
find folder/ -type d File all dirs.
用簡(jiǎn)單的unix command,可以進(jìn)行一些data processing的工作。這里邊的設(shè)計(jì)哲學(xué),可以看作mapreduce的前身。
awk(=filter and print)
awk '{print $7}' file.txt | # 將file.txt里的語(yǔ)句分割,并取出第7項(xiàng)
sort | # 排序
uniq -c | # 去重,并打印出每個(gè)record的計(jì)數(shù)
sort -r -n | # 反向排序,其中-n表示以每個(gè)record開頭的數(shù)字來進(jìn)行排序
head -n 5 # 只輸出前五項(xiàng)
awk '{print length($1), $2}' text1.txt # print the len of first and second columns with whitespace as delimiter
$(NF-1) # the second last column
awk `NR==2, NR==5 {print $0}` text1.txt # get the second to fifth row
awk `NR==2; NR==5 {print $0}` text1.txt # get the second and fifth row
awk -F ";" '{print $1}' a.txt # change delimiter(field) to ;
awk '$2~/usa|italian/ {print $2, $4}' a.txt # // is regex. $2~ only looks in the second column.
awk '$1==$3 {print}' a.txt # search first and third column the same
sed
grep(=search)
grep -i so a.txt # search for case insensitive occurrences of "so" in a.txt
ls | grep t # search for all files with word "t"
ls | grep -v t # search for all files without word "t"