Linux Basic Commands

Ashutosh Verma
6 min readMay 31, 2020
Source:wallpaperset.com

Since my childhood I am only aware of Windows and using it, but few years back I was attracted towards the beauty of linux and decided to learn about it. Now I have been using linux from last 2 years and decided to write blog on basic commands of linux so that people who are newcomer and interested in learning linux can get started. I would try to use the concept of KISS(Keep It Super Simple) to avoid the complexity in my explanations but still if you find any difficulty in any of the command explained in this article then feel free to contact me on my social media accounts.

In this article I will be covering some basic commands given below:
1. ls — Listing of files and directories
2. pwd — Present working directory
3. cd — Change directory
4. mkdir — Make directory
5. touch — Create new files or change last modification time of a file
6. cat — Display file content
7. less/more — Display a large file page by page
8. cp — Copy file from one path to another
9. mv — Move file from one path to another, also use to rename a file
10. file — Shows information of a file
11. history — History of commands executed by a user

1. ls

This command is used to get a list of all the files along with their information present in a directory.
Usage: ls [OPTION]… [FILE]…
You can check about all the options available for this command using help menu. To check manual page you can use man ls and for help menu ls — help(sometimes -h is used instead of — help in some commands). You can also check man pages and help menu for other commands just by replacing the ls with the command you are searching for(e.g — man cat or cat — help).
Some of the most useful options are given below:
1.1. ls -l : This will give the list of files along with some detailed information.

Here,
first column tells you about the permissions for owner,group users and other users.
second column will tell you about the links(symlinks and hardlinks).
third column will tell you about owner of the file/directory.
fourth column will tell you about the group of the owner.
fifth column is for file size.
next three columns will tell you about last modifications performed.

1.2. ls -a : This option will show all the files including dot files

Single dot represents current directory(here it is ~/Public) and double dot represents one level up directory(here it is / directory)/

1.3. ls -lh : These both options can be used together to get file size in human readable form

As you can see in the screenshot given above, the file size is in KB

2. pwd
This command stands for “Present Working Directory”, this command tells you about the current path you are in.

3. cd

You can use this command to traverse in different directories or change current working directory.

In the above screenshot, first I was in /home/blast directory then using cd command I changed my current working directory to /opt

4. mkdir

This command is used to create a directory
Usage: mkdir [OPTION]… DIRECTORY…
Most of the time you will use this command without any option that means mkdir <dir_name>

As you can see a NewDirectory has been created in this

5. touch

This command can be used to create a file or it can also be used to change the time of modification of the file/directory
Usage: touch [OPTION]… FILE…

When first command was executed then there was no file having name run.txt, therefore a new file has been created but when again same command was executed then file exists already that’s why modification in time was done(marked with red in above image).

6. cat

cat command can be used for many purposes but most of the time it is used to display the content of a file to standard output. It can also be used to concatenate multiple file’s content and the final text is given to the standard output
Usage: cat [OPTION]… [FILE]…

First and second command displays the content of the files. Third command concatenates the content of both the files and displays it.

7. less/more

Suppose you want to read a file which has lot of text in it and you want to read it page by page then this command can be helpful
Usage: more <file>…
If you use cat command to display the text then it will show you only last lines of the file. When using more command then you can read the text page by page as you can see in the screenshot given below. The left bottom is showing that only 5% file is being displayed and you can go further to read more.

8. cp

cp command is used to move a file/directory from one path to another path

Usage: cp [OPTION]… [-T] SOURCE DEST
or: cp [OPTION]… SOURCE… DIRECTORY
or: cp [OPTION]… -t DIRECTORY SOURCE…


Let’s copy a file to /tmp

9. mv

You can move a file/directory using mv command from one path to another

Usage: mv [OPTION]… [-T] SOURCE DEST
or: mv [OPTION]… SOURCE… DIRECTORY
or: mv [OPTION]… -t DIRECTORY SOURCE…

Let’s move a file to /tmp

10. file

This command tells you about type of a file

11. history

history command is used get a list of all the previous commands which was run by you on your terminal. You can always use up and down arrow keys to move between commands run previously but suppose you want to run a command which is very far in the history list, then you can note it’s unique number using history list and run it again with ease. Let’s see how it can be done.

Simply type history in your terminal and press enter key. This will give you a long list of commands run previously, now suppose you want to run command number 2032 again and you don’t want to press aero key until this command comes, instead of this you can simply type !2032 in your terminal and press enter. The command executed will be given as an output.

Thank you readers for reading this article hope you liked it and got something to learn from this. A little appreciation of yours would encourage me to write more.

Feel free to contact me on social media platforms given below.

Twitter (@atinfosec)

--

--

Ashutosh Verma

An avid learner in the field of information security. A self learner and a ctf player sometimes.