Advertisement

  • Understanding Command-line in Ubuntu


    When we talk about the command-line, the first thing that strikes our mind is the issuing of instructions to the system to handle different tasks using typed commands.Well, for a user who shifts to Linux from Windows or other operating systems which have usually a GUI ( Graphical User Interface), he nay feel unusual or a bit uncomfortable during his initial days. Many Linux distros now have an option of installing a GUI. But, command-line offers flexibility and more power to a Linux proffessional.

    So, lets understand how commands in Linux work.

    1. Access the command line through the Terminal program.

    (Applications--Accessories--Terminal).

    When the terminal program initiates the following line appears. 

    jack@mypc:~$ This line will be different for different ubuntu installations. The part " jack" stands for the user who is logged in at present and the text after @ "mypc" is the name of the computer also reffered to as the hostname. Hostname is the name of the computer as displayed on an internet network. It is also used to access your computer remotely across the internet. For the person who has installed Ubuntu himself, he will realise that the user and hostname values which appear in this prompt were given during the installation of Ubuntu.

    So, in short, the prompt tells us who the user is and where he is logged in.

    2. The part after the colon(:) indicates the location in the file system where we are working at. The symbol ~ (tilde) refers to the user's home directory. So, ~ stands for /home folder of the user. In the case of jack it is /home/jack/ .

    3. The $ sign tells that the user is logged in as an ordinary user which means that you do not have administrative priviliges to modify the system. When a user logs in as a root user, the $ sign changes to # (hash).

    So, summing up, the prompt says that it is the user "jack" who is logged in at "mypc" as an ordinary user and is currently working in the /home folder.

    Now, lets try our hand at a very simple command "ls" . Executing ls lists all the files available which looks something as shown below.

    Desktop Documents Music Pictures Public Templates Videos

    The command "cd" is used to change the working directory to a desired one.

    cd Pictures changes the working directory to Pictures and the prompt changes to jack@mypc:~/Pictures$

    cd Videos results in jack@mypc :~/Videos$

    Be sure to leave the pictures directory before changing to the Videos directory.( Use cd~ to go back to the /home folder). Otherwise, it shows an error as below.

    jack@mypc:~/Pictures cd Videos -bash: cd : Videos : No such file or directory

    This is because the system looks for Videos in Pictures directory, but it is in /home folder.

    The difference between the command 'cd' and 'ls' is that 'cd' takes arguments i.e it has to be told with whom to work with.

    jack@mypc:~$ cp ~/Videos/Zombie.mp3 ~/Music

    This command 'cp' also takes arguments i.e it is needed to be specified which file has to copied from which file to where. Arguments are generally separated by a space.

    This becomes more clear by understanding the difference between the commands given below.

    ls lists all the files.

    ls -l lists all the files with their date of creation and the user.

    ls -a lists all the files even the hidden ones.

    ls -la lists all files, the hidden ones with their user and the time of creation.

    ls --help lists all the properties associated with the command.

    more