20 Basic Ubuntu commands
Note: Each command has its own additional parameters to extend its functionality but in this article, we won’t go into that much detail. Consider it to be a basic introduction to the basic Ubuntu commands.
- mkdir (Make Directory) One of the common actions that you may want to take is to create a new folder or even go a step further to create a subfolder. To perform these functions, you will have to use the mkdir command and type the name of the folder after it. Example: [email protected]:/# mkdir test This command will create test directory at the root directory of your server.
- ls (List) ls command stands for list. You will use it whenever you want to see everything that is in your directory. It will display all the files and folders that exist in the current directory that you have opened. To use it, just type the directory name then follow it up with the ls. Example: [email protected]:~# ls This command will list all the files and folders that are in the server’s root directory sys/ test/ tmp/ usr/ var/
- cd (Change Directory) cd is a command for changing a directory in the terminal. It is one of the basic Ubuntu commands that you cannot avoid, no matter what. To use it, you simply need to type the name of the folder that you want to move to. Example: [email protected]:~# cd /test now you’re inside test directory [email protected]:/test# Basic commands to remember:
[email protected]:~# cd / this will open the root directory. [email protected]:~# cd .. open one level up directory. [email protected]:~# cd - will open the home directory
- cp (Copy) This is the most obvious command, whether you are a newbie or not. It stands for copy-and-paste. It will come handy when you want to organize your files on the computer. To use it, you need to know the file name and the target destination where you will paste it. If the file that you want to copy and paste requires permission from the root, then you will have to use the des command. Example: [email protected]:/test# cp t1/* t2 This command will copy all the files from t1 folder into folder t2. Also, Read: Important Advanced Linux Commands for Programmers
- sudo (SuperUserDo) This command stands for SuperUserDo. It is also a basic and an essential command for the Ubuntu newbies. You will always use it when typing other commands that require to gain permission from the root (if you are not a root user). You simply need to place this command before the command that you want to execute with root permission. Example: [email protected]:~$ sudo service apache2 restart This command will let you restart the web server with root permission. However, you’ll have to enter your password for once.
- rm (Remove) The rm command is used for removing files and directories from their current location. You should use -f if the file requires permission from the root and -r if you want to perform a recursive removal of the folder. Example: [email protected]:/test# rm -rf t2 This command will delete the t2 directory and all its content from the test directory.
- find (find) Sometimes you may need to use a file but you can’t find its exact location or remember its path, use the find command. It will help you to find that file with ease. You only need to type this command then add some keywords about the file. Example: [email protected]:/test# find t1 t1 t1/xd.p As you can see it found everything related to t2 in the test directory
- poweroff (Poweroff computer) This command lets you switch the computer using the Ubuntu terminal. It is an ideal option for turning a computer off without using the mechanical method. if you are not a root user, you should type sudo command before typing poweroff. Example: [email protected]:/test# poweroff and the system will shut down
- Cat (concatenate) One of the common things that you may intend to do is to inspect texts and codes in your script. The cat command is used for viewing those texts and even codes that are in a particular file that you have opened. Example: [email protected]:/test/t1# cat hello.txt Hi, This is for testing only The above command is showing the text that was inside the hello.txt file.
- Pwd When using Ubuntu, it is always prudent to the current directory that you are working on. This will help you to know where you will go next. pwd is the best command for doing this job. It will print your current directory. Example: [email protected]:/test/t1# pwd /test/t1 the above command is showing the directory in which you are right now.
- mv (Move/rename) You will need this command whenever you want to move your file to a different location or give it a different name. When it comes to renaming, you need to type both the old and the new name. Remember to start with the des command for files that require permission from the root. Example: [email protected]:/test# mv t1/* t2 [email protected]:/test# mv t2 test2 [email protected]:/test# ls t1 test2 In the above example first command will move all the files from t1 to t2 and the next command will change the name of t2 folder to test2
- rmdir (Remove directory) Apart from removing files, you may also need to remove a directory. This is the command for doing this job. If you want to remove a directory named t1, just type “rmdir t1”. Example: [email protected]:/test# ls t1 test2 [email protected]:/test# rmdir t1 [email protected]:/test# ls test2 The command rmdir t1 successfully deleted the directory t1 from test directory.
- touch (Create blank file) The touch command is used for creating blank files in the Ubuntu terminal. It can be compared to the mkdir command for directories. You can use it to create a file in any directory that you want. Example: [email protected]:/test/test2# touch empty.txt [email protected]:/test/test2# ls empty.txt hello.txt The above command has created an empty text file named empty.txt under test2 directory.
- apt-get (Download, install, and update software) You will need this command when you are trying to install a software that you want to run in your Ubuntu PC. Apart from the installation, you will need this tool when upgrading and uninstalling your software. Since most of these actions will require to get permission from the root, you will always have to start by typing the sudo command. Example: [email protected]:/# apt-get install apache2 This command will install apache web server on your ubuntu os. you can also use apt-get command to update the system. [email protected]:/# apt-get update
- free (check free ram) You can use this command to check the amount of free and used RAM in your computer. Example: [email protected]:/test/test2# free total used free shared buff/cache available 2097152 598076 1417768 232288 81308 1424127 The above command showing how much ram is being used and available.
- df (Disk space) As a normal computer user, it is prudent to check the disk space that is available in your operating system. df is the command for checking disk usage in your Ubuntu. It is usually used along the -h parameter. Example: [email protected]:/test# df -h Filesystem Size Used Avail Use% Mounted on /dev/simfs 95G 2.3G 93G 3% / devtmpfs 1.0G 0 1.0G 0% /dev tmpfs 1.0G 0 1.0G 0% /dev/shm tmpfs 1.0G 99M 926M 10% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 1.0G 0 1.0G 0% /sys/fs/cgroup none 1.0G 0 1.0G 0% /run/shm The above command shows which file system is having how much disk space, how much is available and where it is mounted.
- Chmod (Change Permission) chmod is an important command that you can use to change file and directory permissions. These permissions include read, write and execute. You need to type chmod, followed by the specific permission then the filename or folder. Example: [email protected]:/test# chmod 755 test2 This command will grant Read + write + execute permission to the User and read + execute permission to the group and everyone else. Learn more about file permissions here.
- du (Directory usage) du command displays the size of a directory and all of its subdirectories. Example: [email protected]:/test# du 8 ./test2 12 .
- service (Run System V init scripts)
Service command is very useful command for running, stopping or restarting System V init scripts that are stored inside/etc/init.d directory.
Example:
[email protected]:~# service apache2 restart
This command will successfully restart your apache server.
20.
-–help This command will provide you all the details about the command you are running and the parameters associated with it Example: [email protected]:/test# mv –help Usage: mv [OPTION]… [-T] SOURCE DEST or: mv [OPTION]… SOURCE… DIRECTORY or: mv [OPTION]… -t DIRECTORY SOURCE… Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY. .. This above commands explain the working of mv command and list all the parameters associated with it.
Conclusion
Mastering all these basic Ubuntu commands may be hectic to a newbie. It is important that you start practising them daily. Once you are able to use these basic commands, you will have a smooth time graduating to the advanced Ubuntu commands.