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.
Navigating Filesystems
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 String | Description |
---|---|
/ | The root directory, absolute "highest" level |
./ | The current directory |
../ | The directory one level higher than the current one |
~/ | The home directory |
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 tutorialEverything you can do in Mac's Finder, you should be able to do in the command line.
Command | Description | useful flags |
---|---|---|
pwd | “Print working directory” (where am i?) | |
cd | “change directory” (move between directories) | |
ls | List directory contents | -alSt |
mv | Move item/s | |
rm | Remove item/s | -r |
cp | Copy item/s | |
less | view contents of file on the command line | -S |
wc | “word count" | -l |
echo | print a string/variable |
If you get stuck, run man <Command>
to view usage and help options
Level 2-Basic File manipulation (Excel-like stuff)
Command | Description | useful flags |
---|---|---|
cat | ||
head | -n | |
tail | -n | |
cut | -df | |
paste | ||
sort | -nrk | |
uniq | -c |
Level 3-Search & more elaborate File manipulation (Excel-like stuff)
Command | Description | useful flags |
---|---|---|
sed | powerful and flexible file manipulation: global search and replace, stripping headers, etc | -i |
grep | search a file for strings or regex patterns Read More | -nfo |
awk | file manipulation - good for reordering columns or filtering on values | -F |
(Shift-\ , "pipe") | ||
> | ||
>> |