1. Quick Linux Review
1.1. Remote Machine Access
We use ARA cluster at Friedrich Schiller University Jena for this course. Reachable via SSH only accessible from university network or VPN . To achieve this goal, you’ll need to make sure you have access to the ARA cluster. If you’re unsure whether you have access or not:
Task
Email your URZ username to shima.bani@uni-jena.de.
Wait for a reply that you are good to go, then test your access and do step 3.
Use your URZ username to log into ARA:
ssh -X <username>@ara-login01.rz.uni-jena.de
1.2. Getting Started with Linux
Be aware that Linux system is case sensitive.
pwd (Print Working Directory) Shows the current directory you are in.
pwd
ls (List)
ls
: Lists the contents of the current directory.ls path/to/directory
: Lists the contents of a specific directory.ls -l
: Lists in long format, providing detailed information about files and directories, including permissions, owner, group, size, and modification time.ls -a
: Lists all files, including hidden files (those starting with a dot, like.config
).ls -lh
: Lists in long format with file sizes displayed in a human-readable format (e.g., KB, MB).
cd (Change Directory)
Allows you to navigate between directories.
cd <directory_name>
mkdir (Make Directory)
mkdir directory_name
: Creates a directory in the current directory.mkdir /path/to/directory
: Creates a directory at an absolute path.
rmdir (Remove Directory)
Deletes an empty directory.
rmdir <directory_name>
touch
Creates an empty file or updates the access and modification timestamps of an existing file.
touch <filename>
rm (Remove)
Deletes files or directories.
rm <filename>
rm -r <directory_name>
cp (Copy)
Copies files or directories.
cp <source_file_adr> <destination_file_adr>
cp -r <source_dir_adr> <destination_dir_adr>
mv (Move)
Moves or renames files and directories.
mv <source_file/dir_adr> <destination_file/dir_adr>
cat
Displays the contents of a file.
cat <filename>
more or less
View the contents of a file one screen at a time.
more <filename>
less <filename>
head and tail
Display the beginning or end of a file.
head <filename>
tail <filename>
grep (Global Regular Expression Print)
Search for text patterns in files.
grep <pattern> <filename>
-- help
Access the usage and options of commands to get detailed information.
<command> --help
man (Manual)
Access the usage and options of commands to get detailed information.
man <command>
Termination
Terminate a shell session or log out of a user session.
exit
logout
> (Output Redirection)
Redirect the output of a command to a file, overwriting the file if it already exists.
<command> > <filename>
>> (Append Output)
Redirect the output of a command to a file, but it appends the output to the end of the file if it already exists.
<command> >> <filename>
tee
Display the output of a command on the screen, as well as save it to a file.
<command> | tee <filename>
<command> | tee -a <filename> # Append to the existed file
echo
Print text or messages.
echo "<text>"
echo "$(date)"
1.3. Path Notations and Shortcuts
Absolute Path
An absolute path specifies the location of a file or directory from the root directory. It starts with a forward slash (“/”). For example:
/home/user/documents/file.txt
Relative Path
A relative path specifies the location of a file or directory relative to the current working directory. It does not begin with a forward slash. For example, if your current directory is /home/user, then documents/file.txt is a relative path.
. (Dot)
Represents the current directory. It can be used to reference files or directories in the current directory. For example, ./script.sh runs a script in the current directory.
.. (Double Dot)
Represents the parent directory. It is used to navigate up one directory level. For example, ../../file.txt references a file two levels up in the directory structure.
~ (Tilde)
Represents the home directory of the current user. It can be used to reference files or directories in the user’s home directory. For example, ~/documents/file.txt references a file in the user’s home directory.
cd (Change Directory)
cd directory_name: Changes the current directory to the specified directory.
cd /absolute/path/to/directory: Changes the current directory to an absolute path.
cd ..: Moves up one directory level (parent directory).
cd .: Stays in the current directory (useful when you want to execute a command in the current directory).
cd ~ or cd: Takes you to your home directory.
Environment Variables
You can use environment variables in paths to make them more dynamic. For example, $HOME represents the home directory, and you can use it like cd $HOME/Documents.
1.4. Command-Line Text Editors
Linux offers a wide range of text editors, from command-line options like Vi, Vim, and Nano to graphical editors like gedit and Kate.
Vi
Vi is a popular command-line text editor in Linux. Here are some essential commands for using Vi:
Open a file for editing or create a new file with the specified filename.
vi <filename>
There are two modes in Vi, Editing mode and command mode. To enter editing mode:
i: Insert text before the cursor.
a: Append text after the cursor.
And to enter command mode press ESC and you have following commands:
Arrow keys: Move the cursor left, down, up, and right.
G: Go to the end of the file.
x: Delete the character under the cursor.
dd: Delete the current line.
yy: Copy the current line.
p: Paste the copied text after the cursor.
u: Undo the most recent change.
Ctrl-r: Redo the most recent undone change.
w: Save changes to the file.
q: Quit Vi.
wq or :x: Save changes and quit.
q!: Quit Vi without saving changes.
Task
Create a new directory called <your_first_name> in your home directory.
Navigate to the created directory.
Create a new directory inside it called “Original”.
Create a text file called “todo.txt” inside the inner directory.
Use the vi text editor to open “todo.txt” and add some sample to-do items. Save and exit the file.
Create another directory called “Backup” inside <your_first_name>.
Copy only the “todo.txt” file from the “Original” directory to the “Backup” directory.
Simultaneously display “Backup completed successfully” on the screen and save this text to a file called “backup.log” inside the “Backup” directory.
Simultaneously display “Backup at <current_date_and_time>” on the screen and append it to “backup.log”.
List the contents of the <your_first_name> directory and save it into a text file called “list_my_dir.txt”.
1.5. File Transfer
While there are various methods available for secure file transfers, in this context, we specifically utilize SFTP, which stands for Secure File Transfer Protocol. It is a secure and encrypted protocol used for transferring files between a local and a remote system. It is commonly used in Linux for securely transferring files to and from remote servers over an SSH connection. Before using SFTP, ensure that an SFTP server is running on the remote host.
To initiate an SFTP session from your local Linux system to ARA Cluster, open a terminal and use the following command:
sftp <username>@ara-login01.rz.uni-jena.de
You will be prompted for your password or key passphrase to authenticate.
SFTP Commands
Once connected, you can use various commands to navigate and transfer files. Here are some common SFTP commands:
ls
: List files and directories on the remote server.cd
: Change the remote directory.get
: Download a file from the remote server to your local system.put
: Upload a file from your local system to the remote server.pwd
: Print the current remote directory.quit
orexit
: Disconnect from the remote server.
File Transfers
To transfer files, use the get
and put
commands. For example, to download a file, use get <filename>
, and to upload, use put <filename>
.
Task
Pick two file transfer methods (e.g., SCP, SSHFS, FTPS, …).
Transfer a file from your local system to your account on ARA using that two method.
Give a short summary of their workings and differences.
1.6. System’s Hardware Information
The Linux command-line utility, lscpu
, is employed to retrieve system CPU information. This command acquires CPU architecture details from the sysfs
and /proc/cpuinfo
files, then presents the information within terminal.
You can also view system memory information using the cat /proc/meminfo
command. This command will display detailed information about the system’s memory usage and configuration.