Basic shell commands in Linux ( For Linux Beginners )

A shell is a user interface that provides access to an operating system. It is a program that takes your commands you type from the keyboard and gives them the operating system to perform the required task. After the task is completed it displays the output.  A shell is an environment in which we can run our commands. A program called ‘bash’ acts as the shell program in most Linux systems.

The prompt, $, which is called command prompt, is issued by the shell. While the prompt is displayed, you can type a command. The shell reads your input after you press Enter. It determines the command you want executed by looking at the first word of your input. The following are some of the basic shell commands used in linux.



The date command is a simple example of shell command which displays current date and time:

$ date

Sat Aug 13 15:23:50 IST 2016



In Linux machines you can use the following command to log into your server.

# ssh root@IP_address -p port_number

The above example command will try to log into your server as root were the ‘p’ argument being the port that the SSH service listens to. If you don’t use -p then it will try to connect on the default SSH listening port 22. Now you are logged into your server via SSH.



To check in which directory you are currently residing, you can use the pwd shell command. PWD stands for ‘print working directory’.

# root@vps:~# pwd




ls command is used to list the content of a directory. This command has many options that you can combine with. Ls with no option list files and directories in bare format where we won’t be able to view details like file types, size, modified date and time, permission and links etc.

# ls

Desktop Documents Downloads  Music  Pictures  Public  Templates  Videos



If you want to go back up on one directory, you can use the following command:

# cd ..

For example if you are in /usr/local and you type “cd ..” , you will return to the directory /usr.

To navigate to the /root directory. Type:

# cd /



If you want to create a file, use the following command:

# touch file1

This command will create a file which will be empty. To populate it you can use one of the many text editors in Linux such as vim, vi, nano, emacs etc…



For creating a directory, you can use the mkdir command:

# mkdir dir1



If you want to delete the created directory, use the following command:

# rm -rf dir1

This above command will delete everything in the present dir1 directory.

You can also use the ‘rm’ command to delete the created file. For this please use the following command:

# rm -rf file1



You can use the ‘mv’ command to rename a file. If you want to rename a file named as file1 to file2 you can use the following command for that:

# mv file1 file2

‘mv’ command can also be used to move a file from one directory to another, for this purpose use the command:

# mv /root/file1 /var/www/file2



If you need to copy files and directories you can use the ‘cp’ command:

cp file1 file2

The above command will make a copy of the file in to the same directory.



Head command is used to display the first few lines of a text file. For example, the following will display the first ten lines of the file named file1 in the current directory (i.e., the directory in which the user is currently working):

# head file1



You can also use tail command to display the last few lines of a text file.

# tail file1

The above command will display the last ten lines of the file named file1 in the current directory.



If you want to display the contents of a file at the command line, the simplest way is to use the ‘cat’ command. To display the contents of a file named as file1, use the following command:

# cat file1

Cat command can also use for combining copies of text files and creating new text files.

These are the basic shell commands used in Linux.


If you need any further assistance please reach our support department.



Leave a Reply