Linux Commands
The CSF runs the Linux operating system. Interaction with the system is done by typing commands into a terminal program. This can be a little daunting at first. The table below contains the basic Linux commands you will likely use on the CSF.
It is worth remembering that when you login to the CSF, the folder you will be first in is your home directory (Windows users can think of this as similar to “My Documents”.) The home directory is private to you and where you should keep important files (it is backed-up storage).
The other useful thing is that the Linux term directory is what Windows users call a folder when talking about storage.
Commands specific to the batch system (not a default part of Linux) are covered in other sections of our documentation. Other useful Linux commands may also be mentioned elsewhere.
| Commands | Description | 
|---|---|
| cd dir1cd ~/dir1/dir2cd ~/scratchcd ..cd | Change directory (go into dir1which is located inside the current dir).Go into dir2indir1in home (~is shorthand forGo into your scratch directory (CSF-specific) Go up to parent directory (e.g., from ~/dir1/dir2to~/dir1)Go back to your home directory from where ever you currently are (useful if you become lost) | 
| pwd | Lost? Print Working Directory (display your current location – the folder you are currently working in) | 
| lsls -lhls -lh file1 dirAls -lh dirA/*.dat | List content (names of files and directories) of current directory List in long form (dates, file sizes, names) current directory List in long form (dates, file sizes, names) specified files, directories … List in long form all files ending in .datin directorydirA(note that the -lin these commands is a lower-case letter L (not a number one) | 
| cp fileA fileBcp fileA dirAcp fileA ~/scratch | Copy (duplicate) a file (copy fileAto a new filefileB)Copy (duplicate) a file into the directory named dirACopy (duplicate) a file into your scratch directory (CSF-specific) | 
| mv fileC fileDmv fileE dirAmv fileF dirA/fileG | Rename a file (from fileCtofileD). Works for directories too.Move fileEinto sub-directorydirA(dirAmust exist)Move fileFAND rename it all in one go (dirAmust exist) | 
| rm fileHrm dirA/fileB | Delete (remove) a file (caution!!) Delete (remove) a file named fileBfromdirA | 
| mkdir dirAmkdir -p dirA/dirB/dirC | Create (make) a new folder named dirAin current location (don’t use spaces in folder names!)Create (make) a tree of folders starting at current location | 
| rmdir dirA | Delete (remove) an empty directory. | 
| rm -rf dir1 | Delete a directory and all files and other directories in there, down the entire tree (caution!!!!!) | 
| gzip bigfilegunzip bigfile.gz | Compress a file (becomes bigfile.gz) to make better use of diskspace. Text files usually compress well.Uncompress previously compressed file (becomes bigfile). | 
| less file1zless file2.gz | Display the content of file1(text file) a page at a time on screen.If you’ve compressed file2withgzip, no need to uncompress first.Both commands accept the following keystrokes to navigate: Press spaceto page down through a long filePress returnto scroll down a line at a timePress bto scroll back up a pagePress Gto go to end of filePress qto quit/exit | 
| cat file1zcat file2.gz | Dump entire file to screen (a quick way to look at text files). If you’ve compress file2withgzip, no need to uncompress first. | 
| gedit file1
 | Edit file1using a simple graphical text editor (similar to notepad on Windows). Make sure you have logged in enabling the ability to open graphical programson the CSF so that they display a window on your computer. | 
| file filenameA | Try to tell us what type of data is in filenameA. Useful to determine the output of some program where you are not sure what type of output it has generated. For example:file output.datMight be ASCII text(so we can look at it withlessorgedit)or might be data(you'll need some other program to read it) | 
| du -sh . | How much disk space is current directory (all files and subdirs) using? | 
| df -h . | How much free space is there in the current area? | 
Further Information
If you would like to learn more we recommend the following training materials
- Research IT occasionally run an Introduction to the Unix Shell course, see the courses page for info and a link to booking and materials.
- Beginners guide to UNIX/Linux (University of Bristol)
