20 Essential Linux Commands You Should Know
Most VPS administration happens in the terminal. These 20 commands cover everyday tasks: moving between directories, working with files, installing software and managing processes.
What you need before you start
- A VPS running Linux, e.g. Ubuntu or Debian.
- An SSH client to connect to the server. More: How to use PuTTY.
- A user with root or sudo privileges.
Commands
-
Moving between directories
ls lists the files and folders in a directory. With -l you’ll see size, date and permissions:
ls -lAdd -a to also see hidden files (starting with a dot):
ls -lacd changes the current directory:
cd /home/user/DocumentsGo up one directory:
cd ..pwd shows the full path of the directory you’re in:
pwd -
Files and folders
mkdir creates a new folder:
mkdir new-folderWith -p it also creates any missing parent folders:
mkdir -p projects/site/imagestouch creates an empty file. If the file already exists, it updates its modification time:
touch file.txtcp copies a file:
cp file.txt copy.txtCopying a folder requires -r:
cp -r folder1 folder2mv moves a file to another folder:
mv file.txt folder/The same command is used to rename a file:
mv old.txt new.txtrm deletes a file:
rm file.txtDeleting a folder with all its contents requires -r:
rm -r folder/Be carefulLinux has no recycle bin. Deleted files are gone for good, and a typo in a path with sudo rm -r can wipe the whole system.
-
File contents and search
cat shows a file’s contents in the terminal:
cat file.txtnano opens a file in a simple terminal text editor:
nano file.txtHow to saveCtrl + O and Enter saves the file, Ctrl + X exits the editor.
grep searches for text in a file:
grep "text" file.txtWith -r it searches all files in the current directory and subdirectories:
grep -r "text" .find finds files by name:
find . -type f -name "file.txt"Finding a folder:
find . -type d -name "folder" -
Administration and software
sudo runs a command with administrator privileges. Just put it in front of another command:
sudo apt updateapt manages software on Ubuntu and Debian. First update the package list and the system:
sudo apt update && sudo apt upgradeInstalling a program:
sudo apt install package-namechmod changes file and folder permissions. For example, the owner can do everything and others can only read and execute:
chmod 755 script.shThe simplest way to make a script executable:
chmod +x script.sh -
Archives and disk
tar creates a compressed archive:
tar -czvf archive.tar.gz folder/Extracts an archive:
tar -xzvf archive.tar.gzdf shows how much disk space is used and free:
df -hTo see how much space a specific folder takes, use du:
du -sh folder/ -
Processes and history
ps shows all running processes:
ps auxFinding a specific process:
ps aux | grep nginxkill stops a process by its ID (PID), which you’ll see in the ps output:
kill 12345If the process won’t stop, force it:
kill -9 12345history shows previously entered commands:
history
Practice
Try a few commands safely. This line creates a folder with a file inside, lists it and deletes everything:
mkdir test && cd test && touch file.txt && ls -l && cd .. && rm -r testThe && symbols chain commands: the next one runs only if the previous one succeeded.
Enter man ls or ls --help, replacing ls with the command you want. Press Q to exit the man page.
FAQ
I get “Permission denied”
The command needs administrator privileges. Run it again with sudo in front.
I get “command not found”
Check the command for typos. If it’s correct, the program isn’t installed, and you can install it with sudo apt install.
How do I stop a long-running command?
Press Ctrl + C.
Does apt work on all Linux systems?
No. apt is used on Ubuntu and Debian. On AlmaLinux or Rocky Linux, dnf is used instead.
What’s next
If you have questions, contact us via live chat or email.