Linux Command Line 备忘

1. 如果要删除目录,

rmdir or rm -d 或许可以删除空目录,但是只有
rm -R 可以把目录以及其内容连带删除!

2. 查看文件大小:

ls -l --block-size=G 还可以换成MB
#or 
ls -lh

3. mac中使用sudo user:

sudo -s
然后输入你的用户密码(不是master code)即可!

4. 截取部分文件

截取行: head -100 file.txt > top_100_row.txt 同理可用tail截取  还可使用grep进行行的选择

截取列: cut -f1-10 -d',' file.txt > top_10_column.txt

 5. 查找文件中是否含有某字符串

#查找目录下的所有文件中是否含有某个字符串 
find .|xargs grep -ri "IBM" 
#查找目录下的所有文件中是否含有某个字符串,并且只打印出文件名 
find .|xargs grep -ri "IBM" -l 
#or 
find ./ -name "IBM"
#Ref:http://blog.sina.com.cn/s/blog_691a84f301015khx.html

6. Export path

export PATH=/Volumes/Macintosh_HD_2/Programs/samtools-0.1.19/misc/:$PATH
#you can now type directly on the terminal "samtools"

 7. comm 命令

#找出两个文件不同的地方:
comm -23 <(sort a) <(sort b)
#注意这里的“<“。这个符号是”using a file as standard input"
#i.e. cat xyz.txt 和 cat < xyz.txt 效果是一样的

8. sed command

 

#to delete the 3rd line of a file
sed '3d' fileName.txt
#to select several lines of a file
sed -n '320123,320150'p filename

9. less command

less text.txt 
#then, just type 
450g
#you can find the 450th line

 

 

 

 

posted on 2013-08-07 08:14  Forever_YCC  阅读(278)  评论(0编辑  收藏  举报

导航