Skip to content
RIPE NCC member · Local Internet RegistryCall us on 020 3318 3449sales@hosting-telecom.uk

Basic Linux commands

A quick reference for working on a server: files and folders, permissions, disk space, processes, services, logs and networking.

Contents

The commands you will need most often when working on a server over SSH. For detailed help on any command, use man command or command --help.

Files and folders

pwdwhere am I now
ls -lathe contents of a folder, including hidden files, with permissions and sizes
cd /var/www, cd ~, cd -go to a folder, to your home folder, to the previous folder
mkdir -p a/b/ccreate a folder along with any missing parent folders
cp -a source destinationcopy, keeping permissions and dates; works for folders too
mv source destinationmove or rename
rm file, rm -r folderdelete a file or a folder
cat, lessshow a file in full, or page by page (to quit less, press q)
tail -f /var/log/filefollow the end of a file, such as a log (press Ctrl+C to stop)
Warning rm doesn’t ask for confirmation and doesn’t move files to a bin. Before deleting a lot of files on a cloud server, take a snapshot.

Searching

find /var/www -name '*.php' -mtime -1.php files changed in the last 24 hours
grep -rn 'text' /etc/nginx/lines containing the text in all files in a folder, with line numbers
command -v phpwhere a program is located — more in Finding where a program is located

Permissions and owners

chmod 644 fileread and write for the owner, read for everyone else — the usual permissions for a file
chmod 755 folderthe same, plus entering the folder or running it — the usual permissions for a folder or script
chown -R www-data:www-data /var/www/sitechange the owner of a folder and everything in it
sudo commandrun a command with administrator rights

For what the permission numbers mean and how to set permissions on website files, see File permissions: chmod and chown.

Disk space and memory

df -hhow much space is used and free on your disks
du -sh /var/* | sort -hwhich folders take up the most space — the largest at the bottom
free -hmemory (RAM)

If your disk is full and you need to know what can be deleted, see Out of disk space.

Processes

topwhat is using the CPU and memory right now (to quit, press q); htop is easier to use, if it is installed
ps aux | grep nginxfind processes by name
kill 1234end a process by its number — more in Which program is using a port

To work out what is holding your server back, see Slow server: how to find the cause.

Services and logs

systemctl status nginxwhether a service is running, and the last lines of its log
sudo systemctl restart nginxrestart it; reload re-reads the settings without stopping it
sudo systemctl enable --now nginxstart it and make it start at boot
journalctl -u nginx -n 50the last 50 lines of a service’s log; -f keeps following it

To see the log for a particular hour, errors only, or the previous boot, see Logs: journalctl and /var/log.

Network

ip -4 addr, ip routethe server’s addresses and gateway
sudo ss -ltnpwhich programs are listening on which ports
ping -c 4 hosting-telecom.ukwhether an address is reachable
curl -I https://websitea website’s response: status code and headers
dig website A +shorta DNS record (the dnsutils package on Debian and Ubuntu, bind-utils on AlmaLinux)

Archives

tar -czf site.tar.gz /var/www/sitepack a folder into an archive
tar -xzf site.tar.gzunpack into the current folder

For zip, other kinds of compression and exclusions, see Archives: tar, gz and zip. To copy files to another server, see rsync.

Updating the system

Ubuntu, Debiansudo apt update && sudo apt upgrade
AlmaLinuxsudo dnf upgrade
FreeBSDsudo pkg upgrade — in our images this updates both the system and your software (more in FreeBSD on a cloud server)

Keyboard shortcuts make the command line easier to work with — they are collected in Command-line keyboard shortcuts.

Run long commands in tmux: if your SSH connection drops, they will carry on and finish.

Didn’t find the answer? Ask our support team — we’ll help.

Choose which cookies we may use. You can change your mind at any time with the “Cookie settings” link at the bottom of every page.

Necessary

Always active

They keep the site secure and remember your cookie choice. They don’t identify you.

Google Analytics counts visits and shows which pages people find useful, so we can improve the site. Which cookies