Last updated: September 11, 2024
This repository is available at bit.ly/ufit-rc_linux 
This version of the training module assumes that you have a HiPerGator account.
If you do not have a HiPerGator account, it is probably better to use this repository which allows GitHub Codespaces access.
Click the Zoom logo to view a recording of a training session using this material: 
- File paths (directories or folders):
/,/home/username/,/blue/group/usernameIn this documentation, we will use the convention of putting text that needs to be substituted for your specific case in italic font. So, you would use your username (your GatorLink for UF users), where the directions show username.
pwd,cd,ls(Where am I, change directory, list directory)cp,mv,rm(copy, move (also used for rename), delete)more,less,head,tail,cat(examine files)nano(text editor in Linux)
Note that most things in Linux are case-sensitive. This applies to commands and file names. e.g.
CD testwill not work to change directories to the "test" folder, whilecd testwill work (assuming there is a folder named "test" in the current folder). Similarly,Testandtestare different folders or files.
- Tab completion: type part of a path or file name and hit tab-key, the shell will auto-complete for you.
Note that this may not work for the group directories in
/blue/since directories are automounted, meaning that they may not show up, or be able to be tab-completed, until you access the directory. - Tab completion when there are multiple options: if there are multiple potential completions, hitting the tab-key twice will show you the options.
history: redo something that you did before without retyping (you can also use the ⬆️ arrow key)man: getting help. Many built-in Linux applications have manual pages that document their use and options. e.g.man lswill bring up the page for thelscommand, documenting the many options that change how thelscommand functions.- Another way to get help information about an application is using the application's name followed by either the
-hor--helpflags. Many applications use this convention to provide documentation to users.
- Another way to get help information about an application is using the application's name followed by either the
- Navigation shortcuts:
cd ~or justcdtakes you to your home directorycd -takes you to your previous directorycd ..takes you up one directory level (to the parent directory).is the current directory..is the parent directory, one level up
(Note: some of the data and examples are taken from software-carpentry.org):
-
How to connect to HiPerGator from a terminal other than the web-based terminal in the HiPerGator portal:
- Mac:
ssh username@hpg.rc.ufl.edu(Remember username should be substituted with your username)For additional help, watch the video tutorial on logging in with from a Mac

- Windows:
ssh username@hpg.rc.ufl.edu(Remember username should be substituted with your username)For additional help, watch the video tutorial on logging in with from Windows

