Linux basic commands

This guide aims to help you understand and use basic Linux commands to use GLiCID.

Filesystem hierarchy

Basic commands

Running a command in Linux is generally structured as follows:

<command> -option [argument] (target)

Command chaining is done with the pipe |:

<command> -option [argument] (target) | <command> | etc.

To redirect the output of a command to a file:

<command> > myfile.txt → Overwrites the file and writes into it.

<command> >> myfile.txt → Appends to the file without overwriting.

You can autocomplete commands by using Tab to avoid typing the entire command. You can also do this with directories with some exceptions

Linux quick cheatsheet

Command

Help

which <command>

Check if the command is available in your PATH

pwd

Get the current full path

ls -al

List the contents of the current directory

cd

Change directory

cd ..

Go up one directory

touch a.txt

Create an empty a.txt file

nano a.txt

Edit the a.txt file. Use Ctrl+O to save, and Ctrl+X to exit

cat a.txt

View the contents of the file

less a.txt

Same as cat but you can scroll in the file

cp a.txt otherfile.txt

Copy the a.txt file into a otherfile.txt file

rm a.txt

Delete the a.txt file

mv otherfile.txt file.txt

Rename the otherfile.txt into file.txt

rm -rf folder/

Delete recursively the folder/. There is no backup on many storage spaces. See here to check

User configuration files

Linux systems allow each user to personalize their environment using configuration files stored in their home directory. These files are typically hidden (prefixed with a dot .) and are executed or read automatically by the shell or specific applications.

This file is executed every time a new interactive shell session is started (e.g., when opening a terminal).

Typical use cases: . Setting environment variables . Defining shell aliases . Customizing the command prompt (PS1) . Adding paths to $PATH

.bash_profile / .profile

These files are executed during login shells (e.g., when logging in via SSH).

To ensure that the contents is loaded, we advise you modify the .profile file

File and folder permissions

$ ls -l file.txt
-rwxr-xr-x 1 user group 1234 April  7 12:34 file.txt



In Linux, each file has three types of permissions :
. Read (r): Allows reading the file content.
. Write (w): Allows modifying the file.
. Execute (x): Allows executing a file (for scripts or programs).

And have applicable groups or users to them :

. First three characters : Permissions for the file owner (U)
. Next three characters : Permissions for the group (G)
. Last three characters : Permissions for other users (O)

Processes and Performance Management

# View current processes
ps aux  # Shows all processes with details
- a : Shows all processes.
- u : Shows processes with more details (user, CPU, memory).
- x : Shows all processes, even those without a terminal.

top     # Displays real-time processes
htop    # Enhanced version of "top", if installed

# Kill a process (replace <PID> with the process number)
kill <PID>
kill -9 <PID>  # Force close
pkill <process_name>  # Kill a process by name

File Search and Manipulation

# Search for a file in a directory (requires permissions on the target directory).
find /TargetDirectory -name "myfile.txt" 2>/dev/null

# Search for text in a file
grep "keyword" myfile.txt

# Find all files containing "error" in the current folder
grep -r "error" .

# View file and directory sizes
du -sh *  # File/folder sizes in the current directory

# Check available disk space
df -h

Compression and Archiving

# Create a gzip archive
tar -czvf myarchive.tar.gz folder_to_add_to_archive/

# Extract a tar.gz archive
tar -xzvf myarchive.tar.gz

Transfer to and from GLiCID

You have to run these commands from your local PC, do not run them when already connected to GLiCID
# Transfer your local file.txt onto GLiCID
scp file.txt user@server:/path/destination/

# Copy a folder to a remote server (with -r)
scp -r folder/ user@server:/path/destination/

# Grab a file stored on GLiCID to put it on your local PC
scp user@server:/path/file.txt ./destination/

Downloading data

# Synchronize a local folder with a remote folder
rsync -avz /localfolder/ user@remote:/remotefolder/

# Download a file from the internet
wget https://example.com/myfile.txt

# Download a file with curl
curl -O https://example.com/myfile.txt