Basic Linux commands

The commands below are the ones you are most likely to need when working on a Linux server over SSH.

Navigation and files

  • pwd — print the current directory.
  • ls -la — list files including hidden ones, with permissions and size.
  • cd /path/to/dir — change directory; cd .. goes up one level.
  • cp source target — copy a file; cp -r copies a directory recursively.
  • mv source target — move or rename.
  • rm file — delete a file; rm -r dir deletes a directory recursively. There is no confirmation prompt, so take care.
  • mkdir dir — create a directory.
  • cat file, less file — view a file's contents.
  • tail -f /var/log/messages — follow a log in real time.
  • grep "text" file — find matching lines; grep -r searches a directory tree.
  • find /path -name "*.conf" — find files by name.
  • chmod 644 file, chown user:group file — change permissions and ownership.

Disk and memory

  • df -h — free space on mounted filesystems.
  • du -sh /path — size of a directory.
  • free -m — memory usage in megabytes.

Processes

  • ps aux — list all processes.
  • top — interactive process monitor (see server monitoring).
  • kill PID — terminate a process; kill -9 PID forces it.

Network

  • ip a — network interfaces and addresses.
  • ss -tulpn — open ports and the processes listening on them.
  • ping -c 4 example.com — check that a host is reachable.
  • curl -I https://example.com — show HTTP response headers.

Services and packages

Modern distributions (AlmaLinux, Rocky Linux, CentOS 7 and later, Ubuntu 16.04 and later) manage services with systemd:

  • systemctl status httpd — service status.
  • systemctl start|stop|restart httpd — control a service.
  • systemctl enable httpd — start it at boot (see this article).

Installing packages:

  • AlmaLinux / Rocky / CentOS: dnf install package (yum install package on CentOS 7).
  • Ubuntu / Debian: apt install package.

System

  • uname -a — kernel version.
  • uptime — uptime and load average.
  • reboot, shutdown -h now — restart and shut down.

Ready to start?

Pick a plan — your server will be ready in 15 minutes.