Unix Command Cheat Sheet

Basic linux commands you need to know like breathing air

 

Wildcards and special file names

 

The shell has shorthand to refer to groups of files by allowing wildcards in file names. * (asterisk) is the most common; it is a wildcard meaning "any length of any characters". Other useful ones are []to allow for any character in the set <characters>> 

For example: ls *.bam lists all files in the current directory that end in .bam

Three special file names:

  1. . (single period) means "this directory".
  2. .. (two periods) means "directory above current." So ls -l .. means "list contents of the parent directory."
  3.  ~ (tilde) means "my home directory".


The concept of PATH

On a unix command line, you can only access files that are in your current working directory. If you are in /home/dhivya/dinner and you issue the command: 

less lunchMenu

this will work only if lunchMenu is located in /home/dhivya/dinner.

To access files outside your current directory, you can provide the absolute path or relative path to find the file.  If lunchMenu is actually located in  /home/dhivya/lunch, then you can open it by using one of these two commands:

less /home/dhivya/lunch/lunchMenu

(or)

less ../lunch/lunchMenu

Exception: If the location of a file, most often, an executable is included in your shell enviornment variable called PATH, you can run it from anywhere without specifying where it is.  

echo $PATH to see what is in your PATH.

 Always use tab to complete file names. If the file is in the current directory or is in your PATH, tab will do auto complete.

Always remember where you are, on a Unix enviornment!

 

So many options...

When running scripts and software tools, all the inputs you provide to it are called arguments or parameters or options.  Each tool/script can be a little different in how it takes its arguments. But typically, they follow a structure.

command <options>  inputfile > outputfile

command  -option1 value1 -option2 value2 -option3 inputfile > outputfile

Example: blastp -query scaffolds.fasta -db TAIR10_pep_20101214 -eval 0.0001 -outfmt 6 -out blastp.out

If you need to find out the options for a command, try any of these (again each tool is different):

 

.bash_profile, .profile files

A startup script that gets executed every time a session is started interactively. You can put any command in that file that you could type at the command prompt. Put commands here to set up your particular environment, and to customize things to your preferences (such as paths, aliases, modules to load).

 

BACK TO THE COURSE OUTLINE