Huitian (Yolanda) Diao
Reference: Wiley Linux Command Line and Shell Scripting Bible
-
Shell
A shell is a user interface for access to an operating system's services.
Sometimes. But not always. There is a ghost in the shell.
-
Bash
Bash is a shell for Unix/Linux system. It is a replacement of Bourne shell developed for GNU project GNU project.
-
Command-line interface
An interface where user interacts with system with commands (text), in contrast with GUI interface (GUI) where user interacts with sytem through graphical icons.
-
Launching shell
Mac/Linux system: Use Terminal
Windows system: Install Linux
-
Terminal interface
- The Shell Prompt
~ yolandatiao$
- Command strucutre
[command] [options] [arguments] cat -n test.fasta
- Bash manual
$ man bash
-
Self-help with bash By using man you can check the manual of commands. Try it with the commands we are going to learn later! Also, don't forget to use Google. Always Google before asking. JUST GOOGLE IT!
-
cd: change directory
- Absolute filepath
cd /usr/lib cd documents # a folder named "documents" in current directory
- Relative filepath
cd . # current directory cd .. # parent directory cd ~ # home directory
-
pwd: display current working directory
pwd
-
ls: file listing
ls # basic listing ls -F # distinguish files from directories ls -a # show hidden folders man ls # Read the manual of ls
-
touch: creating file
touch test.txt # Create a file named "test.txt" man touch # Manual of touch
-
cp: copying file
touch test1.txt cp test1.txt test2.txt cp -R dir1 dir2 # Copy the whole directory man cp # Manual of cp
-
mv: renaming file / move file.
mv test2.txt test3.txt # Rename test2.txt to test3.txt mv dir2 dir4 # Rename directory dir2 to dir4 mv test3.txt dir2 # Move test3.txt to directory dir2 man mv
-
rm: deleting file
rm test1.txt rm -i test.txt man rm
Once file is removed, it can not be recovered. Safer option:
mv test1.txt Trash # Move file to Trash folder
-
mkdir: creating directories
-
rmdir: deleting directories
mkdir newdir rmdir newdir
What is directory is not empty?
mkdir newdir1 cd newdir1 touch file1 touch file2 mkdir subdir1 cd .. rmdir newdir1 rm newdir1
Try other methods
rm -r newdir1 rm -rf newdir1
-
stat: status of file
stat test.fasta
-
file: type of file
file test.fasta
-
cat: display all data of file
cat test.fasta
-
less: display data by page (versus cat command which read the entire file)
cat Tumor_lib.fasta less Tumor_lib.fasta man less
-
tail head: display last / first group of data in file
tail Tumor_lib.fasta head Tumor_lib.fasta
-
wc: word count
wc test.fasta wc -l Tumor_lib.fasta man wc
-
grep: Regular expression search
grep "German" painters.txt
-
*: wildcard, a character that represents other characters
ls *.txt
-
sort: Sort contents of a text file line by line
sort painters.txt sort painters.txt > painters_sorted.txt man sort
-
uniq: reports or filters out repeated files
sort painters_A.txt > painters_A_sorted.txt uniq -c painters_A_sorted.txt man uniq
- Go to the folder documents and create a folder yourname_wk1_homework
- Copy Tumor_lib.fasta, test.fasta and folder Art to the folder you created
- Redirect to the folder Art under your new folder and find out how many files are in the folder
- Rename Tumor_lib.fasta to tumorLib.fasta
- Count how many lines there are tumorLib.fasta
- Display content of ClaudeMonet.txt
- Find out how many lines contain "Baroque" in painters.txt
- For test.fasta, find out how many unique lines there are; and for repeating lines how many times each line repeats in test.fasta