Skip to content

Latest commit

 

History

History
221 lines (178 loc) · 5.41 KB

File metadata and controls

221 lines (178 loc) · 5.41 KB

Command Line I

Huitian (Yolanda) Diao

Reference: Wiley Linux Command Line and Shell Scripting Bible

Command line

Concepts

  1. Shell

    A shell is a user interface for access to an operating system's services. System structure

    Sometimes. But not always. There is a ghost in the shell.

    Ghost in the shell

  2. Bash

    Bash is a shell for Unix/Linux system. It is a replacement of Bourne shell developed for GNU project GNU project.

  3. 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.

Starting with the shell

  1. Launching shell

    Mac/Linux system: Use Terminal

    Windows system: Install Linux

  2. Terminal interface

    1. The Shell Prompt
    ~ yolandatiao$
    
    1. Command strucutre
    [command] [options] [arguments]
    cat -n test.fasta
    
    1. Bash manual
    $ man bash
    
  3. 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! You can google it

Nevigating file system

  1. cd: change directory

    1. Absolute filepath
    cd /usr/lib
    cd documents # a folder named "documents" in current directory
    
    1. Relative filepath
    cd . # current directory
    cd .. # parent directory
    cd ~ # home directory
    
  2. pwd: display current working directory

    pwd
    
  3. ls: file listing

    ls # basic listing
    ls -F # distinguish files from directories
    ls -a # show hidden folders
    man ls # Read the manual of ls
    

File handling

  1. touch: creating file

    touch test.txt # Create a file named "test.txt"
    man touch # Manual of touch
    
  2. cp: copying file

    touch test1.txt
    cp test1.txt test2.txt
    cp -R dir1 dir2 # Copy the whole directory
    man cp # Manual of cp
    
  3. 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
    
  4. 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
    

Directory handling

  1. mkdir: creating directories

  2. 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
    

View file contents

  1. stat: status of file

    stat test.fasta
    
  2. file: type of file

    file test.fasta
    
  3. cat: display all data of file

    cat test.fasta
    
  4. less: display data by page (versus cat command which read the entire file)

    cat Tumor_lib.fasta
    less Tumor_lib.fasta
    man less
    
  5. tail head: display last / first group of data in file

    tail Tumor_lib.fasta
    head Tumor_lib.fasta
    
  6. wc: word count

    wc test.fasta
    wc -l Tumor_lib.fasta
    man wc
    

Advanced file viewing

  1. grep: Regular expression search

    grep "German" painters.txt
    
  2. *: wildcard, a character that represents other characters

    ls *.txt
    
  3. sort: Sort contents of a text file line by line

    sort painters.txt
    sort painters.txt > painters_sorted.txt
    man sort
    
  4. uniq: reports or filters out repeated files

    sort painters_A.txt > painters_A_sorted.txt
    uniq -c painters_A_sorted.txt
    man uniq
    

Using cheatsheet is never cheating. It is smart

Practice for Command Line I

  1. Go to the folder documents and create a folder yourname_wk1_homework
  2. Copy Tumor_lib.fasta, test.fasta and folder Art to the folder you created
  3. Redirect to the folder Art under your new folder and find out how many files are in the folder
  4. Rename Tumor_lib.fasta to tumorLib.fasta
  5. Count how many lines there are tumorLib.fasta
  6. Display content of ClaudeMonet.txt
  7. Find out how many lines contain "Baroque" in painters.txt
  8. For test.fasta, find out how many unique lines there are; and for repeating lines how many times each line repeats in test.fasta