Back Back

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

  1. Moving between directories

    ls lists the files and folders in a directory. With -l you’ll see size, date and permissions:

    ls -l

    Add -a to also see hidden files (starting with a dot):

    ls -la

    cd changes the current directory:

    cd /home/user/Documents

    Go up one directory:

    cd ..

    pwd shows the full path of the directory you’re in:

    pwd
  2. Files and folders

    mkdir creates a new folder:

    mkdir new-folder

    With -p it also creates any missing parent folders:

    mkdir -p projects/site/images

    touch creates an empty file. If the file already exists, it updates its modification time:

    touch file.txt

    cp copies a file:

    cp file.txt copy.txt

    Copying a folder requires -r:

    cp -r folder1 folder2

    mv moves a file to another folder:

    mv file.txt folder/

    The same command is used to rename a file:

    mv old.txt new.txt

    rm deletes a file:

    rm file.txt

    Deleting a folder with all its contents requires -r:

    rm -r folder/
    Be careful

    Linux 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.

  3. File contents and search

    cat shows a file’s contents in the terminal:

    cat file.txt

    nano opens a file in a simple terminal text editor:

    nano file.txt
    How to save

    Ctrl + O and Enter saves the file, Ctrl + X exits the editor.

    grep searches for text in a file:

    grep "text" file.txt

    With -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"
  4. Administration and software

    sudo runs a command with administrator privileges. Just put it in front of another command:

    sudo apt update

    apt manages software on Ubuntu and Debian. First update the package list and the system:

    sudo apt update && sudo apt upgrade

    Installing a program:

    sudo apt install package-name

    chmod changes file and folder permissions. For example, the owner can do everything and others can only read and execute:

    chmod 755 script.sh

    The simplest way to make a script executable:

    chmod +x script.sh
  5. Archives and disk

    tar creates a compressed archive:

    tar -czvf archive.tar.gz folder/

    Extracts an archive:

    tar -xzvf archive.tar.gz

    df shows how much disk space is used and free:

    df -h

    To see how much space a specific folder takes, use du:

    du -sh folder/
  6. Processes and history

    ps shows all running processes:

    ps aux

    Finding a specific process:

    ps aux | grep nginx

    kill stops a process by its ID (PID), which you’ll see in the ps output:

    kill 12345

    If the process won’t stop, force it:

    kill -9 12345

    history 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 test

The && symbols chain commands: the next one runs only if the previous one succeeded.

Help for any command

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.

Similar tutorials

VPS Tutorials