Ubuntu has quickly become one of the most popular Linux Operating Systems. For a newbie, using the Command Line Interface may be a bit overwhelming. We have put together a list of basic Ubuntu commands to help you with command line tasks.
Most commands will require you to “sudo”. Sudo allows you to run commands with elevated permissions. When you use sudo, you will be prompted for your administrator password.
All the commands below can be ran via an SSH session or a Terminal session within Ubuntu.
Table of Contents:
Updating & Installing Packages
Get updated package list for Ubuntu:
sudo apt-get update
Apply security updates and patches for Ubuntu:
sudo apt-get upgrade
Note: The “sudo apt-get upgrade” command will fetch files from the default Internet or Local mirrors. The location of the update repositories are “/etc/apt/sources.list”. You need NOT to make any changes to this repository file unless you need to add custom repositories.
Apply kernel updates for Ubuntu:
sudo apt-get dist-upgrade
sudo reboot
Upgrade individual packages for Ubuntu:
sudo apt-get install <package-name>
sudo apt-get install <package-name> <package-name> <package-name>
Note: Replace <package-name> with the application package name to upgrade it individually. You may alternatively upgrade multiple applications at once by running the same command but separating them by a space. If you do not know the package name, use the command below to view a list of packages currently installed on your system.
dpkg --list
Remove individual packages for Ubuntu:
sudo apt-get remove <package-name>
Other Basic Ubuntu Commands
“cd” – Change to a different directory
The following command will take you to the “home” directory:
cd /home
The following command takes you up one directory level:
cd ..
The following command takes you to the previous directory:
cd -
“ls” – List contents of a directory
The following command will provide a list of files and folders in the current directory:
ls
“mkdir” – Make a new directory
The following command with make a new directory (folder) in the current directory:
mkdir <new-directory-name>
Note: Replace <new-directory-name> with the name of the directory you would like to create.
“cp” – Copy a file
The following command will copy a file from the current directory to another:
cp <filename> <directory>
Note: Replace <filename> with the name of the file you want to copy. Replace <directory> with the name of directory you want to copy to. Example: /home/user
“mv” – Move a file
The following command will move a file from the current directory to another:
mv <filename> <directory>
Note: Replace <filename> with the name of the file you want to move. Replace <directory> with the name of directory you want to move to. Example: /home/user
“rm” – Remove a file
The following command will remove a file:
rm <filename>
Note: Replace <filename> with the name of the file you want to remove.