Click for detailed status
Linux command line
The Linux command line is a powerful tool for interacting with the operating system and executing commands. It allows users to perform tasks efficiently, automate processes, and manage files and applications. The command line interface (CLI) is often preferred by advanced users for its speed and flexibility compared to graphical user interfaces (GUIs).
The learning curve
The command line can be intimidating at first, but with practice, it becomes a valuable skill. Start with basic commands and gradually explore more advanced features. Learning some basic before using the clusters, can greatly enhance you experience and productivity.
Basics¶
Bash¶
Bash is a powerful scripting language, which can be used directly in a Linux terminal and is often combined with Linux commands. It can simplify many tasks when working on an HPC cluster. Bash is the default shell on Euler.
.bashrc¶
The .bashrc file is executed when you start a new terminal session. You can add aliases, environment variables, and functions here to customize your shell environment. To edit it, use:
Editing .bashrc
Please be very careful when editing your .bashrc. A misconfigured .bashrc can result in you not being able to login to Euler any more. And please don't delete your .bashrc file.
For more details, see the bashrc manual
Tab completion¶
Most terminals support tab completion. Press Tab while typing a command or filename to auto-complete or list possible options.
history¶
Use the up/down arrow keys to scroll through previous commands. View history with:
For more details, see thehistory manual
exit¶
Exit the current shell:
For more details, see theexit manual
Environment variables¶
Environment variables store system-wide settings. View all environment variables with:
To view a specific variable, use: To set an environment variable, use: To unset a variable, use: For more details, see theecho manual, export manual, unset manual
echo¶
Print a string to the terminal:
For more details, see theecho manual
alias¶
Aliases are shortcuts for commands. Create an alias with:
For example, to create an alias forls -l:
To view all aliases, use:
For more details, see the alias manual
Bash scripts¶
Bash scripts are files containing a series of commands that can be executed together. They help automate repetitive tasks and create reusable workflows.
To create a bash script:
- Create a file with a .sh extension
- Add the shebang line at the top: #!/bin/bash
- Make it executable: chmod +x script.sh
- Run it: ./script.sh
Variables¶
Set a variable and print its value:
For more details see: Shell variablesFunctions¶
Define a function to group commands:
For more details, see thebash manual
Comments¶
Comments start with # and are ignored by the shell:
bash manual
Conditionals¶
Use if statements to execute commands based on conditions:
if [ $VAR_A == "some string variable" ]; then
echo "Variable matches"
else
echo "Variable does not match"
fi
bash manual
Loops¶
To repeat a command multiple times, you can use a loop. Here are some examples:
For more details, see thebash manual
Files and Directories¶
pwd¶
Pwd (print working directory) prints the current directory you are in:
For more details, see thepwd manual
ls¶
Ls (list) is used to list files and directories in the current directory.
Use wildcards to match files:*: Matches any number of characters?: Matches a single character[abc]: Matches any character in brackets
-a: Include hidden files-h: Human-readable sizes, such as KB, MB, GB-l: Long listing format-r: Reverse order-s: Include file sizes-S: Sort by file size, largest first-t: Sort by time, newest first
For more options and details, see the ls manual.
Colorized Output
If your terminal supports it, you can use ls --color=auto to get colored output for different file types.
This is disabled by default on Euler because it caused issues with the Lustre filesystem.
du¶
Du (disk usage) shows the disk usage of files and directories.
Some options:-h: Human-readable sizes, such as KB, MB, GB-s: Summary of total size-c: Include a grand total
For more details, see the du manual
find¶
Search for files and directories: - Find files by name:
Find directories by name: For more details, see thefind manual
cd¶
Cd (change directory) is used to navigate between directories in the filesystem.
To go up one level, use: To return to your home directory, use: To return to the previous directory, use: For more details, see thecd manual
mkdir¶
Mkdir (make directory) is used to create new directories.
Create a directory and its parent directories if they do not exist: For more details, see themkdir manual
rmdir¶
Mkdir (remove directory) is used to delete empty directories.
For more details, see thermdir manual
touch¶
Touch is used to create an empty file or update the timestamp of an existing file.
Update the timestamp of an existing file: For more details, see thetouch manual
chmod¶
Chmod (change mode) is used to change the permissions of files and directories.
This command adds execute permission for the user on the filescript.sh.
To change permissions for all users:
This command adds read permission for all users on the file file.txt.
For more details, see the chmod manual and the Wikipedia's File-system permissions
chown¶
Chown (change owner) is used to change the ownership of files and directories.
This command changes the owner offile.txt to user and the group to group.
To change ownership recursively for a directory and its contents:
For more details, see the chown manual
cp¶
Cp (copy) is used to copy files and directories.
Copy a directory recursively: For more details, see thecp manual
mv¶
Mv (move) is used to rename or move files and directories.
Move a file to a different directory: For more details, see themv manual
rm¶
Rm (remove) is used to delete files and directories.
Delete a directory and its contents recursively: For more details, see therm manual
ln¶
Ln (link) is used to create links to files. - Create a hard link:
- Create a symbolic link: For more details, see theln manual
cat¶
Cat (concatenate) is used to display the content of a file, contatenate files, or create new files. To display the content of a file:
To concatenate multiple files: To create a new file and write to it, use: Terminate input withCtrl+D.
For more details, see the cat manual
less¶
View the content of a file with backward navigation:
UseSpace to go to the next page, b to go back a page, and q to quit.
For more details, see the less manual
more¶
View the content of a file one screen at a time:
PressSpace to go to the next page, Enter to go to the next line, and q to quit.
For more details, see the more manual
Text editors¶
nano¶
Edit a file with the nano editor:
Ctrl+O to save, Ctrl+X to exit, and Ctrl+K to cut a line. It is user-friendly and suitable for beginners.
For more details, see the nano manual
vi¶
Edit a file with the vi editor:
i. After editing, press Esc to exit insert mode. To save and exit, type :wq. To exit without saving, type :q!.
For more details, see the vi manual
vim¶
Edit a file with the vim editor:
vi, but with more features. Use i to enter insert mode, Esc to exit insert mode, and :wq to save and exit. To exit without saving, type :q!.
For more details, see the vim manual
Redirections¶
Redirect the output of a command to a file:
Append the output to a file: Redirect both standard output and standard error to a file: Redirect standard error to a file: Redirect standard output to standard error: Redirect standard input from a file: Use a pipe to connect the output of one command to the input of another: For example, to filer the output of a command and sort it: For more details, see thebash manual
Compression and Archiving¶
zip¶
Create a compressed zip archive:
Extract a zip archive: For more details, see thezip manual
bzip2¶
Compress a file with bzip2:
For more details, see thebzip2 manual
gzip¶
Gzip (GNU zip) is a file compression utility. Compress a file with gzip:
Decompress a file with gzip: For more details, see thegzip manual
tar¶
Tar (tape archive) is used to create and extract archive files. Invented for tape backups, it is now widely used for file archiving. Create a tar archive:
Extract a tar archive: Some options: --c: Create a new archive
- -x: Extract files from an archive
- -f: Specify the archive file name
- -v: Verbose output (list files being processed)
For more details, see the tar manual
System information¶
man¶
Display the manual for a command:
For more details, see theman manual
top¶
Real-time view of running processes:
For more details, see thetop manual
htop¶
Interactive process viewer:
For more details, see thehtop homepage
id¶
Show user and group IDs:
For more details, see theid manual
whoami¶
Display the current user:
For more details, see thewhoami manual
which¶
Find the path of an executable command:
For more details, see thewhich manual
Strings and Text¶
awk¶
Awk is a powerful text processing tool that can be used to manipulate data and generate reports. Example: sum columns in a queue listing:
For more details, see theawk manual
cut¶
Cut is used to extract sections from each line of input.
This command extracts the first field (username) from the/etc/passwd file, using : as the delimiter.
For more details, see the cut manual
grep¶
Grep (global regular expression print) is used to search for patterns
For more details, see thegrep manual
sed¶
Sed (stream editor) is used to perform basic text transformations on an input stream (file or input from a pipeline).
For more details, see thesed manual
sort¶
Sort lines of text files:
For more details, see thesort manual