- Note that on both Mac and Windows, when you are typing your password, no characters display while you type. Just keep typing, and hit Enter, and you should be logged in.
- Mac:
-
Where are you when you log in?
pwd -
What files are there?
ls -
At Research Computing, we ask that users keep most of their data in their group's
/blue/group/folder. Let’s change directories there:cd /blue/group/username-
You can see your primary group by typing the
idcommand:[userA@login2 ~]$ id uid=10856(userA) gid=1234(mygroup) groups=1234(mygroup),1235(othergroup)In the output of the
idcommand, you can see your primary group after thegid=, in this example,mygroup. Other groups, referred to as secondary groups are listed after that in thegroups=section, showing that this user is also in theothergroup.
-
-
Let’s make a directory to put some data:
mkdir cli_demo- When naming files and directories, avoid spaces and special characters. Use underscores (
_), dashes (-) or camelCase instead of spaces.
- When naming files and directories, avoid spaces and special characters. Use underscores (
-
Now, what’s there?
ls -l. The-lflag gives a "long listing" with more information.- Linux commands usually have flags to change how they work
man,-hor--helpoften give you help- You can and should also use documentation on the web for more information about commands and their options
-
Change into cli_demo directory:
cd cli_demoorcd cl-Tab-key -
Copy some demo data here (
.):cp -r /data/training/LinuxCLI/molecules .- Note the
-rto recursively copy, sincecpwon’t copy directories by default. - Also note the “
.” at the end of the command. In Linux, "." is short for the current location.The
moleculesfolder of files is also available in this repository atdata/molecules. This folder originated from the software-carpentry Shell Training materials.
- Note the
-
Check that the copy worked:
ls -
Change directories into the molecules directory:
cd molecules -
Look at these files with
more,cat,head,tail:more propane.pdbandcat propane.pdbhead propane.pdborhead -n2 propane.pdbtail propane.pdbortail -n2 propane.pdb
-
Redirects: You can redirect the output of a command to a file with the "
>" character (see below for more information about STDIN, STDOUT, and STDERR).Caution: Redirection with "
>" first erases the file you are redirecting to if it exists, replacing it with the new contents. You can append to a file with ">>".- As an example, we can get the lengths, in number of lines, of all the files ending in "
.pdb" using the wildcard "*" and redirect the output to a file:wc -l *.pdb > lengths.txt - Let’s see what this file looks like:
cat lengths.txt
Wildcard expansion (e.g.
*.pdb) is a convenient way to operate on a list of files matching some characteristic: e.g. having the.pdbending, starting with "p" (p*), etc. The wildcard is evaluated and the list of matching files is passed into the command. - As an example, we can get the lengths, in number of lines, of all the files ending in "
-
Sorting: We might want the lengths sorted:
sort -n lengths.txt- What happens without the
-n?
- What happens without the
-
Pipes: We can connect commands by piping the output from one command into the input for the next command using the vertical bar character "
|":The pipe character, "
|", is typically located above the Enter-key on US keyboards with the "\" and is accessed with the Shift-keywc -l *.pdb | sort -n > lengths.txt- Or if we only want to know the shortest file:
wc -l *.pdb | sort -n | head -n1
Why this works: Most Linux programs can take input from what is called "standard in", often abbreviated as "STDIN". In addition, they typically have two output streams, "standard out", "STDOUT", and "standard error", "STDERR". Both of these print to the screen by default, but can be redirected as we saw above (in fact we only redirect STDOUT with the "
>"; any STDERR would still print to the screen).So, while you can run a command like
wc -l propane.pdb, you can also get the same result by running thecatcommand and "piping" the STDOUT of that to the STDIN ofwc:cat propane.pdb | wc -l. Similarly, you can keep piping commands connecting the output of one command to the input for the next command. -
grep: We can search for text using
grep:grep ATOM propane.pdb
-
awk:awkcan do a lot, but one thing it’s good it is pulling out columns from files, in this case the 3rd column:grep ATOM propane.pdb | awk '{print $3}'
-
uniq:
uniqis a command to find unique entries in a sorted list:grep ATOM propane.pdb | awk '{print $3}' | sort | uniq -
Loops: One of the great things about the command line is the ability to automate repetitive tasks. Let’s say we want to verify that all our molecules are hydrocarbons (made up of only C and H atoms). Below is what the loop looks like neatly spaced out as if it were in a script:
for molecule in *.pdb do echo $molecule grep ATOM $molecule | awk '{print $3}' | sort | uniq done
As we type this in on the command line, once you hit the Enter-key at the end of the first line, Bash gives you the continuation prompt, "
>", essentially telling you that you have started a command (a for loop), but not finished it:[user@login1 molecules]$ for molecule in *.pdb >
You can keep typing the rest of the lines so that it looks like this:
[user@login1 molecules]$ for molecule in *.pdb > do > echo $molecule > grep ATOM $molecule | awk '{print $3}' | sort | uniq > done
Once you hit the Enter-key after the "
done", that completes the for loop, and Bash executes it, showing the output.If you find yourself stuck in the continuation prompt mode, you can use the key combination
Ctrl-Cto cancel and exit back to the main command prompt.Ctrl-Cwill usually cancel execution of a program in Bash and is a handy key-combination to know! -
Using nano to edit files: We can use the
nanotext editor to edit files. Let’s add a comment to the top of thelengths.txtfile:nano lengths.txt- Use the arrow keys to move around in the file.
- Type your comment at the top of the file, e.g.
# This file has the lengths of all the pdb files in this directory - To save and exit, use the key combination
Ctrl-X(hold down the Ctrl-key and hit the X-key), then hit the Y-key to confirm that you want to save, and hit Enter to confirm the file name. cat lengths.txtto see your comment at the top of the file.- You can use
nanoto create new files. Just typenano newfile.txt, type some text, and then useCtrl-X, Y, Enter to save and exit. - If you want to exit
nanowithout saving changes, useCtrl-X, then hit the N-key when prompted to save changes.
-
Deleting files: Let’s get rid of the lengths.txt file:
rm lengths.txt- That file is now gone!! There is no undo, no recycle bin or trash can. As soon as you type the command and hit return, the file is gone!
- Be careful... but don’t keep everything forever either!
-
Removing directories: We can remove the
cli_demodirectory and everything in it with the-rflag to recursively delete everything in it:cd ..(to go back to the parent directory, in this case the molecules directory) and thenrm -r cli_demo
slurmInfo– Get information on compute resources in your groupblue_quota,orange_quota,home_quota– Get information on quotas and usencdu– Calculate and show storage usage by folder. Can take time to calculate—most helpful in /homeshowAllocation– Get information on investments
These commands only work when you have a job running or pending in the queue:
jobhtop,jobnvtop– View real-time job performance dataqos_to_burst,qos_to_main– Move pending jobs to burst/main QOS
- Which molecule has the most H atoms?
- Make a directory in your
cli_demofolder and copy themethane.pdbfile there (preferably without moving from themoleculesdirectory) - From the
moleculesdirectory, get theheadof themethane.pdbfile in the directory you created above. - Change directories to the directory you made above, rename the
methane.pdbfile tomy_methane.pdb. - Edit the
my_methane.pdbfile and put your name as the AUTHOR. I recommend thenanotext editor on the command line for new users:nano my_methane.pdband use the arrow keys to move around. The commands at the bottom of the screen use the Ctrl-key with another key, so^Xmeans holding down the Ctrl-key and the X-key simultaneously to exit. - How many ATOMS does methane have?
