In this article, we explore a comprehensive list of must-know Linux system commands that every beginner should familiarize themselves with. Whether you're managing packages, updating your system, or controlling services, these commands will help you efficiently manage your Linux environment. From basic tasks like listing installed packages to more advanced operations such as upgrading to the latest release or enabling services, this guide covers all the essential commands to get you started on mastering the Linux command line.

Let's start with the basics

  • $ sudo reboot now Reboots the system immediately.
  • $ sudo apt update Fetches the latest updates for all installed packages from the repositories, ensuring the local package database is up to date.
  • $ sudo apt upgrade Installs the latest available versions of all packages that currently have updates, but doesn’t remove any packages.
  • $ sudo apt full-upgrade Performs a complete system upgrade by installing the newest versions of all packages and handling changing dependencies, including removing obsolete packages. Recommended for a full system upgrade.
  • $ sudo apt autoremove Removes packages that were automatically installed to satisfy dependencies for other packages but are no longer needed.
  • $ sudo apt list --installed Lists all currently installed packages on the system.
  • $ sudo do-release-upgrade Upgrades the system to the latest Long-Term Support (LTS) release of Ubuntu or other Linux distributions using the same command structure.
  • $ sudo do-release-upgrade -d Upgrades the system to the latest available development release (non-LTS) of the distribution.

Processes-related commands

  • $ sudo systemctl enable [name] Enables a service to start automatically on boot.
  • $ sudo systemctl disable [name] Disables a service, preventing it from starting automatically on boot.
  • $ sudo systemctl start [name] Starts a specified service immediately.
  • $ sudo systemctl restart [name] Restarts a specified service.
  • $ sudo systemctl status [name] Displays the current status of a specified service, including whether it's running, enabled, or if there are any errors.
  • $ sudo systemctl kill [name] Terminates all processes associated with a specified service. This command sends a termination signal to the service, effectively stopping it immediately. It’s useful when a service becomes unresponsive and needs to be forcefully stopped.
  • $ sudo chmod u+x /opt/[folder]/[executable] Grants the user (u) execute (+x) permission for the specified executable file located in the /opt/[folder]/ directory, allowing the user to run that executable.
  • $ tail -f /proc/[pid]/fd/1 Monitors the real-time output (stdout) of a specific process by its Process ID (PID). Replace 1 with 2 to track the error output (stderr). This is useful for debugging or monitoring process logs.
  • $ journalctl -f -u myservice Continuously displays real-time log output for the myservice.service.
  • $ journalctl -ef -u myservice Jumps to the most recent log entries for myservice.service and continues to display new logs in real-time.
  • $ sudo lsof -p $PID Lists all open file handles associated with the process ID ($PID) of a service.
  • $ sudo lsof | awk '{ print $1 " " $2; }' | sort -rn | uniq -c | sort -rn | head -15 Displays the top 15 processes with the highest number of open file handles by using lsof, filtering and sorting the output for easier analysis.
  • $ sudo nano /etc/security/limits.conf Opens the limits.conf file in the text editor nano with superuser privileges (sudo). This file is used to configure system-wide limits for users, including the maximum number of open file handles (nofile) for all users or specific users. You can modify this file to increase or adjust the system limit for open file handles.
  • $ sudo nano /etc/systemd/user.conf Opens the user.conf configuration file in nano with superuser privileges. This file is used to set limits for individual users or processes running under systemd, including limits on resources like open file handles (NOFILE). You can modify this file to set per-user or per-process limits on open file descriptors.

Commands to create a process

Here’s a step-by-step guide to creating a process that runs at startup using a .service file with the necessary Linux commands:

  • $ cd /etc/systemd/system/ Navigate to the systemd directory where .service files are stored, typically /etc/systemd/system/.
  • $ sudo nano myservice.service Use sudo nano or any text editor to create and edit a new .service file.

Define the service in the file, this is our recommendation:


[Unit]
Description=[description]

[Service]
Type=simple
ExecStart=/opt/[folder]/[executable]
# if the process crashed restart in 3 seconds, always
Restart=always
RestartSec=3
# forceful shutdown settings
KillMode=mixed
KillSignal=SIGTERM
SendSIGHUP=no
SendSIGKILL=yes
FinalKillSignal=SIGTERM
# setup the NOFILE limit as well
LimitNOFILE=2147483647

[Install]
WantedBy=multi-user.target

Make sure to save the file, then:

  • $ sudo systemctl daemon-reload Reload the systemd daemon to apply the changes.
  • $ sudo systemctl restart myservice.service Restart (or start) the service.

Firewall-related commands

  • $ sudo apt install ufw Installs the UFW (Uncomplicated Firewall) package.
  • $ sudo ufw status verbose sudo ufw status verbose:
  • $ sudo ufw app list Lists all the applications that have firewall profiles available.
  • $ sudo ufw app info 'OpenSSH' Shows detailed information about the firewall rules for the 'OpenSSH' application.
  • $ sudo ufw allow ssh Allows SSH connections through the firewall.
  • $ sudo ufw allow 7722/tcp Allows incoming connections on TCP port 7722.
  • $ sudo ufw enable Enables the UFW firewall to start enforcing rules.
  • $ sudo ufw disable Disables the UFW firewall to start enforcing rules.
  • $ sudo ufw allow from 192.168.1.0/24 to any port 3306 Allows connections from the 192.168.1.0/24 network to port 3306.
  • $ sudo ufw delete allow 22 Deletes the rule that allows incoming connections on port 22 (typically used for SSH).