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 -rcopies a directory recursively.mv source target— move or rename.rm file— delete a file;rm -r dirdeletes 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 -rsearches 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 PIDforces 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 packageon 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.