|
Useful Linux Commands A practical reference for system administration, user management, networking, and related tasks — the commands we rely on regularly in our work. Unless stated otherwise, the examples assume a Debian- or Ubuntu-based system running systemd. 1. VPN Management1.1 Activate a VPN ConnectionThe following command activates a VPN connection named VPN1, prompting for credentials if required: nmcli con up id 'VPN1' --ask
1.2 Check VPN Connection StatusCheck whether the VPN1 connection is currently active: nmcli con show --active | grep 'VPN1'
2. File & Directory Management2.1 Get the Size of Home SubdirectoriesReport the disk space used by each subdirectory of /home: sudo du -sh /home/*
Command / flag Description du Reports disk usage of files and directories. -s Prints a single total for each argument rather than one line per subdirectory. -h Prints sizes in human-readable units (K, M, G) instead of raw blocks.
2.2 Synchronize Files Between HostsCopy a directory to a remote machine, preserving file attributes and skipping temporary and 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 — copies recursively and preserves symbolic links, permissions, timestamps, and ownership. Hard links, ACLs, and extended attributes are not included; add -H, -A, and -X if they are needed. -v Verbose output to track which files are being transferred. -u Leaves files that are newer on the destination than on the source untouched. Note that rsync already transfers only files that differ; -u adds protection against overwriting newer copies. -z Compresses data in transit to reduce bandwidth use. On a fast local network, this can slow the transfer down, particularly for data that is already compressed. --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 UserCreate a new user account. On Debian and Ubuntu, adduser is an interactive front end to useradd: it creates the home directory, copies the skeleton files, and prompts for a password. sudo adduser username
3.2 Grant Administrator PrivilegesAdd the user to the sudo group, which grants administrative access. The change takes effect at the user's next login: sudo adduser username sudo
3.3 Delete a User and Their FilesRemove a user account together with its home directory and mail spool. The command will fail if the account still owns running processes, so terminate those first (see Terminate All Processes of a User): sudo userdel -r username
3.4 List All UsersList the user accounts known to the system. getent queries every source configured in the name service switch, so it also returns accounts supplied by LDAP or Active Directory, not only those held in /etc/passwd. The output includes system and service accounts as well as human users: getent passwd
3.5 Terminate All Processes of a UserTerminate every process belonging to the specified user. The -9 option sends SIGKILL, which cannot be caught or ignored, so processes get no opportunity to close files or save state; it is worth omitting it first so that the default SIGTERM is sent instead: sudo killall -9 -u username
4. System Utilities4.1 Delay a Command by a Specified TimeUse sleep to postpone the execution of a command. The example below runs ls after a delay of one hour: sleep 1h && ls Replace 1h with any other duration, such as 30m (minutes) or 90s (seconds). The delay is tied to the shell that started it, so the command is lost if the terminal closes.
4.2 Enable SSH on UbuntuInstall the OpenSSH server to allow secure remote connections: sudo apt update sudo apt install openssh-server
The service normally starts automatically once the package is installed. To confirm that 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 the clock to the value obtained above. If an NTP client is active — the default on current Ubuntu releases — disable automatic synchronization first, or the manual setting will be overwritten within seconds: sudo timedatectl set-ntp false sudo date --set="2026-03-02T09:55:21+03:30"
5. Troubleshooting & System Updates5.1 Resolve a GLIBC Version ErrorA program may fail to start with an error such as: /lib/x86_64-linux-gnu/libm.so.6: version 'GLIBC_2.29' not found
This means that the program was built against a newer version of the GNU C Library (glibc) than the one installed on this machine. It is not caused by a missing Fortran library, and installing one will not resolve it. Check which version is present with: ldd --version GLIBC_2.29 corresponds to glibc 2.29, first shipped in Ubuntu 19.04; Ubuntu 18.04 provides 2.27. Because glibc cannot safely be upgraded on its own, the workable options are to rebuild the program on this machine, to run it inside a container or a conda environment that supplies a newer glibc, or to upgrade the distribution. 5.2 Resolve a Missing Fortran Runtime LibraryA different message — libgfortran.so.3: cannot open shared object file — indicates that the runtime library of GCC 4 is missing. Where it is still packaged, install it with: sudo apt-get install libgfortran3 Note: libgfortran3 was dropped after Ubuntu 18.04 and is not available on 20.04 or later. If the package cannot be installed, copy libgfortran.so.3 from an older Ubuntu system and refresh the linker cache, as shown below. This is a last resort: mixing libraries between releases can introduce further incompatibilities. sudo su cd /usr/lib/x86_64-linux-gnu scp username@<remote-IP>:/usr/lib/x86_64-linux-gnu/libgfortran.so.3* . ldconfig
6. Process Control6.1 Suspend a Running ProcessSuspend a process by its PID (20419 in this example). The process stops executing but stays in memory and keeps its open files. sudo is needed only if the process belongs to another user: sudo kill -STOP 20419
6.2 Resume a Suspended ProcessResume a process that was previously suspended: sudo kill -CONT 20419
7. Converting Python Scripts to Standalone BinariesPyInstaller bundles a Python script together with the interpreter and its dependencies, producing an executable that runs on machines with no Python installation. The result is platform-specific: a binary built on Linux runs only on Linux, and only on systems whose glibc is no older than that of the build machine. 7.1 Create a Virtual Environment and Upgrade pipUbuntu 23.04 and later protect the system Python from pip, so create and activate a virtual environment first, then upgrade pip inside it: python3 -m venv ~/venvs/pyinstaller source ~/venvs/pyinstaller/bin/activate python3 -m pip install --upgrade pip
7.2 Install PyInstallerpip install pyinstaller
7.3 Compile the ScriptRun PyInstaller against your script. On its own, PyInstaller writes a folder of files to dist/; --onefile packs everything into a single executable, dist/your_script: pyinstaller --onefile your_script.py
|

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