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. For Windows users, navigating around your directories (folders) and managing your files must be done with commands. The table below contains the basic Linux commands you will need to know to use the CSF.

Commands specific to the batch system (not a default part of Linux) are covered in other parts of our documentation. Other useful Linux commands may also be mentioned elsewhere.

Commands Description
Terminology 1: Directory (or dir)
Terminology 2: Home directory (or home)
Linux directories are the same as Windows folders.
Your private directory similar to My Documents. It is also the directory you start in upon login.
cd dir1
cd ~/dir1/dir2
cd ~/scratch
cd ..
cd
Change directory (go into dir1 which is located in the current dir).
Go into dir2 in dir1 in your home dir (~ is shorthand for home)
Go into your scratch directory (CSF-specific)
Go up to parent directory (e.g., from ~/dir1/dir2 to ~/dir1)
Go back to home (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
mkdir dirA
mkdir -p dirA/dirB/dirC
Make directory named dirA (in the current directory)
Make directory tree dirA/dirB/dirC (dirB inside dirA …) including dirs that don’t already exist
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
rm -rf dir1 Delete directory and all files (and other sub-dirs) in there (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.
Press space to page down through a long file
Press return to scroll down a line at a time
Press b to scroll back up a page
Press G to go to end of file
Press 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 programs
on 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

Last modified on July 10, 2024 at 11:20 am by George Leaver