Using the linux command line is one of the most useful skill you can develop. If you have a good hand on the command line then you can operate the whole system or number of systems for that matter by just typing commands in a black window. This is a short tutorial series that will quickly get you through the linux commands that are most frequently used when using the command line/shell.

If you don’t know what a command line is, what this video to get a better understanding.

The best way to learn and get comfortable with the commands is to dig into them right away. Open the terminal and type each command yourself and analyse the output it produces. Lets start!

Date

The date command prints out the current date.

Output

Cal

The cal command displays calendar of the current month.

Output

 

Suppose you want to see all the months of the year 1995 then you will type

Output

 

Now if you want to see the calendar for the month of August 1995 you will type

Output

 

Clear

As you will keep typing commands the command line gets messy with commands and their respective outputs all over the screen. To hide this clutter at any point of time just type in the clear command.

 

Navigating the Linux File System

The commands that you are going to see now are by far the most frequently used. If you are familiar with the linux file system then these command will come very easy to you, if not then I urge you to watch this video first.

By default when you open the command line you will be in your home directory.

PWD (Print Working Directory)

While working with the command line this may happen a lot to you that you might loose track of which directory you are currently working in, don’t worry, pwd command to the rescue. When you type the in the pwd command it will print the complete path of the directory that you are working in.

Output

(The output will be different for you depending on the directory you are in)

Representing the current and the parent directory

Linux has its own way to represent the current directory you are in and its parent. The current directory you are in is represented by a dot(.) and its parent its represented by two dots(..), so if you are in a directory named /Users/john/desktop/folder then at that moment the folder is represented by a dot(.) and the desktop is represented by two dots(..).

LS

Suppose you are inside a directory and you want the see the list of all files in that directory, all you have to type is the ls command. It will print out the names of all the files and directories contained inside that directory.

Output

The ls command has many options that can give you much more useful information than just the name of the file. Lets explore some of these options

ls – a

When you type -a after the ls command it will print all the folders and directories including the hidden ones!

Output

Notice the first two names are dot(.) and two dots(..). As we discussed earlier the single dot represents the current directory itself and the two dots(..) represents its parent.

ls -l

The option -l gives you much more information like the permissions of the file, whether it is a directory or a file, its size, created date, /modified etc.

Output

ls -t

-t will print the files and directories in a sorted order according to the most recently created/modified date.

ls -r

-r will print all the files and directories in the reverse order.

ls -R

-R notice the capital R in this case, options that you provide are case sensitive. What -R does it prints all the files recursively. Suppose you are inside a folder that contains two files named File1 and File2, and two folders, Folder1 and Folder2. The Folder1 further contains two more files File3 and File4. If you run the ls -R command then the output will contain not only File1, File2, Folder1 and Folder2 but also File3 and File4, what it basically does is it goes inside every folder and prints its content.

Combining ‘ls’ with multiple options

Previously you saw many options that go along with the ls command, you can combine more than one options at the same time!

So suppose you want to print all the files and directories sorted according to modified/created date but in a reverse order then you will type

You can also write

it will produce the same result.

CD (Change directory)

As the name suggests cd command is used the change the current working directory. So suppose you are currently in your home directory and you want to go to your desktop then you will type.

You can type pwd to confirm your current directory.

Suppose you are in Folder1 that contains a directory named Folder2 which further contains directory Folder3. So the structure looks something like this.

 

Now you want to navigate to Folder3, you can do that in following ways

or

cd /

cd / will take you to the root directory, you can type this command anytime and anywhere, it doesn’t depend what is your current working directory.

cd ~

cd ~ will take you to your home directory, you can type this command anytime and anywhere, it doesn’t depend what is your current working directory.

cd –

cd – will take you to your previous working directory, so suppose you were in a directory /Users/john/Desktop/Work/Folder1 and by mistake you typed cd / and now you are in the root directory! To go back you would have to type so long path or navigate between so many folders, its tedious! Well there is a solution and its cd – by typing this command you will back into your previous working directory.


Well that is it for this tutorial on basic Linux Commands, you might have felt that some of them were easy while others went right above your head. The only way to get hold on to these commands is by actually trying them out and practicing!

 

Next Tutorial : Getting Familiar with Linux Commands – Tutorial 1 – File Specific Commands

About The Author

Android Developer and enthusiast, believes in developing products and content to help people. Likes to do deep thinking.

Related Posts

Leave a Reply

Your email address will not be published.

3 × one =