Linux: Command Line Interface

Table of Contents

Related Tutorials

Command Line 

Introduction to the Shell

To explore the world of Linux, at first, you’ll need to get acquainted with the translator, the one who will do the talking for you. To operate the Linux system, you would need to put out commands for programs or tasks you’d want to execute. The program that recognizes your command from the keyboard and interprets it to the kernel for execution is called the shell. In different graphical user interfaces (GUI) you have probably used text-based interfaces called ‘Terminal’ or ‘Console’ which are just different representations of the shell, and they all have a similar purpose of operation at the core. 

Most Linux distributions are equipped with the default bash (Bourne again shell) program, and it is likely that you’ll use the same program as well. For rookies who don’t want to install Linux OS before getting a basic grasp of it, the web service JSLinux lets you run a Linux virtual module on your browser completely free. In this tutorial, I’ll be using the JSLinux service for easing the newcomers into it. 

Normally, most shell prompts end with a ‘$’ sign for normal users. Some come with other signs too, like the older shell prompts end with ‘%’. For root users, the sign changes to ‘#’. An image showing The JSLinux shell interface is shown below. Notice how the end sign is ‘#’, meaning the web service lets you login as a root user. 

4Je2jELLjrYTsZTHpLEa0 0fJvg3F8qmnmxC3pU8i7Wpc0roVIpqswn i7cSZWIjEw 8e8v7ZSecrfjGkzt43hc1Hpa8dttXT3GPF5U5VE jEi9DpcNVsBUKfd011qN3L WeiD2dYCzwo3KPxXmTxQuZ JIwa8IGk9B8DrLJwZWH6ttQ43GKC e - Linux: Command Line Interface

Let me show you an example of how to put out simple commands on your shell interface. A simple command echo lets you get back whatever you write beside it as plain text output. The utilization of the echo command will look like this.

InxYavKBiCocYgLu8Tb1cDJjsR9oHvI5Jtx QQGts5MRtbKlV286 7sphf6zujIYeFY2BfGmqKfcPrB5qhEUmlj89y3mo33MGb5roNAhh - Linux: Command Line Interface


In Linux, a hierarchical directory tree design is utilized to keep all your files organized. You can find out where you are in the file system by using the print-working-directory command. When this command is run on the computer, the current directory’s absolute pathname will be shown to the user.

A certain pathname indicates a certain file’s location in the system It’s more like an address that helps you realize exactly which route of the filesystem you’ll need to take to locate the file. To use the print-working-directory command simply type in pwd like below.

Syntax: # pwd
as3IIWjl6wxbQqamMlf9dlkSfkc 3AGk1PuAxaSFe8hIElv3pw6Gjfon4IS9HCnvO7pQQukE8JKfRjX4BF9cMBhfRm2wROGwHa NNDrImkoOtysEzwLvo1rOv7MEyoJ4BrQJX4kR a3wqgv8guny ZQtz6aOye7XzKHuWb28DKIHDJFhzWAU2beF - Linux: Command Line Interface

Notice that here a pathname saying root has appeared. This is the first directory in any Linux file system. 

Change Directory (cd)

Mastering the concept of path in Linux is extremely important as you’ll need paths to navigate your way around the filesystem. The command pwd will tell you the path of your current directory and another change directory command cd will let you reach the directory you want. 

There are two sorts of path descriptions that you can use: absolute pathname, and relative pathname. An absolute pathname is the path description of a directory from the home/root directory.  To illustrate an example, let’s see an absolute pathname: /home/George/pictures. 

Syntax: # cd /home
kR sldScGZ CRswMVFqsuP6HxCEHTq2V KzEGGLWF hHI5K9rYTuU08idyWNXqU1j DeeE LE4k9j3k7XdQ7Lmgx5ZsrghK1y7LPC2GeNOLxP 12jBRG3LRlp7gj tWBI4ANW2Ha i1dcXbYgWLHTFJjmhXqWTkJ3b8AD7KzEUH1 hvz6QnPIDNU - Linux: Command Line Interface

