Introducing Linux and the Command Line
|
UNIX is the original operating system, Linux refers to the kernel itself and is used by most top supercomputers.
On Linux systems, like supercomputers, everything is done on the command line.
Many commands need options (flags) beginning with a - to be utilised effecitvely
Many commands need additional arguments to be passed into them to perform
The root directory is specified by the root directory, referred to as / .
Directory names in a path are separated with / on Unix and Mac, but by \ on Windows.
Whitespace matters. Every space makes a difference, so be careful what you are typing.
|
Navigating through files and directories
|
Information is stored in files, which are stored in directories. A directory is itself a file which contains references to other files.
The pwd command will always show where you are at any time.
The ls command lists the contents of the present working directory. Additional options and arguments can filter this list further.
The man command will return usage and flags of any command you specify
.. means ‘the directory above the current one’ in the directory tree, whereas . on its own specifies ‘the current directory’.
The cd command allows you to navigate through directories, but you also need to direct it to where you want to go using cd [path] .
Use history to display recent commands, and ![number] to repeat a command by number.
|
Working with files and directories
|
Most files’ names are something.extension . The extension isn’t required, and doesn’t guarantee anything, but is normally used to indicate the type of data in the file.
cp [old] [new] copies a file.
mv [old] [path] moves a file into the specified path, mv [old] [new] renames a file.
mkdir [path] creates a new directory.
rmdir [path] removes an empty directory. rm [path] removes a file. These are irreversible as the shell does not have a recycle bin.
|
Useful Tools
|
echo is the print statement in UNIX.
If pressing Enter gives you e.g. > , this indicates you are writing a string in echo . You can exit it by pressing Ctrl+C to return to the prompt.
command > [file] redirects a command’s output to a file (overwriting any existing content).
command >> [file] appends a command’s output to a file.
The different viewing commands more , less and cat have different uses depending on the size of your file.
cat prints a file directly to the screen, less opens a new window.
The * wildcard matches zero or more characters in a filename, so *.txt matches all files ending in .txt .
The ? wildcard matches any single character in a filename, so ?.txt matches a.txt but not any.txt .
The [] wildcard matches any single character called in the bracket that is present in the filename, so [12].txt matches 1.txt , 2.txt , but no other number or character.
|
Loops and Conditionals
|
A for loop repeats commands once for every thing in a list.
Every for loop needs a variable to refer to the thing it is currently operating on.
Use $name to expand a variable (i.e., get its value). ${name} can also be used.
Do not use spaces, quotes, or wildcard characters such as ‘*’ or ‘?’ in filenames, as it complicates variable expansion.
Give files consistent names that are easy to match with wildcard patterns to make it easy to select them for looping.
|
Bash Scripting
|
Bash scripting and utilising text editors is the most important skill in Linux
Without bash scripting, you are unable to submit jobs on an HPC, and the usability of Linux is limited.
|
ssh Keys
|
ssh key-pairs are needed to log into most supercomputing systems
To log into ICHEC’s cluster, an ssh key-pair is necessary
You only need one ssh key-pair generated per device
ssh keys are typically stored in the user’s home directory
|
Extra commands
|
grep selects lines in files that match patterns. It can be combined with pipes | to be even more useful.
.tar archives are very useful ways of converting a while folder into a single file. They are often used in data sharing.
The creation of .tar archives requires the use of flags to create and untar them.
The -cf tar flags create an archive with a specified name. The -xf flag is used to extract the archive contents.
|
{:auto_ids}
key word 1
: explanation 1
key word 2
: explanation 2