Ubuntu Server CLI Commands: A Cheat Sheet For Beginners


Ubuntu Server is one of the most widely used Linux distributions for running servers. If you are just getting started with Ubuntu Server, then you may find it difficult to remember all the commands needed to manage your server. In this blog post, I will provide you with a cheat sheet of the most useful Ubuntu Server commands, along with a brief explanation of what they do.

    sudo: This command is used to execute a command with root privileges. It stands for "superuser do". You need to type sudo before any command that requires root access.

    apt: This command is used to install, update, and remove packages on Ubuntu. It stands for "Advanced Package Tool". To install a package, you would use the command sudo apt install <package-name>. To update all installed packages, use sudo apt update followed by sudo apt upgrade. To remove a package, use sudo apt remove <package-name>.

    systemctl: This command is used to manage system services on Ubuntu. You can use it to start, stop, restart, enable, and disable services. To start a service, use sudo systemctl start <service-name>. To stop a service, use sudo systemctl stop <service-name>. To restart a service, use sudo systemctl restart <service-name>. To enable a service to start automatically on boot, use sudo systemctl enable <service-name>. To disable a service from starting automatically on boot, use sudo systemctl disable <service-name>.

    ufw: This command is used to manage Ubuntu's Uncomplicated Firewall. You can use it to enable or disable the firewall, as well as to open or close ports. To enable the firewall, use sudo ufw enable. To disable the firewall, use sudo ufw disable. To allow incoming traffic on a specific port, use sudo ufw allow <port-number>. To deny incoming traffic on a specific port, use sudo ufw deny <port-number>.

    ls: This command is used to list the files and directories in the current working directory. To list all files and directories (including hidden ones), use ls -a. To list files in long format, use ls -l. To list files in long format with human-readable file sizes, use ls -lh.

    cd: This command is used to change the current working directory. To change to a directory, use cd <directory-name>. To change to the home directory, use cd ~. To change to the previous directory, use cd -.

    pwd: This command is used to print the current working directory.

    mkdir: This command is used to create a new directory. To create a directory, use mkdir <directory-name>.

    rm: This command is used to remove files or directories. To remove a file, use rm <file-name>. To remove a directory and its contents, use rm -r <directory-name>.

    tar: This command is used to create, list, and extract tar archives. To create a tar archive, use tar -czvf <archive-name>.tar.gz <directory-to-archive>. To list the contents of a tar archive, use tar -tvf <archive-name>.tar.gz. To extract a tar archive, use tar -xzvf <archive-name>.tar.gz.

These are some of the most useful Ubuntu Server commands that you will need to know. As you become more comfortable with Ubuntu Server, you will find that there are many more commands that can be used to manage your server.