UNIX Cheat Sheet

Contents:

Also see UNIX directories and files - a quick introduction.

Another complete tutorial is online here: http://www.ee.surrey.ac.uk/Teaching/Unix/index.html

Working at the command line

Use Tab for filename completion: start a filename, and then hit <Tab> to finish it.

Use arrow keys for command line history and editing: up/down arrows will move you through commands you’ve run, and left/right arrows (plus backspace etc.) let you edit those commands.

Looking at text files

‘head’ and ‘tail’ will display at the first 10 or last 10 lines of a text file, respectively. ‘head -20’ will display at the top 20 lines.

‘less’ will let you page through output. ‘q’ exits from ‘less’ before the end of the file.

Enabling access for other people

Warning, this is dangerous; the ‘root’ account has complete control over your machine!

You can give other people access to your EC2 machine by setting a password for the ‘root’ account:

%% passwd root

You can also give them access to some or all your EC2 machines by giving them your private key, but this is a really bad idea.

A less dangerous way to do access control is to have them, or you, create a public/private key pair by doing:

%% ssh-keygen -t dsa -f new_key

Then add ‘new_key.pub’ to /root/.ssh/authorized_keys:

%% cat new_key.pub >> /root/.ssh/authorized_keys

and give them the ‘new_key’ file as their private key to log into this EC2 machine only.

Long running jobs

Use ‘top’ to keep track of what jobs are running on your machine, either under your current login/connection or from previous ones. Type ‘q’ to quit out of top.

The first column in top is the process ID, or PID. It’s usually a 3-5 digit number. You can do:

kill -9 $pid

(replacing $pid with the number) to stop the jobs.

Long running jobs, take 2

A more complicated (but incredibly awesome, useful, and life-changing) way to run jobs is to use ‘screen’.

Install screen:

%% apt-get -y install screen

Run it:

%% screen

Now you have a “virtual” text window manager in which you can run programs and detach from/reattach to the programs.

Run some program, like bowtie or bwa.

Then ‘detach’ from your screen session: hit ‘CTRL-A’ followed by ‘d’.

Now you can log out and everything in the screen will continue to run.

To reattach, log back in and type ‘screen -r’. You will see the program still running and all of the output from it.

If you are running multiple screens, you can do

%% screen -ls

to see how many, and

%% screen -r $num

to reattach to a specific screen session.

Screen also lets you run multiple shells and switch between them, and it has its own copy/paste buffer, etc. So it can get pretty complicated!


LICENSE: This documentation and all textual/graphic site content is licensed under the Creative Commons - 0 License (CC0) -- fork @ github. Presentations (PPT/PDF) and PDFs are the property of their respective owners and are under the terms indicated within the presentation.
comments powered by Disqus