In contrast, relative pathnames are paths from one directory to another.  Suppose you would like to access a file from your current directory. It’d be really bizarre if to do that, you had to start describing the path all the way from the home directory. Relative pathnames save you from that sort of hassle.  In the previous example, if you’d like to access a file ‘Harry’ inside pictures, simply write ‘# cd Harry’.

Besides these, there are far more compact command expressing techniques associated to change directory like, ‘# cd .’, ‘# cd ..’, ‘# cd~’, ‘# cd-‘. These commands will respectively take you to the current directory, parent directory, home directory, and previous directory. 


To store your files or to further extend your nested filesystem you’ll need to make directories. With the command mkdir, you’ll be able to make new directories where you can reach using the command cd and create more files. The picture below will show how the command works.

Syntax: # mkdir filename
WnyiAtMA 6DnqKJEK22VpeRRz8drcefQSIUUJkckMI V0QxgtYbzaunpqMqx71mhkeuWkNSOs5LMfJCuGVaSZsC102ccWZRAP0U0SazEJQDTt2Tvbvg nQN8hBgeQZawyO5sbmkckvO93LU w2Wak5KjMZ W9M fwsMzwRa1cf14t2VJjh iAQw - Linux: Command Line Interface

Creating a File (touch)

Let’s learn how to create a file in the directory you desire. Reach the directory you want to create your new file in first. You can easily create a new file there using the touch command. The following example illustrates a scenario where you create a new file named ‘felina’ in your home directory. 

Syntax: # touch filename
9eYk 8pETqfXKhSl2L 7L636qxAOzLj8Xj yyCmr7dIZmwcB1d29wj0RKm4Z07 QCbVPOt cldOys0ZNZwW8aiULpJVRiTHN4 cv1xNuM85I9YA9ThsKxI3Uh1avk1cTSXWckFEpmNX2hgpSvMWGm VPctzRE4IhudqzQikYo1dC n6p5Y8Gc5F0 - Linux: Command Line Interface

List Directories (ls)

Specified pathnames will let you access different files currently stored in your filesystem. But what if you forget the name of a file! Will the file be lost forever? No worries, as the list directories command, ls, will show you a list of all the available directories. Let me show you an example.

Syntax: # ls
w023Qgn0EDVjCyUDOq76nqAJUEeyMvAL7sFjRuw7s vdKsHt3PYMm3bcGMwiSnwg5suNQjEE9c3I9vLQZ7QS EuMtl9x i4cpQYYJ8j5d0HwkPyX4Vze8r2L vIP9NkwOkzLVNjPVh83ApeghFtt6cfyBW2u yDJjJISOFIEzVoJ9ILwQ2nVV cZ - Linux: Command Line Interface

Here, we can see there are only two files present in the home directory. One of them is the file we created in the previous example. 

File Description (file)

The command ‘file’ is used to determine and show the description of a file.  Remember you’ll have to type in the whole name of the file, including extensions, for the system to acknowledge it. Here’s an example where we determine the description of a PNG file.   

Syntax: # file filename.ext
tVeVmu2o 7PTYNODKu64eYE1adTmz7kVj54zqdsgHp3lGuEjOr3pWI IKtpMI1zMZcKO4hOEBI0lsg6PPCtsfClH9WtDa6gdf AnKchA1kPX SAdKdI3dmN6OUWUqgoDCadv6tCsLjZK48JQoe0ijtnerWucHajYzG01tZFIu1ZjlriGuld1EnYF - Linux: Command Line Interface


The cat command is short for its function which is to concatenate files. It’s mainly a utility command that can perform various tasks, like printing the content of a file on the output interface, including text into a file, combining multiple files, etc. Check out an example of the command’s simplest function that simply prints out the texts of a file.   

Syntax: # cat filename.ext

Sadly, the command is not convenient for large files, so better keep that in mind.


This command does nothing that it sounds like. It’s a utility command that lets you see the writings of a text file on the screen, one page at a time. Unlike the cat command, this one doesn’t face any issues while dealing with larger files, mostly because it accesses and presents the file page by page. See the example below to better realize the command’s functionality. 

