Linux For Beginners – Part II – Working with Terminal

Share

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.

03
Figure 1 – Unity Menu

In this article you will be instructed about basic terminal commands.

Basic Ubuntu Terminal Commands

    1. 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.

      • $ ls

Figure 2
Figure 2

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

Figure 3
Figure 3

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

Figure 4
Figure 4

If you need to sort files by modification date, you could use -t option.

      • $ ls -t

Figure 5
Figure 5

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

Figure 6
Figure 6
      • $ ls –help

    1. cat – Get content of a file, concatenate and list files

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.

Figure 7

Using following command we could print the content in a file in the terminal.

  $ cat <fileName> 
Figure 8
Figure 8

Using following command you could copy the content of a file into another new file.

  $ cat fileName > newFileName 
Figure 9
Figure 9

Also you could concatenate content of two or more files into a new file using following command.

  $ cat file1Name file2Name > newFileName 
Figure 10
Figure 10
    1. pwd – Print Working Directory

This command will simply prints the current working directory on the terminal.

$ pwd
Figure 11
Figure 11
    1. 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.

 $ cd
Figure 12
Figure 12

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 ~
Figure 13
Figure 13
Figure 14
Figure 14

If you need to go to the parent directory, you could use following command.

 $ cd ..
Figure 15
Figure 15

You could go to root directory using following command.

 $ cd /
    1. mkdir – Make Directory

You could make a folder using mkdir command.

 $ mkdir
Figure 16
Figure 16
    1. rm – Remove

With rm command you could remove file and directories from your Linux PC. To remove a file use following command.

 $ rm
Figure 17
Figure 17

To remove directory, you could use Remove directories and their contents recursively option with rm command.

 $ rm -R
Figure 18
Figure 18

You could use rmdir command to delete directories too. Try and find out how to use rmdir command to remove directories.

    1. 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.

 $ cp
Figure 19
Figure 19

If you have files inside directory, you should add -R option to copy files and directories recursively.

 $ cp
Figure 20
Figure 20
    1. mv – Move

In Linux based operating systems, we use mv command to move and rename files and directories. Use following command to move files.

 $ mv
Figure 21
Figure 21
    1. clear

If you need to clear the terminal window, you could use clear command.

 $ clear
    1. exit

To exit from the terminal, you could use exit command.

 $exit
    1. reboot

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.

    1. shutdown

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 fosmediar@gmail.com .

 Thank you.

 
Tagged : / /