If you need access to a Linux shell
You can follow the instructions in this video to get access to a Linux shell on the cluster:
https://www.mivideo.it.umich.edu/media/t/1_gcd7nfix
For more reading:
https://linuxcommand.org/tlcl.php
Getting to Know the Environment
When you log in to the cluster you will be met with a shell prompt.
The shell prompt looks like this:
[uniqname@gl-login#~]
Where uniqname is your UMich uniqname and # is a number between 1-4.
When you see this prompt, the computer is waiting for you to enter a command
You will not have access to a mouse to navigate on this screen, but you can use the following:
- “Backspace” key
- “Enter” key to execute the line you have typed
- Enter the command exit to log out
- Use the “Tab” key to use autocomplete
- Left/Right Arrow
- Up/Down arrow to access your command history
- Ctrl + “c” to interupt a command you have started
Try entering a few commands to see the response from the system.
Here are a few to try:
date | who |
ps -eaf | history |
Directory structure
The Linux filesystem stores files within directories. These directories can store other directories as well. The hierarchy of directories is called a directory tree, with a single topmost root directory
Navigating the filesystem
We can access a file using its pathname.
Using the filesystem image above, if we were in the rorellana home directory and we were trying to access the index.html file inside the public_html directory, we could access either by:
Using the absolute path: /home/rorellana/public_html/index.html | Using the relative path: public_html/index.html |
Moving Between Directories
You can move to other directories by using the cd command and either the relative path or the absolute path.
pwd
The directory we are currently in is known as the present working directory and can always be checked by using the pwd command.
Home Directory
This directory that you start in is known as your home directory.
The system sets up a shortcut to your home directory.
You can either use $HOME or ~ as a shortcut to your home directory.
Special Directories
There are two special directories:
.refers to the current directory
.. refers to the directory “above” the current directory, or the parent directory.
You can use .. to change back into a parent directory.
Listing, Creating and Removing Directories
To see what you have in a directory you can use the ls command.
You can use mkdir <dirname> to create a directory named <dirname>.
Likewise, you can use rmdir <dirname> to remove an empty directory.
Working with Files
There are a series of commands you can use to interact with files.
touch <file1> | create a file named file1 |
mv <file1> <file2> | “move” or rename file1 to file2 |
cp <file1> <file2> | copy file1 to file2 |
cp -r <dir1> <dir2> | copy directory1 to directory2 |
cp <file1> <file2> <dir1> | copy file1 and file2 to directory1 |
rm <file1> | remove/delete file1 |
rm -r <dir1> | remove directory1 |
Searching Files
Here are some commands you can use to search for or within files
grep 'search pattern' <file_name> | grep allows you to look for a term/search pattern within a file |
find 'startlocation' search parameters | find allows you to look for files that match given parameters i.e. creation date, owner, type |
Working more with Files
You can get the contents of a file by using the cat command to dump the contents of the file to the standard output, i.e. the screen.
If you need the last or first line of a file you can also use tail or head. These tail and head commands can take more options if you need more than a couple of lines. You can get more information on those, or other commands by using the man command, as in man tail.
You can redirect the output of a command. If you wanted to send the output to a file instead of the standard output you can use the redirect >. For example: cat examplefile.txt > redirectedfile.txt will take the contents of examplefile.txt and use them to create a new file named redirectedfile.txt.
The above example redirects to a file, but you can also redirect from the standard output to another command by using the pipe |. For example: cat examplefile.txt | grep 'abc' will take the output from the cat examplefile.txt command and redirect it to the grep 'abc' command. You can use this to chain multiple commands together!
Editing Files
You can edit files with the nano editor. The nano editor has all the commands listed at the bottom of the screen where the ^ denotes the “CTRL” key. So “CTRL+O” prompts nano to save your file, while “CTRL+X” prompts nano to exit the program.
Let’s create a simple file named my_script.sh that contains echo hello $USER by :
1) calling nano
2) entering echo hello $USER
3) pressing CTRL+O to save the file
4) naming the file my_script.sh
5) pressing CTRL+X to exit nano
Looking at File Permissions
We can take a look at file permission by using ls -l this gives us something that looks like this:
If we look at the permissions of the file we just saved it should look something this:
If we note the file permissions we see that the user and group has read and write access while “other” users only have read access. We can modify the permissions by using chmod. For example to make it executable by the user and group we could do chmod ug+x my_script.sh. Doing this and then checking the permissions shows:
Likewise, you can remove permissions. For example if you didn’t want the others to be able to read your file you could do chmod o-r my_script.sh