Common shell commands

Author

Jelmer Poelstra

Published

August 4, 2023



Common shell commands and notation

Below is a list of common and useful-for-us Unix shell commands and features.

While it’s not an exhaustive list, getting a grasp on the commands and features above will go a long way in allowing you to work in the Unix shell. We should see nearly all of these in action during our sessions.

They are grouped into some general categories, with small examples between parentheses:

  • Navigating in the Terminal
    • pwd — returns (prints) your working directory
    • cd — change working directory
  • Viewing Files
    • cat — print the entire contents of a file
    • head — print the first lines of a file
    • tail — print the last lines of a file
    • less — view the contents of a file in a “pager” (press q to quit/exit!)
  • Managing/Organizing Files
    • ls — list contents of directory
    • mkdir — create a new directory
    • rm — remove/delete a file or directory
    • cp — copy files/directories to a new location
    • mv — move/rename files/directories to a new location
  • Working With Compressed Files
    • gzip/gunzip — compress/uncompress a file with gzip compression (.gz)
    • unzip — uncompress a zip (.zip) file
    • zcat — print the contents of a compressed file to the screen
  • Assessing Files
    • md5/shasum — check file integrity via “checksums” (fingerprints) for a file
    • grep — search a text file for lines containing a pattern of text
    • wc — return number of lines, words, characters in a file
  • Editing Files (or other data)
    • sort — Sort data, can sort a file by one or more columns (sort metadata/meta.tsv)
    • cut — Select one or more columns from a tabular file (cut -f 1,3 metadata/meta.tsv)
    • uniq — Exclude duplicate entries in a list (cut -f1 metadata/meta.tsv | uniq)
    • tr — Substitute a character (class) for another (echo acgt | tr A-Z a-z)
    • sed — A powerful & flexible command, but most often used to find-and-replace text.
    • awk — A powerful & flexible command, most useful to work with tabular (e.g., CSV, TSV, GFF/GTF) files
  • Miscellaneous
    • wget — download a file from online (wget <URL>)
    • man — get help (manual) for a command (man ls)
  • Special Notation
    • | — The pipe, to use the output of a command as the input for another command (ls | wc -l)
    • ~ — The path to your Home directory (cp data/fastq/* ~)
    • . — Your current working dir (cp data/fastq/* .)
    • .. — One directory up from your current working dir (cd ..)
    • $USER — Your user name (echo $USER)
    • $HOME — The path to your Home directory (echo $HOME)
  • Shell wildcards
    • * — matches any number of any character, including nothing (ls *fastq.gz)
    • ? — matches any single character (ls *fast?)
    • [] — matches a single character of those listed between brackets, e.g. [012] matches 0, 1, or 2
    • [^] — matches a single character not listed between brackets, e.g. [0-9] excludes any numbers


Back to top