Working on the command line - part 1
After logging into the system, you will be greeted by a command line prompt, which typically looks like this:
username@login1:~ █
This line displays crucial information, including:
- Your username: This is the first part of the prompt, displayed before the
@
symbol. It identifies who you are in the system. - System name: Following the
@
symbol, the system name indicates the specific machine or server you are connected to. - Current location in the file system: This is displayed after the colon (
:
). In the example provided, the current location is represented by a tilde (~
). The tilde is shorthand notation for your private home directory, which is a designated space for your personal files and configurations.
Lastly, the black square visible at the end of the line is the prompt itself. This is where you can begin typing commands to interact with the system. The prompt serves as a visual indicator, signifying that the system is ready to accept and process your input. As you become more familiar with the command line interface, you will learn how to navigate the file system, execute various commands, and manage files and directories more efficiently.
Why Use a Command Line?
Before diving into command line commands, it's important to understand the advantages that a command line interface (CLI) offers over a graphical user interface (GUI). While many tasks can be performed using both CLI and GUI-based file managers (such as MobaXterm, WinSCP, FileZilla, and the Hábrók web portal), each approach has its own benefits.
Advantages of a Command Line Interface:
- Low Network Bandwidth Usage: CLI consumes minimal network bandwidth, enabling its use in remote locations without compromising performance.
- Combining Tools: Command line tools can be easily combined to create more powerful, customized solutions.
- Efficient Repetition: The CLI allows for simple and efficient repetition of tasks, streamlining your workflow.
- Scripting Capability: Commands can be copied and combined into scripts to create complex workflows, which can be executed multiple times with ease.
- Output Capture: With CLI, it's easy to capture and store program outputs in files for further analysis, sharing, or processing by other tools.
In summary, the main advantage of a command line interface is the ease of automation it provides. It also offers exceptional flexibility, as users can write custom scripts to perform specialized tasks. These features make CLI the preferred interface for managing computer clusters.
While graphical user interfaces are generally more user-friendly, they do have limitations. GUIs restrict users to the capabilities they support and make it more challenging to repeat tasks multiple times. By contrast, the CLI offers a higher degree of customization and control, making it the ideal choice for advanced users or specialized tasks.
The welcome messages
Above the prompt there will have been a welcome message. This message will contain useful information that the CIT wants the Hábrók users to know about. A full example looks like:
Welcome to the Hábrók HPC cluster Login Node (( \\``. \_`.``-. ( `.`.` `._ `._`-. `._ \`--. ,' `. `--._ `. .`. `--.--- `. ` `. `.-- `; .`._ :- : ;. `.__,.,__ __ `\ : ,-( ';o`>. `-.`: ,' `._ .: (,-`, \ ; ;. ,: ,"`-._>-: ;,' `---.,---. `>'" "-` ,' "":::::".. `-. `;"'_, (\`\ _ `:::::::::::'" `---. -hrr- `-(_,' -'),)\`. _ .::::"' `----._,-"") \_,': `.-' `-----' `--;-. `. ``.`--.____/ `-^--' \(-. `.``-.`-=:-.__) ` `.`.`._`.-._`--.) `-^---^--.`-- Use the following commands to adjust your environment: 'module avail' - show available modules 'module add <module>' - adds a module to your environment for this session ------------------------------------------------------------------------------------------- | | | Do not run long, heavy jobs on the login node; only use it for simple and short tasks! | | The interactive node, hn-interactive.hpc.rug.nl, can be used for testing your program. | | | ------------------------------------------------------------------------------------------- Updates: Planned Maintenance: - None. Also see our status page: https://status.hpc.rug.nl
The message has four parts:
- Welcome message with hawk art.
- Useful information for the users, like explaining the important module command and to be careful running heavy computations on certain nodes.
- Updates on the system status, which may be useful for you.
- Maintenance plans you should be aware of.
File system structure
Before continuing with the command line interface it is good to first discuss the file system structure as used on Linux systems like Hábrók.
A graphical overview of the folder/directory structure is shown in the following figure:
The root of the file system hierarchy is at /
. This is different from Windows where the file system starts with drive letters like C:
or `X:
.
Within the root of the file system there are several directories, which can have subdirectories. There are system ones like bin/
for holding system tools and programs, and etc/
which is used for storing files with all kinds of settings.
Another difference between Linux and Windows is that directories are separated by the forward slash /
, whereas Windows uses the backslash \
. So where a Windows path might look like:
C:\Users\p-number1\programs\analyse.exe
A similar path on a Linux system would look like:
/home/p-number1/programs/analyse.x
home directory
On a Linux system each user has a home directory. On Hábrók these are located in /home/
in the root of the file system.
When you log in into the system your command line prompt will start in this home directory. And any files you refer to, without giving a full path will refer to files within the home directory.
Full versus relative paths
If you refer to a file, without starting at the root of the file system using /
, the path + filename combination will refer to a point starting in the current directory. If you want to refer to another location in the file system hierarchy you will have to give the full path. A full path starts with /
, which is the root of the file system. An example is:
/data/p-number1/exp_1/series.csv
If you want to refer to a location within the current directory, you can use relative paths like:
sources/analyse.c
In this case we assumed that the command line prompt was in the home directory /home/p-number1
.
Special pointers
There are two special pointers that can be used to point to locations in a relative path, these are:
.
points to the current directory. This is mainly useful when referring to programs that are not in standard locations. In order to execute such a program it has to made clear in which precise location they are. When the program or script is in the current directory./
can be used to point to this, like./myscript.sh
...
points to the directory one level higher in the hierarchy. So when being in the directorysources
in the example structure..
would refer to the home direcory/home/p-number1
.
As mentioned before, another useful pointer is ~
, which points to your home directory. So, if you want to refer to a file in your home directory, you can use the notation ~/myfile.txt
instead of /home/p-number/myfile.txt
.
Next section: Working on the command line - part 2