Linux Useful Commands I'm Unfami

2019-05-10  本文已影响0人  __小赤佬__

ls -l filename 列出文件rwx权限
du -h . disk use helper - 列出各个文件大小
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.

用简单的unix command,可以进行一些data processing的工作。这里边的设计哲学,可以看作mapreduce的前身。

awk(=filter and print)
awk '{print $7}' file.txt |  # 将file.txt里的语句分割,并取出第7项
sort | # 排序
uniq -c | # 去重,并打印出每个record的计数
sort -r -n | # 反向排序,其中-n表示以每个record开头的数字来进行排序
head -n 5 # 只输出前五项

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"
sort
uniq
xargs

Reference:

上一篇下一篇

猜你喜欢

热点阅读