The OS of MSU HPC is CentOS which is a brach of Linux. So if you want to use our system, it is essential to equip some basic knowledge on Linux. Even though Linux supports GUI, most works are done on a dummy terminal via texts. The Linux command line is a text interface to Linux.
We will walk through some practical exercises to become familiar with a few basic commands and concept.
Let's run the first command. Type pwd and pressing the Enter or Return key to run it (From now, I'll not mention pressing Enter/Return key part to run command).
You will see a path such as /mnt/home/user/your_id
pwd is an abbreviation of 'print working directory'. It print out the shell's current working directory. You can change the working directory using the cd command, an abbereviation for 'change directory'.
Now your working directory is '/' which is the root directory. There is nothing much you can do on the root directory, so let's go to your 'home' directory.
Regardless of your location, when you just type 'cd', you will be home. You can also type 'cd ~' instead of 'cd' to be back your home.
To go the previous directory, type 'cd -'
The root directory has many subdirectories including your home directory. Let's go to 'bin' directory.
To go up to the parent directory (it is / for us now), use the special syntax of two dots with cd such as
To go up to the previous directory, use - with cd such as
You can use .. more than once if you have to move up multiple levels of parent directories.
Relative and absolute Paths
A path is an address of a directory. Most of the examples we've looked at so far uses relative paths. So you final location is decides based on your current working directory. However, sometimes you want to use an absolute path than relative one. Your home's absolute path at HPC is /mnt/home/your_id. See the example to find how to use a relative and absolute paths.
Creating and removing directories
To make a directory, use mkdir (short for 'make directory') such as
ls is a command to list files and folder. We will learn it in a minute. You can create multiple directories as well.
To make a subdirectory, use with p option such as
To remove directory use rm command with r. Without r option, rm will not delete directories (but you can delete files). r means recursive.
Creating and removing files
You can use editors to create files, but it is out of scope of this tutorial. Let's use ls and a pipe > (we will explain pipes later).
Now we have three directories (temp01, temp02, temp03) and one file (list.txt). We already know how to delete directories. To delete files, we use command rm such as
Copying moving/renaming directories and files
To copy files or directories, use cp such as
With r option, you can copy files and directories recursively. i.e., copy subdirectories and files.
mv command mv files/directories or rename them.
Listing directories and files
We already used ls. To list directories and files, us ls (short for 'list').
There are many options for ls. Most frequently used options are
- a: list all files and directories including hidden contents
- h: print sizes in human readable format (e.g.: 1K, 2.4M, 3.1G)
- l: list with a long listing format
- t: sort my modification time
You can use options separately like ls -l -a -t or together like ls -lat.
Now let's do some exercise.
- Log in your MSU HPC account and go to any dev-node.
- Create linux_tutorial dir on your home.
- Copy a folder and contents for this tutorial from
- /mnt/research/common-data/workshops/intro2Linux_iamsam to linux_tutorial dir on your home
- Go to linux_tutorial
- Find a hidden directory and rename it to not_hidden
- Check the contents of not_hidden
- Create a new directory called new_dir
- Copy the file youfoundit.txt into new_dir
- remove garbage dir