- 25 basic Ubuntu Commands
- What are the basic commands of Ubuntu
- Command 1: pwd
- Command 2: dir
- Command 3: ls
- Command 4: cd
- Command 5: touch
- Command 6: cat
- Command 7: mkdir
- Command 8: rm
- Command 9: cp
- Command 10: mv
- Command 11: head
- Command 12: tail
- Command 13: uname
- Command 14: wget
- Command 15: apt-get or -apt
- Command 16: history
- Command 17: grep
- Command 18: man
- Command 19: ps
- Command 20: zip or unzip
- Command 21: hostname
- Command 22: ping
- Command 23: w
- Command 24: useradd
- Command 25: passwd
- Conclusion
25 basic Ubuntu Commands
Ubuntu is the most popular Debian-based distribution of Linux Operating System; It was initially released in 2004. Due to its distinctive features, various distros of Linux are developed based on Ubuntu. It is developed and maintained by Canonical Ltd. and a large community of software developers around the globe; Canonical Ltd. is a software company with its origin in the UK, and it has hired staff in several countries to work for Ubuntu. There are several releases of Ubuntu, such as stable release, Long Term Support (LTS), and unstable. The stable and unstable releases are launched every year in April and October, respectively, whereas the long-term support variant is released after two years and is available for the next five years. The latest LTS release is 20.04; it will be available till 2025. Ubuntu supports both Command Line Interface (CLI) and Graphical User Interface (GUI) to perform various tasks on the OS. CLI is the basic way to interact with systems hardware (processor/memory); you can perform all the tasks that GUI can perform. In this article, we will demonstrate the use of 25 basic commands that provide ease to execute various tasks of Ubuntu using CLI.
What are the basic commands of Ubuntu
This section contains some basic commands of Ubuntu, so let us start and discuss them one by one. Firstly, you must open the terminal in Ubuntu; press “ctrl+alt+t” from your keyboard to open the terminal.
Command 1: pwd
This command refers to the present working directory in which you are operating; in simpler words, in which your terminal is open. To check PWD, execute the pwd keyword in your terminal and hit enter; the command of PWD is written below along with the result of that command.
Command 2: dir
The dir command is used to print (on the terminal) all the available directories in the present working directory:
Command 3: ls
This command is used to list down all the directories and files inside the present working directory (or you can give the path of a specific directory); the ls command can be executed as shown below:
The ls command supports various flags, and each flag has some specific role in printing the directories or files of the current working directory.
To print the detailed information of the files/directories; the “-al” flag is used with the “ls” command:
The “-R” flag will print subdirectories of a directory as well:
Moreover, to get the hidden files, “-a” flag is used:
Command 4: cd
One of the most used commands of Ubuntu; you can change the directories in the terminal using the “cd” command. For instance, the following command will change the pwd to desktop.
There are multiple uses of this command: one can change the present directory to root directory or home directory using this command. When you open a fresh terminal, you are in the home directory.
To change directory to root. For instance, we are in the Desktop directory and want to switch to the root directory:
To change the present directory to the home directory:
Command 5: touch
This Ubuntu command can be used to create a new file as well one can use it to change the timestamp of any file; the command given below will create a new text time in pwd:
If we execute a touch command to create a file, but the file is already created, then it would change the timestamp of that file to the current time; for instance, the command given below will change the timestamp of the file1.txt. you can check that the timestamp has been changed to the current time:
Command 6: cat
This command is used to show the content of any file: For instance, the following command will display the content inside “file1.txt”:
Or you can use this command to save the content of multiples files to one file:
Command 7: mkdir
The above-mentioned command will make a directory in your pwd; for example, the following command will make the directory “new” in pwd.
Command 8: rm
This remove command is used to remove the specific file from a directory; For instance, below mentioned command would remove the “test.txt” file from the pwd:
Or you can remove the empty directory, as the command given below will remove the “test” directory:
Command 9: cp
The cp command will help you to copy any file or folder to any directory;
To copy a file to directory1:
If you want to copy the complete folder, then;
Command 10: mv
You can use this command to move files around the computer, and you can also rename files or directories inside a specific directory: the command given below will move the “file2.txt” to “directory1”:
Moreover, the command given below will move the “test1” directory to “directory1”:
Command 11: head
This command helps you to get the first ten lines of a text file; for instance, the following command will help to get the first ten lines of the “file1.text” file:
Command 12: tail
The tail command is used to get the last ten lines of the text file; the command below will print the ten lines from the bottom of “file1.txt”:
Command 13: uname
You can use the command to get the release number, version of Linux, and much more. The “-a” flag is used to get detailed information.
Command 14: wget
You can use the wget command to download the content from the internet; for instance, the following command will download VirtualBox.
Command 15: apt-get or -apt
This is one of the most important and most used commands of Ubuntu that works with Ubuntu Advanced Packaging Tool (APT); you can use this “-apt-get” or “-apt” to install or remove packages, or you can perform other maintenance tasks. The “apt” requires sudo privileges to successfully execute the command.
The syntax stated below will help you to install the required package:
For install to install vlc media player package use:
Or you can remove the package by executing the command given below:
And to delete vlc media player package:
Command 16: history
The history command shows the list of commands (with numeric numbers) executed:
And you can execute any of the listed commands. For instance, if you want to execute the 2nd command (which is apt update command), then you have to write “!2” to get the result of that command:
Command 17: grep
With the help of grep, you can search for a pattern in which a specific word lies; for instance, the command given below will print all the lines that contain “20” from “file1.txt”:
Command 18: man
The man command will help you to get the complete user manual of any specific command; for instance, the following command will list down the detailed usage of the “cat” command:
Command 19: ps
Using the -ps command, you will be able to get the list of processes.
Command 20: zip or unzip
To convert your files to zip archive; you can get help by using the “gzip” command; moreover, a zipped file can be unzipped using the “gunzip” command:
You can unzip the “file1.txt” as shown below:
Command 21: hostname
This command will print your hostname on the terminal:
Command 22: ping
You can use the ping command to check the connectivity to your server; for example, the command below will ping to YouTube and also prints the response time:
Command 23: w
This command will display the user details that are currently logged into the system:
Command 24: useradd
Ubuntu supports multiuser access; if you want to add another user to your system, execute the following command to do so:
Or you can delete the user also;
Command 25: passwd
With the help of the passwd command, you can change the password of your Ubuntu user:
You must pass “username” to “passwd” to change the password of that; for example, the command given below will change the password of user “adnan”.
Conclusion
Command-line interface (CLI) is the basic utility of any machine; you can use it to perform multiple tasks and can perform all those operations that can be performed using GUI. It is not just a simple app; it is key to every operating system as there are terminal commands behind GUI operations. All in all, CLI can be used to operate the entire operating system without GUI. Like other OS, Ubuntu also contains a terminal that supports hundreds of commands to perform different operations. This article lists down the most used Ubuntu commands and their usage. Every command can perform a specific task and can help you to automate the requested action.