一些有用的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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章