一些有用的UNIX命令

你将从这里发现一些有用的UNIX命令,它们将会是你探索下一代测序数据的有力支撑。此外,从这里你还可以发现更多更有用的命令.

直接在命令行处敲这些命令将会详细介绍它们.


clear  or Ctrl-l: clear screen

上下箭头键可以用来浏览之前用过的命令

Ctrl-r 搜索使用过的命令的历史
## Ctrl-r opens this query tool
## start typing part of the command you issued a while back and it will show
## up in the query tool -- I think the history gets deleted after logging out
(reverse-i-search)`':
使用Tab键可以补齐命令,文件名和文件夹

exit or Ctrl-d: 退出Shell


poweroff : 从命令行关机

man : 显示你感兴趣的命令的详细手册
使用空格翻页.q键退出.
man man
## displays the man-page of man ;-)
man ssh
## displays man-page of the ssh client

文件系统相关


这里给出了友好的UNIX文件系统的介绍。阅读  这里  可以大致解释一个典型的Unix文件系统.

cd : 在文件夹之间移动
cd .. : 返回到上一目录. 例如, 如果你在/home/cartwrightlab/desktop 目录并且想返回/home ,那么使用 cd ../..
pwd
/home/cartwrightlab/desktop
cd ../..
pwd
/home
cp : 拷贝文件
cp dir1/foo.txt dir2/
## copies foo.txt from dir1 to dir2
cp -r dir1/ dir2/
## copies dir1 and its contents to dir2
ls : 列出文件夹下所有的内容
ls -l
## list files with detailed info
ls -a
## show all files including hidden files
ls -lh
## show a list of files including their sizes in human readable form
ls -lha
## well...
mkdir : make a new directory
mkdir foo
## makes directory foo
mv : 移动文件或重命名文件
mv foo.txt newdirectory/foo.txt
## moves foo.txt into newdirectory
mv foo.txt cat.txt
## renames foo.txt to cat.txt
 
rename : 根据正则表达式对多个文件重命名  regular expression  表示重命名的规则
rename 's/\.txt$/\.fasta/' *
## changes the file extension for all files (*) in a directory from .txt to .fasta
rm : 删除文件或文件夹
rm foo.txt
## delete foo.txt
rm -r foo
## delete the directory foo and its contents
find : 搜索文件 --  这里  有一个极好的教程介绍如何很好地使用这个强大的命令
find /home/user -name pattern
## searches for files in /home/user that match the pattern
df : 汇报磁盘系统使用情况
df -h
## reports the size, used space, and available
## space of every device available on the system
##
## useful if you want to know how much space you
## have left to work with -- Can I really extract this tarball?!
du : 估计特定文件夹下的内容占据的空间大小
du -h /home/user
## estimates the size of the user's home directory
## and the contained directories
##
## can be used to estimate the size of any directory
pwd : 打印你所处的路径

注意: 你处理文件的所有命令都假设你在该文件夹内. 如果不是的话, 你可以使用相对路径. 例如: 你的文件 (file_1.txt)在文件夹 home/cartwrightlab/Documents/TruSeq/ 下, 而你在另一个文件夹下工作 home/cartwrightlab/Documents, 如果你要想重命名 file_1 而不离开你目前的文件夹的话, 你该使用如下命令:
mv TruSeq/file_1.txt TruSeq/newfile_1.txt
注意, 你并不需要输入完整的路径,因为TruSeq 是Documents的子目录.

挂载

mount : 挂载一个设备

一个设备可以是一个硬盘. 设备一般在目录/dev下都可找到. 然而,不同系统之间的名字有所不同. 比如 /dev/sdb1 是你刚插入到电脑的USB驱动器. 你将它挂载到/mnt文件夹, 可通过如下命令:
mount /dev/sdb1 /mnt
umount : 卸载文件系统

为了将刚才挂载的驱动器卸载, 你需要使用如下命令. 然而,这个过程会长一些, 因为可能还有数据没有写入呢!
umount /mnt

和文本文件打交道

处理文本文件的额外信息可以参考  Editing text files .

less : 将文件内容打印到标准输出; 你当然可以像man命令那样搜索模式
less foo.txt
head : 将文件的前10行打印到标准输出,对于大文件很有用
head foo.txt
只打印前5行的话:
head -n 5 foo.txt
tail : 将文件的最后10行打印到标准输出
tail foo.txt
只打印最后5行的话:
tail -n 5 foo.txt
nano : 很容易使用的文本编辑器
然而Nano处理大文件并不合适, 详细的编辑大文件的方法可参考:  post .
nano foo.txt
cat连接文本并打印到标准输出,或重定向到另一文件
cat foo.txt
## dump foo.txt to standard out (the screen)
cat foo1.txt foo2.txt foo3.txt > foo_combined.txt
## dump foo1.txt through foo3.txt to another file
cat *.txt > combined.txt

## dump all text files in current directory to another file
grep : 在文件内搜索符合模式的内容 -- 返回满足模式的行
## Simple pattern matching and full-fledged support for regular expressions.
## There are tons of how-to's on the web.
grep pattern foo.txt
## basic usage to look for pattern in file foo.txt
cat foo.txt | grep pattern
## same as above using cat and a pipe (see I/O Redirection)
cat *.txt | grep pattern
## search for a pattern in all text files in the present directory
uniq : 报告或省略重复的行
cat foo.txt | uniq > foo-filtered.txt
## only retain uniq lines in foo.txt and save these in
## foo-filtered.txt
##
## think about filtering out duplicate sequences etc.
vi : 强大的文本编辑器,但学习起来很不容易. 那为什么还要学习vi呢? 因为任何新安装Unix或Linux的电脑上都有它 .

wc : 统计一个文件的行数,字数和字节数
wc -l foo.txt
## counts the number of lines in foo.txt
cat foo.txt | wc -l
## same as above using a pipe (see I/O Redirection)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值