Basic Linux commands
If you're new to Linux servers, knowing just the commands below lets you do most tasks. Connect with SSH and try typing them in as shown.
Moving around and viewing files
pwd # The folder you're in now
ls -al # List files in the current folder (including hidden files)
cd /var/www # Change folder
cd ~ # Go to your home folder
cat myfile # Show a file's contents
less myfile # View a long file (q to exit)
Creating, copying, moving and deleting files and folders
mkdir folder # Create a folder
cp orig copy # Copy a file (for folders, cp -r)
mv oldname newname # Rename / move
rm myfile # Delete a file
rm -r folder # Delete a whole folder
⚠️ Linux has no recycle bin. Files deleted with
rmcan't be recovered, so use it carefully.
Editing files (nano)
nano myfile
After editing, save with Ctrl + O → Enter, and exit with Ctrl + X.
Administrator privileges (sudo)
When changing system settings or installing programs, put sudo in front of the command.
sudo apt update # Refresh the list of programs you can install
sudo apt upgrade -y # Update all installed programs
sudo apt install -y htop # Install a program
Checking server status
df -h # Disk usage
free -h # Memory usage
htop # See which programs use the most CPU/memory (q to exit)
uptime # How long the server has been on
Managing services (background programs)
Programs like web servers and DBs run as services.
sudo systemctl status nginx # Check status
sudo systemctl restart nginx # Restart
sudo systemctl enable nginx # Start automatically at boot
journalctl -u nginx -f # View live logs (Ctrl + C to exit)
Stopping a running program
ps aux | grep name # Find the program (the second column is the PID)
kill PID_NUM # Ask it to stop
kill -9 PID_NUM # Force it to stop
Rebooting
sudo reboot
Clicking the Reboot button on your Dashboard does the same thing. As a next step, we recommend Basic server security setup.