Useful Linux Commands

A practical reference for system administration, user management, networking, and more — commands we rely on regularly in our work.

1.   VPN Management

1.1      Activate a VPN Connection

The following command activates a VPN connection named VPN1, prompting for credentials if required:

sudo nmcli con up id 'VPN1' --ask

 

1.2      Check VPN Connection Status

Verify whether the VPN1 connection is currently active:

sudo nmcli con show --active | grep 'VPN1'

 

2.   File & Directory Management

2.1      Get the Size of Home Subdirectories

Calculate and display the disk usage of each subdirectory under /home:

sudo du -sh /home/*

 

Flag   Description

du          Reports disk usage of files and directories.

-s            Displays a summary total for each directory (suppresses subdirectory detail).

-h           Formats output in a human-readable form (KB, MB, GB, etc.).

 

2.2      Sync Only New or Modified Files Between Hosts

Copy files to a remote machine, preserving timestamps and excluding temporary or trajectory files:

rsync -avzu  --progress       --exclude='*tmp*'  --exclude='mdcrd*'  /home/user/data/  user@192.168.1.10:/home/user/backup/

 

Flag   Description

-a           Archive mode — preserves symbolic links, permissions, timestamps, and other attributes.

-v           Verbose output to track which files are being transferred.

-u           Skips files that are newer on the destination than the source.

-z           Compresses data during transfer to reduce bandwidth usage.

--progress       Displays real-time transfer progress for each file.

--exclude         Prevents files matching the specified pattern from being copied.

 

3.   User Management

3.1      Add a New User

Creates a new user account with the specified username:

sudo adduser username

 

3.2      Grant Administrator Privileges

Adds the user to the sudo group, giving them administrative access:

sudo adduser username sudo

 

3.3      Delete a User and Their Files

Removes a user account along with their home directory and mail spool:

sudo userdel -r username

 

3.4      List All Users

Displays all user accounts registered on the system:

cat /etc/passwd

 

3.5      Terminate All Processes of a User

Forcefully kills every active process belonging to the specified user:

sudo killall -9 -u username

 

4.   System Utilities

4.1      Delay a Command by a Specified Time

Use sleep to postpone command execution. The example below runs ls after a one-hour delay:

sleep 1h && ls

You can substitute 1h with values such as 30m (minutes) or 90s (seconds).

 

4.2      Enable SSH on Ubuntu

Install the OpenSSH server to allow secure remote connections:

sudo apt update

sudo apt install openssh-server

 

The SSH service typically starts automatically after installation. To confirm it is running:

sudo systemctl status ssh

If the service is inactive, start it manually and enable it to launch at boot:

sudo systemctl start ssh

sudo systemctl enable ssh

 

4.3      Synchronize the System Clock

Step 1. On the machine with the correct time, retrieve the current timestamp:

date --iso-8601='second'

Step 2. On the machine with the incorrect time, set it using the value obtained above:

sudo date --set 2026-03-02T09:55:21+03:30

 

5.   Troubleshooting & System Updates

5.1      Resolve a GLIBC Version Error

If you encounter the error:

/lib/x86_64-linux-gnu/libm.so.6: version 'GLIBC_2.29' not found

 

Try installing the required Fortran runtime library:

sudo apt-get install libgfortran3

Note: libgfortran3 is not officially supported on Ubuntu 20.04. If the package is unavailable, copy libgfortran.so.3 from an older Ubuntu system using the commands below.

sudo su

cd /usr/lib/x86_64-linux-gnu

scp -r username@<remote-IP>:/usr/lib/x86_64-linux-gnu/libgfortran.so.3 .

 

6.   Process Control

6.1      Suspend a Running Process

Pause a process using its PID (e.g., 20419). The process is stopped but remains in memory:

sudo kill -STOP 20419

 

6.2      Resume a Suspended Process

Continue execution of a previously paused process:

sudo kill -CONT 20419

 

7.   Converting Python Scripts to Standalone Binaries

PyInstaller packages a Python script and all its dependencies into a single executable binary, which can be distributed and run on machines without a Python installation.

7.1      Upgrade pip

Ensure you have the latest version of pip before proceeding:

python3 -m pip install --upgrade pip

 

7.2      Install PyInstaller

sudo pip3 install pyinstaller

 

7.3      Compile the Script

Run PyInstaller against your script. The compiled binary will be placed in the dist/ folder:

pyinstaller your_script.py

 

University of Kurdistan, Sanandaj logo

Department of Chemistry, Faculty of Science, University of Kurdistan