Terminal is the most important component in a Linux operating system. In operating systems such as Ubuntu, you could use graphical ways to do your work also. If you need to install a software there’s a software center in Ubuntu. But still if you need to handle your system as you wish, you need to learn to use Linux terminal. So first of all launch the terminal emulator in Ubuntu using Ctrl + ALT + T shortcut or by searching in the unity menu.
In this article you will be instructed about basic terminal commands.
Basic Ubuntu Terminal Commands
- ls – List Directory Contents
If you need to list what you have in a directory you could use ls command. Basic way to use ls command is,
$ ls [OPTION]... [FILE]...
Now if you just enter ls in the terminal, you will get contents inside your directory.
There are some options that could be used with ls commands so you could get more details of the contents of your directory using those options.
If you use long format option (-l) with ls command you will get content with permissions, number of hard links, owner, group, size, last modified date and file name respectively.
$ ls -l
Now if you need to list all contents in a directory, use list all files in the given directory option (-a). This command will list all files in the directory including hidden files. In Linux, if you type dot “.” at the beginning of the file name, the file will be considered as a hidden file. So .user, .documents etc. will be hidden files.
$ ls -a
If you need to sort files by modification date, you could use -t option.
$ ls -t
When you’re using ls command, you could use multiple commands as you wish. If you need to list files in a directory in long format and get sizes of them in a human readable way, you could use both -l -h options to do so. Likewise you could use any number of options as you wish.
$ ls -l -h
$ ls –help
cat command is normally used to print the content of a file in the terminal. The syntax of the cat command is,
$ cat [OPTION]... [FILE]...
Here we have created a file to test the command which contains few text lines.
Using following command we could print the content in a file in the terminal.
$ cat <fileName>
Using following command you could copy the content of a file into another new file.
$ cat fileName > newFileName
Also you could concatenate content of two or more files into a new file using following command.
$ cat file1Name file2Name > newFileName
- pwd – Print Working Directory
This command will simply prints the current working directory on the terminal.
- cd – Change Directory
Change directory command is used to go into a folder in Linux. Way to use this command is,
$ cd [-L| [-P [-e]] [-@]] [DIRECTORY]
Now if you have a folder named NewDir in your current path, we could use following method to enter into this folder.
In Linux, user directory could represent using ~ sign. So if you need to go into user directory from anywhere, you could use one of following commands.
$ cd $ cd ~
If you need to go to the parent directory, you could use following command.
$ cd ..
You could go to root directory using following command.
$ cd /
- mkdir – Make Directory
You could make a folder using mkdir command.
- rm – Remove
With rm command you could remove file and directories from your Linux PC. To remove a file use following command.
To remove directory, you could use Remove directories and their contents recursively option with rm command.
$ rm -R
You could use rmdir command to delete directories too. Try and find out how to use rmdir command to remove directories.
- cp – Copy Files and Directories
Using cp command, we could copy directories and files from one directory to any other place. Use following command to copy files and folders.
If you have files inside directory, you should add -R option to copy files and directories recursively.
- mv – Move
In Linux based operating systems, we use mv command to move and rename files and directories. Use following command to move files.
If you need to clear the terminal window, you could use clear command.
To exit from the terminal, you could use exit command.
reboot command will restart your system. But this command needs root permission so you have to use sudo with the command and you need to know root password of your system.
$ sudo reboot or # reboot
having # means that you have gained root access in your terminal. If you have gained root access, then you don’t need to type sudo again.
shutdown command is also need root permission to execute. To halt system after shutdown, we put -h option with shutdown command. And we use now as time duration before shutdown the system so the system will immediately shuts down.
$ sudo shutdown -h now or # shutdown -h now
There more options for all those commands. So try command –help ($ls –help) to get help or search over the internet to get more details about those commands. Here we have mentioned basic operations of those commands.
This article will continue with new Linux methods and new Linux based things. Until then try surfing internet, find out new things and try to do them so you will learn more and more. If you have any question or ideas to improve this article, comment here or send an e mail to firstname.lastname@example.org .