Syntax: # less filename.ext
ef8FeBhpjF9ycqP8GNQLdB9exdATTJ6AF8 0RkKUG2z8h bqeyx HfBYojlF1oB5wny6m1cXJwiLK lLsffi23qUCkdpXrP2gL 4M4nHxGFC8JJMOOBlBncdBuNeqywGGva1TIKbfEBKbDFhr6KsCeIo0bdE5I8vhHUK9DLLZX fY9tT7bZpTsSh - Linux: Command Line Interface


Using this history command, you can access the list of your previously executed commands and re-execute any of them. This saves you the hassle of retyping the same commands countless times. Just type in history to access the list and after getting the list, switch between options using the up-down arrows and press enter to execute the desired command. See the example below for a better understanding.

Syntax: # history
BE1mRllmp07QvuSklah3ISvAy3rDewHsr7uMeINWm7WTnROTSO3ojSZwqRaBr4j0TIgiJS3yiIF2Jhmsr9muoVnbExEimlMrbBt8U iPR3C 5MQk9UXXixJAgmRy9eotB mPRpiGlb6I76iUsrnbFRg8tjt qAakR SdAnsiOSZNPbj1hHb wrf - Linux: Command Line Interface


Another useful utility command is clear, which clears up the shell prompt and gives you a clean slate to type in commands. Remember that clear doesn’t erase your history, it just clears up the interface screen. You can always access the list of your previous commands by typing in history. See the after-effects of the clear command below. 

Syntax: # clear
hcW0Z hGLP292P FuRVhWw1iHngLH3H flqmiWZ8w1PgGATjKufYeSb38nJ3yo1mpN6p1HHGRcEhtUGnYWVKsBFeLuK2K 28z1qhsNSIvOGK9r2v2QtXHIQGqHbOzqgLMQMe1Wle0TsjEorfYNVR SAlmNe8 PhbqGJmJpWwSr8BMLMawTai0fT - Linux: Command Line Interface


Copying a file or files to a certain directory, using the shell interface, is a really simple process. The command cp lets you copy a certain file into a certain directory. Just type in the cp command, type the file name, and then type in the desired directory; your file will be copied.  See how to use this command in the picture below. 

Syntax: # cat filename.ext /home/dirname
qAXAD8LApJm5FJ9KJJPScWYU6s2V 2ugl R7UHI pZ6pnb7I7efdTS1rnA5UVzv 89lGc1X5pPA2t61xQoy5fc6dH 0fP6FRYgFHPPxriFqntxjjv80tKC62GbDRM TSt ecHiN7N - Linux: Command Line Interface

A very helpful, additional expression related to the cp command is ‘cp -r’, which lets you copy all the files in a directory to another directory of your choice. See the example below.

pnkORNk VaNvFyftiPJceidsgogiZdroSi CgW55swmDqO i5fKgOj0bLXoT7yo1NRJ4ivWpgXUmE7TE8hF1MnL e1citC4NZ1UfK4npVUEEh4RPffHZAA8npTvXNe3o - Linux: Command Line Interface


The mv command is a versatile utility command. You can use it to move a file or multiple files to a new directory. This command is also used for renaming a file or directory. See the examples below.

For moving one file:

Syntax: # mv filename.ext /home/dirname
HG29Nn9a6qPCnOTuMn 3Bm6j67x8DsKHXyxFbkKLAygqHDwztjR7UleXaKzobbtc1KzxhMMPg7V5Ca962pjSH2 kdYaGylgbjFLv SVimtGnJr1PBmcG0cRMKpRmKqJTV2 - Linux: Command Line Interface

For moving multiple files:

Syntax: # mv filename1.ext filename2.ext /home/dirname
I2GKnENKl9pWzT CrmQzTP 3t67qU KBZwW5xYp2mp9 WybUVEhO5NDIvMUruSlQ5JnKTPPhcKmshFAj kWBMDlT80z2u dr41W1sskPxJNV6th5pbv7fqIVwwoqj6xIobWTCmJs50vT4Gn8XVmf7 uS fYXFrZT0VIVTWhk3mSS82l2YsNcNwQr - Linux: Command Line Interface

For renaming: 

