Use of Basic Commands & utilities on Linux.

Introduction

Lets start the command line utilities based on linux platforms.

Pre-requisities

In this blog we do learn some basics commands.

1- pwd

This command is to find the current working directory pwd.

/root
The /root directory is the home directory of the root (administrative) user. If you are logged in with another user the you will see something like this:

pwd

Output

/home/nitin

 

2- ls Command utility

In this utility you can see the files and directories containing in the current working directory.

ls

It will give the result for the list of current working directories and files list.

3- touch utility

touch file{1..3}

To create 3 files in a single command use above command.

ls file1 file2 file3 file4 file5

Now run ls command to see the list of files.

Let’s learn some more arguments with ls command.

ls -l whether -l is stand for the long. It gives the result of long list and provide the information of user and group of the files and directories.

Its also provide the information of created data of the files and directories and its size as well.

ls -l

-rw-r--r-- 1 root root 0 Feb 28 19:45 file1

-rw-r--r-- 1 root root 0 Feb 28 19:45 file2

-rw-r--r-- 1 root root 0 Feb 28 19:45 file3

-rw-r--r-- 1 root root 0 Feb 28 19:45 file4

-rw-r--r-- 1 root root 0 Feb 28 19:45 file5

 

ls -a

. .aptitude .bashrc file2 file4 .profile .ssh .. .bash_history file1 file3 file5 .rnd .viminfo

 

This command is used to show all files with hidden files.

We can pass multiple flags as well by simply stringing them together:

ls -l -a

drwx------ 4 root root 4096 Feb 28 19:45 .

drwxr-xr-x 23 root root 4096 May 3 2013 ..

drwx------ 2 root root 4096 Feb 28 17:19 .aptitude

-rw------- 1 root root 2036 Feb 28 18:20 .bash_history

-rw-r--r-- 1 root root 570 Jan 31 2010 .bashrc

-rw-r--r-- 1 root root 0 Feb 28 19:45 file 1

 

This commands gives us combine result of long list and the hidden files.

ls -la

This will function exactly the same and takes less typing.

Another interesting option is -R flag which lists files recursively. The only directories which are having within our home directory and which are hidden.

we’ll have to pass the -a option:

ls -Ra 

. .aptitude .bashrc file2 file4 .profile .ssh .. .bash_history file1 file3 file5 .rnd .viminfo ./.aptitude: . .. cache config ./.ssh: . .. authorized_keys

Now we know how ls command work, let’s change the “object” that ls operates on.

How ls utility use the particular directory

Now list files & directories with ls command in root directory or current working directory.

 

1

 

Any directory path that begins with a slash (/) is known as an “absolute” path example (/home/nitin/).

 

1

 

We don’t have any non-hidden directories in our current folder, so let’s make it quickly to demonstrate.

mkdir dir{1..3} touch dir{1 2 3}/test{a,b}

This will create some directories with some files inside. We can see the directories with a normal ls command:

ls

dir1 dir2 dir3 file1 file2 file3 file4 file5

In order to see what is inside of the “dir1” directory, we could give the absolute path as shown above

pwd

/root

And then add the directory.

ls /root/dir1 testA testB testC

We can refer directories under our current directory by just naming the directory.

ls dir1 testA testB testC

If we don’t begin a path specification with a slash, the operating system looks for the directory path starting at the current directory.

We can refer the directory that contains our current directory using a special syntax. The directory containing our current directory is called its “parent” directory. We can refere the parent directory using two dots (..).

Let’s move back up a level:

cd .. pwd /

Now we’re back in the root directory. We can also refer our current directory with a single dot:

ls .

bin etc lib media proc sbin sys var boot home lib64 mnt root selinux tmp vmlinuz dev initrd.img lost+found opt run srv usr

This is useful in a number of situations.

We said “~” symbol is our home directory. Let’s use that as the start of another directory path to change to our “dir1” inside our home:

cd ~/dir1 pwd /root/dir1

Now moved into a directory within  home directory very easily using the “~” symbol to replace the first part of path.

But what if we forgot to do something before changing directories and want to go back to our most recent directory? We can return to our previous directory by typing:

cd - pwd /

We are back in our last directory.

Let’s finish up by moving back to our home directory. We could do this by using the tilde as the path to switch.

cd pwd /root

Now back to the home directory again.

This blog is to understand the basic commands using in linux like :- ls, cd, mkdir etc

Hope this will help for those who are new in linux.

 

Leave a Reply

Your email address will not be published.