|
Useful Linux Commands A practical reference for system administration, user management, networking, and more — commands we rely on regularly in our work. 1. VPN Management1.1 Activate a VPN ConnectionThe 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 StatusVerify whether the VPN1 connection is currently active: sudo nmcli con show --active | grep 'VPN1'
2. File & Directory Management2.1 Get the Size of Home SubdirectoriesCalculate 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 HostsCopy 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 Management3.1 Add a New UserCreates a new user account with the specified username: sudo adduser username
3.2 Grant Administrator PrivilegesAdds the user to the sudo group, giving them administrative access: sudo adduser username sudo
3.3 Delete a User and Their FilesRemoves a user account along with their home directory and mail spool: sudo userdel -r username
3.4 List All UsersDisplays all user accounts registered on the system: cat /etc/passwd
3.5 Terminate All Processes of a UserForcefully kills every active process belonging to the specified user: sudo killall -9 -u username
4. System Utilities4.1 Delay a Command by a Specified TimeUse 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 UbuntuInstall 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 ClockStep 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 Updates5.1 Resolve a GLIBC Version ErrorIf 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 Control6.1 Suspend a Running ProcessPause 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 ProcessContinue execution of a previously paused process: sudo kill -CONT 20419
7. Converting Python Scripts to Standalone BinariesPyInstaller 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 pipEnsure you have the latest version of pip before proceeding: python3 -m pip install --upgrade pip
7.2 Install PyInstallersudo pip3 install pyinstaller
7.3 Compile the ScriptRun PyInstaller against your script. The compiled binary will be placed in the dist/ folder: pyinstaller your_script.py
|

|
Department of Chemistry, Faculty of Science, University of Kurdistan |
|
Mehdi Irani Teaching duties Methods |