Example in this note: home/yxf/edu/lecture
The Unix bootcamp
- ls: list of files and directories in home directories
- pwd: Which directory you are working at
- mkdir: make new directory
mkdir edu - cd: change directory A to directory B.
cd edu----change current directory to edu directory - Back to home: cd / (cd /, cd ~ is same)
cd home
cd yxf
or: cd /home/yxf - cd .. : Navigate upward directory
cd edu
pwd: /home/yxf/edu
cd ..
pwd: /home/yxf - Absolute path: No /
Relative path: - manual command: man ls
man cd
man man - rm: remove directories
rm ~/edu/lecture/
rmdir data
cd ..
rmdir lecture - touch: creat new empty file
cd edu
touch heaven.txt
touch earth .txt
ls - mv(1): move file
mkdir temp
mv heaven.txt temp
mv earth.txt temp
ls temp - mv(2): remame file (another function)
tough rags
ls
mv rags temp/riches
ls temp - mv(3): move directories
mv temp temp2
ls temp2 - rm: remove file
cd templs
rm -i earth.txt heaven.txt rags (Function of "i" command-line option is to ask for confirmation) - cp: copy files
touch file1
cp file1 file2 ---in same directory
ls
touch ~/edu/file3
cp ~edu/file3 ~/edu/lecture/ - echo: put text in a file and view it
ecoh "call me king"
call me king
ecoh "call me king" > oening_line.txt
ls
more opening_line.txt-----view content of file - cat: combine multiple files
echo "the primroses were over." >> opening_line.txt
cat opening_line.txt
Data analysis
- Download data online (file name is "SGD_features.tab")
At first make a new directory (lec03) and then download data in new directory - View data
more SGD_features.README - Open stream from data
cat SGD_features.tab - Check how many lines in the file
cat SGD_features.tab | wc -l
"cat SGD_features.tab | wc" or "wc -l SGD_features.tab" will check the number of lines, words and characters - Search desired data:
grep: which lines match a certain pattern
cat SGD_features.tab | grep YAL060W ----Find information on gene YAL060W
cat SGD_features.tab | grep YAL060W --color=always | head ----Highlight the matched pattern - Search data without a given pattern
cat SGD_features.tab | grep -v Dubious | wc -l ---- the number of lines which not contain "Dubious" - Store result in a new file
">" character is redirection
cat SGD_features.tab | grep YAL060W > match.tab - How to select gene
"cut" is used to select certain colimn of gene
cat SGD_features.tab | cut -f 2 | head ----select data of column 2
cat SGD_features.tab | cut -f 2 | grep ORF | wc -l ----how many ORF gene
cat SGD_features.tab | cut -f 2,3,4 | grep ORF | head ----select multiple columns - How many feature types are in this data
Make a new file for this feature type(ORF): cat SGD_features.tab | cut -f 2 > types.txt
?sorting
?unique
Compressed files and directories
- Compressed format
Single file : .gz, .bz, .bz2, .zip
Multiple files: .tar.gz, .tar.bz2 - How to compress or uncompress a file
data: AF086833.fa
compress: gzip AF086833
uncompress: gunzip AF086833.fa.gz - How to compress or uncompress multiple files
data: AF086833.fa, AF086833.gb
Compress format: tar czfv archive-name list-of-files-that-go-into-the-archive
czfv: creat a compressed file in verbose mode
tar czfv sequences.tar.gz AF086833.fa AF086833.gb
Or: tar czvf sequences.tar.gz AF086833.*
Better way: mkdir sequences
mv AF086833.* aequences/
tar czvf sequences.tar.gz sequences/*
管道命令:就是多个命令联用,上一个命令的输出是下一个命令的输入。通俗来讲就是命令A的数据结果就是命令B的输入数据,两个命令之间以管道符“|”连接