Skip to main content

Command Line Basics

You don't need to be a command line expert to perform bioinformatic analyses but there are some basic navigation commands you should know.

When working from the terminal, you "move" around the filesystem in and out of folders/directories. Every file or folder/directory has an address. You can navigate and find things using these addresses/directions using what are called "file paths".

File Path StringDescription
/The root directory, absolute "highest" level
./The current directory
../The directory one level higher than the current one
~/The home directory
Tutorial on Filepaths

You should know the difference between absolute vs relative file paths and file path syntax well enough that you can understand the differences between the following paths:

/path/to/dir
path/to/dir
~/path/to/dir
../path/to/dir
./path/to/dir

Editing files

Sometimes when working on remote servers, we need to be able to do some basic file editing. Since not all GUI-based text editors can do this, it is useful to know how to do this through the command line. Check out one of the popular editors (e.g. vim, emacs, nano)

Useful Shell/GNU commands for biochemists to know

Level 1 - Finder/File navigation

Level 1 shell tutorial

Everything you can do in Mac's Finder, you should be able to do in the command line.

CommandDescriptionuseful flags
pwdPrint working directory” (where am i?)
cdchange directory” (move between directories)
lsList directory contents-alSt
mvMove item/s
rmRemove item/s-r
cpCopy item/s
lessview contents of file on the command line-S
wc“word count"-l
echoprint a string/variable
tip

If you get stuck, run man <Command> to view usage and help options

Level 2-Basic File manipulation (Excel-like stuff)

CommandDescriptionuseful flags
cat
head-n
tail-n
cut-df
paste
sort-nrk
uniq-c

Level 3-Search & more elaborate File manipulation (Excel-like stuff)

CommandDescriptionuseful flags
sedpowerful and flexible file manipulation: global search and replace, stripping headers, etc-i
grepsearch a file for strings or regex patterns Read More-nfo
awkfile manipulation - good for reordering columns or filtering on values-F
(Shift-\, "pipe")
>
>>