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 dir1 cd ~/dir1/dir2 cd ~/scratch cd .. cd
|
Change directory (go into dir1 which is located inside the current dir).Go into dir2 in dir1 in home (~ is shorthand for Go into your scratch directory (CSF-specific) Go up to parent directory (e.g., from ~/dir1/dir2 to ~/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) |
ls ls -lh ls -lh file1 dirA ls -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 .dat in directory dirA (note that the -l in these commands is a lower-case letter L (not a number one)
|
cp fileA fileB cp fileA dirA cp fileA ~/scratch
|
Copy (duplicate) a file (copy fileA to a new file fileB )Copy (duplicate) a file into the directory named dirA Copy (duplicate) a file into your scratch directory (CSF-specific) |
mv fileC fileD mv fileE dirA mv fileF dirA/fileG
|
Rename a file (from fileC to fileD ). Works for directories too.Move fileE into sub-directory dirA (dirA must exist)Move fileF AND rename it all in one go (dirA must exist)
|
rm fileH rm dirA/fileB
|
Delete (remove) a file (caution!!) Delete (remove) a file named fileB from dirA
|
mkdir dirA mkdir -p dirA/dirB/dirC
|
Create (make) a new folder named dirA in 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 bigfile gunzip 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 file1 zless file2.gz
|
Display the content of file1 (text file) a page at a time on screen.If you’ve compressed file2 with gzip , no need to uncompress first.Both commands accept the following keystrokes to navigate: Press space to page down through a long filePress return to scroll down a line at a timePress b to scroll back up a pagePress G to go to end of filePress q to quit/exit
|
cat file1 zcat file2.gz
|
Dump entire file to screen (a quick way to look at text files). If you’ve compress file2 with gzip , no need to uncompress first.
|
gedit file1
|
Edit file1 using 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.dat Might be ASCII text (so we can look at it with less or gedit )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
- IT Services online Intro to Unix/Linux course
- 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)