Ubuntu Operating System
All SCRP nodes run on Ubuntu 20.04 LTS, a popular version of the Linux operating system. While you might be able to get by relying on the web interfaces of Jupyter and RStudio for simple tasks, familiarity with Linux is going to be very helpful for anything slightly more advanced. This section introduces some basic commands.
Help
When you are not sure what a command does or what are the corresponding options, you can check if the command has built in help:
command -h / command --help
For some external commands the help option does not always exist. In this case, you may use the man command, which stands for manuals.
man command
And of course do not forget the powerful Google.
Navigation
The most important command is cd
, abbreviation of ‘change directory’:
cd directory
There are two ways of representing a directory, absolute path and relative path.
A absolute path is a path starting from a system recognisable directory. The most common one is ~
, representing your home directory.
~/folder_name1/folder_name2
Notices in Linux we use /
to represent our path instead of \
in Windows.
A relative path is the path relative to your current directory. For example:
./folder_name1/folder_name2
Here the .
means your current directory. For example if you are in your home directory, a.k.a ~
, the relative path expression will be identical to the abosolute path expression.
Always remember in Linux everything is case sensitive—Folder1
and folder1
are two different directories.
Other useful shortcuts includes:
cd ~ # Go to your home directory
cd .. # Go one directory up from where you locate
cd - # Go to your previous directory
File Manipulation
If you want to know what files and folders are placed in your a directory, you can type:
# Shows content of current directory
ls
# Shows content of directory dir_path
ls dir_path
To create a new file:
touch file_path
Note that touch
only creates the file. If you would like to actually type something to the file, you can use nano
editor instead:
nano file_path
To copy a file:
cp file_path destination_path
For example, cp testing.py ~/python/test/site-52/
will move a file called testing.py to the directory ~/python/test/site-52/.
Use mv
to move a file or to change a file’s name:
# Move file to a different location
mv file_path destination_path
# Rename
mv file_name new_file_name
To delete a file:
rm file_path
If your filename is too long, try pressing Tab on your keyboard, the terminal will do a smart guess to your filename or list out similar filenames. Keep pressing Tab and then Enter to choose the file you want.
Directory Manipulation
Moving, copying and renaming folders are much like files, but we use different command to create and remove folders.
To create a folder,
mkdir dir_path
To remove a folder,
rm -r dir_path
This will also delete any files inside the folder.
Files and Directory Permission
In Linux you can set permissions to different files, some program, like Slurm, only works with files with correct permissions.
To read about current file permissions, you may use the ls -la
command. You should see for example on the left
drwxr-xr-x some_other_stuff directory_name
-rw-r----- some_other_stuff file_name
Here ls
is the command itself and -la
are options relating to the command—in this case, all files in a long list format.
The permissions are shown on the left 10 digit morse code:
- The first digit means if this is a folder or a file. If it is folder a ‘d’ is shown. (The d stands for directory, the difference between it and folder is subtle and neglected)
- The next three digits are the read, write and execute permissions for the owner of the file. So ‘rw-‘ means the user can read, and write to the file/folder but not execute.
- The next three digits are the permissions for the file’s user group.
- The last three digit are the permissions for any other user.
To change a file or a directory’s permissions:
chmod u=rwx,g=rw,o= file_name
The above command will give read, write and execute access to the owner, read and write access to users belonging to the file’s user group and no access to any other user.
You can also specify just the permission for the type of user you would like to change:
# Modify permission for owner of the file only
chmod u=rwx file_name