Syntax: # mv prev_filename.ext  new_filename.ext 
SZ46UfLRgEWblWU5BYc25FWIFFsPcfcuLFwJsFQrrppz3YxOKEtrX5H3qrjRndoX3pecoj26dRiL CDzvrJXHsQsoJzuIxoYI5LsFLVtJEb7t6bU4lOS3lZRQ Z8icEX4rS8SILU7h1TTNiMq2sPWNhdK WQvTd iMaHH3DQGSaYuFihHEUcI1k0 - Linux: Command Line Interface


Use the rm command to remove any file you want. Remember files once removed can’t be restored in Linux systems. So, be careful while using this command. Check the example below to see how to use it.

Syntax: # mv filename.ext 
J37gDVv9hUndbU05IsihQ1 cnFB8MGngXYu35ohUrMdrrJAuC4vNsZ3EKznR 4AoaWfUxWPSg8Fr z5t169w45yXnLCjQEDsy40b6PoZE 4QBDUIZVu4aOxYxR5TWxpLEPXatYefLjmsPQr9 - Linux: Command Line Interface


For finding a specific file in a directory, the shell has the find command. To apply the find command you will need to specify the directory where the search will take place and the name of the file you’re looking for. For further specification, the type of the file can be mentioned. Know that the search will take place not only in the mentioned directory but also in the subdirectories as well. Take a look at the following example to know how to use this command. 

Syntax: # find /home/dirname filename.ext
OSVcF2JFcciC8GdvCz61runAZPPJGqyka3tHFocUWKuNWIlvrKU9Dlqgu4a7Anon L23q6R8IJ8u5md624eO8WjZcsUKnW17mJE - Linux: Command Line Interface


The help command is a great assistance tool for Linux users, especially rookies. Applying this command, you can get adequate descriptions like utilization, syntax, structure, etc. for any command as well as information about the associated expressions available. This example below will further clarify the help command’s functionality. Here using the help command, we have obtained a description of the command pwd. 

Syntax: # help command_name
pAgiMp4E15zVSm4muu5 adZg16sWA9R9wihriYu8JEP996Vga6Y2H2IBeP xr3iT808y2Kptbm89v 01FNNEgChrriVoW7Zy4PK0FRK8QYcFFtI9 - Linux: Command Line Interface


The man command stands short for manual. With this command, you can find system built-in, user manual pages for a specified command. The manual page will contain in detail information like name, synopsis, return values, description, etc. about the inquired command. The picture below shows the manual page obtained for the command find.

Syntax: # man command_name
jAYT5lWCgSGXgDCNymCQ2 o8 6Zw7RvckFCqNks1ESPRviterjgSIX5mtFTT4umXY6OPkcOmA1VPQYujx4I8yixflLDbGuYjQOfOoEGhib5FJonTVJ9nPJ039AAhrifXYOzpPFdV0gEMXWLCFyOYVCkMZLO wl6R6sWyKJGKUUv gMjVNymyuV6p - Linux: Command Line Interface


alias command is a powerful tool to enhance user experience. With the use of this command, you can assign a short alias for a specific command, so that you can avoid repeated typing of long command names. See the example below.

Syntax: # alias your_name=’command_name’
SIFFMYl66hHkbkKtXu9gDkxIaBtJvs9hHeD0cukyefE hlXvoXGR9yF1oPqsw3a8bUAoWnrG dSkonBVxN1W1eGMFhGEvzjLkv y3HKCVDvhqpwzAgA4UdHqXiQ7IRLjlYCA3VMwE1zmRr4iOKK51aE SDqLAy HGQC35287aGSCPuvu15gG8Nua - Linux: Command Line Interface

Now, I can use the string c instead of cd, for the cd command.


The function of the logout command is to exit the shell interface. You can also use the exit command for this. Both of these have the same syntax. Check out the picture below.

Syntax: # logout
ptm9cVKNJ7FBAUBzXSakArB72lknVRsy9lulW9tw3LIPNoPsf MDNleJ0 20dUizcCjMi9rSs72HgMSUKZwipvLyBWiVIzHV5e eTYpjYcbe5pIIsxseYoju8EQxqSi419hfKTsi - Linux: Command Line Interface
Share The Tutorial With Your Friends