Unix Command Cheat Sheet
...
ls
- list the contents of the current directorypwd
- print the present working directory - tells you where you are currently. The format is something like/home/myID
- just like on most computer systems, this represents leaves on the tree of the file system structure, also called a "path".cd <whereto>
- change the present working directory to<whereto>
You will need to provide a path like /work/myID to change to that directory.- Some special
<wheretos>
:..
(period, period) means "up one level". . means current directory. ~ (tilde) means "my home directory".~myfriend
(tilde "myfriend) means "myfriend's home directory".
- Some special
nano - The text editor we'll be using
df
shows you the top level of the directory structure of the system you're working on, along with how much disk space is availablehead <file>
andtail <file>
shows you the top or bottom 10 lines of a file<file>
more <file>
andless <file>
both display the contents of<file>
in nice ways. Read the bit above aboutman
to figure out how to navigate and search when usingless
file <file>
tells you what kind of file<file>
is.cat <file>
outputs all the contents of<file>
- CAUTION - only use on small files.rm <file>
deletes a file. This is permanent - not a "trash can" deletion.cp <source> <destination>
copies the filesource
to the location and/or file namedestination
}. Using.
(period) means "here, with the same name". *cp -r <dirname> <destination>
will recursively copy the directorydirname
and all its contents to the directorydestination
.scp <user>@<host>:<source> <destination>
works just like cp but copiessource
from the useruser
's directory on remote machinehost
to the local filedestination
mkdir <dirname>
andrmdir <dirname>
make and remove the directory "dirname". This only removes empty directories - "rm -r <dirname>" will remove everything.wget <url>
fetches a file with a valid URL. It's not that common but we'll usewget
to pull data from one of TACC's web-based storage devices.- man <unixcommand> displays the manual page for a unix command.
- > is used to redirect STDOUT and STDERR to files.
...
.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).
File Editors
There are a number of options for editing files at TACC. These fall into three categories:
- Linux text editors installed at TACC (nano, vi, emacs). These run in your terminal window. vi and emacs are extremely powerful but also quite complex, so nano may be the best choice as a first local text editor.
- Text editors or IDEs that run on your local computer but have an SFTP (secure FTP) interface that lets you connect to a remote computer (Notepad++ or Komodo Edit). Once you connect to the remote host, you can navigate its directory structure and edit files. When you open a file, its contents are brought over the network into the text editor's edit window, then saved back when you save the file.
- Software that will allow you to mount your home directory on TACC as if it were a normal disk e.g. MacFuse/MacFusion for Mac, or ExpanDrive for Windows or Mac ($$, but free trial). Then, you can use any text editor to open files and copy them to your computer with the usual drag-drop.
As we will be using nano throughout the class, it is a good idea to review some of the basics. nano is a very simple editor available on most Linux systems. If you are able to use ssh, you can use nano. To invoke it, just type:
...
nano (or)
nano <filename>
You'll see a short menu of operations at the bottom of the terminal window. The most important are:
- ctl-o - write out the file
- ctl-x - exit nano
You can just type in text, and navigate around using arrow keys. A couple of other navigation shortcuts: - ctl-a - go to start of line
- ctl-e - go to end of line
...
- Case matters: directory named BioITeam is different from directory named bioiteam.
- Do not use white spaces in file names: Though you may be tempted to name your directory my raw data, such naming makes sense when you are looking at the directory visually on your mac finder or windows explorer, but in command line, space means next option. So, mkdir my raw data will actually make 3 directories: my, raw, and data. Use uppercase, or underscores instead of white spaces like my_raw_data.
- Be careful with using special characters : Typically, underscores,dashes, periods are ok in filenames. But avoid, punctuations and other such special characters. A directory called sarah's raw data would be a bad idea.
BACK TO THE COURSE OUTLINE