In Unix like operating system the files are organized in a hierarchical directory structure which is similar to a tree like structure. The first directory in this directory structure is called the root directory and it contains all the other files and subdirectories.
The root directory is reprented by /
At any point of time, we are inside some directory and it becomes the current working directory for us. The current working directory will contain some files and path to its parent directory which lies above it and may contain some subdirectories which lies below it in the hierarchical directory structure.
In order to know the current working directory we use the pwd (print working directory) command.
[yusuf@linux ~]$ pwd
In order to list the content of a directory we use the ls command.
[yusuf@linux ~]$ ls
If we want to list the content of a specific directory, say content of the etc directory which is inside the root directory we write the following.
[yusuf@linux ~]$ ls /etc
If we want to list the content of a multiple directories, say content of the etc and usr directory which is inside the root directory we write the following.
[yusuf@linux ~]$ ls /etc /usr
---- content of /etc directory ---
---- content of /usr directory ---
If we want to list the content of a directory in long format we type the following command.
[yusufshakeel@linux GitHub]$ ls -l
drwxr-xr-x 13 yusufshakeel staff 442 May 15 2015 C-Project
drwxr-xr-x 7 yusufshakeel staff 238 Mar 24 2015 Php-Project
drwxr-xr-x 12 yusufshakeel staff 408 Sep 4 18:14 UglifyJS2
drwxr-xr-x 18 yusufshakeel staff 612 Mar 24 2015 Web-App
drwxr-xr-x 21 yusufshakeel staff 714 Aug 15 2015 bootstrap-datetimepicker
drwxr-xr-x 9 yusufshakeel staff 306 Aug 23 21:22 chartjs
drwxr-xr-x 8 yusufshakeel staff 272 Jul 24 2015 database-tutorial
drwxr-xr-x 14 yusufshakeel staff 476 Aug 14 2015 datetimepicker
drwxr-xr-x 13 yusufshakeel staff 442 Jun 29 2015 fonts
drwxr-xr-x 8 yusufshakeel staff 272 Jun 13 2015 gcm
drwxr-xr-x 9 yusufshakeel staff 306 Jan 9 14:16 google-services
drwxr-xr-x 21 yusufshakeel staff 714 Nov 24 18:22 jQuery-File-Upload
drwxr-xr-x 23 yusufshakeel staff 782 Oct 3 15:56 jquery_jeditable
drwxr-xr-x 31 yusufshakeel staff 1054 Aug 14 2015 moment
drwxr-xr-x 38 yusufshakeel staff 1292 May 29 2015 phpredis
drwxr-xr-x 14 yusufshakeel staff 476 Sep 6 10:29 yusufshakeel.github.io
drwxr-xr-x 43 yusufshakeel staff 1462 May 30 2015 zguide
Commands are often followed by some option which alters the behaviour of the command, and further, by some arguments upon which the command takes some action.
Following is a general format of a command.
[yusuf@linux ~]$ command -options arguments
We saw the ls option -l which listed the content of a directory in long format.
To change from one directory to the another we use the cd command.
[yusuf@linux ~]$ cd /etc
It will change the current working directory to etc directory inside the root directory.
We can use absolute and relative pathname to change directory. An absolute pathname for a file or directory will start from the root directory /. So if we want to change our current working directory from /home/yusufshakeel to etc directory inside the root directory, we will use the following absolute path.
A relative pathname starts from the current working directory. So if we consider the following directory structure.
| +-- sample.txt
If our current working directory is yusuf then if we want to change the directory to doc, we will type in the following command.
[yusuf@linux ~]$ cd doc
Similarly, if we want to change the directory from yusuf to v1 which is inside the sheet directory, we will type the following relative pathname
[yusuf@linux ~]$ cd sheet/v1
To move to the parent directory of the current working directory, we use the following command.
[yusuf@linux ~]$ cd ..
The file command is used to get a brief description of file.
[yusuf@linux ~]$ file test.php
test.php: PHP script text
Have fun learning :-)
Copyright © 2014 - 2019 DYclassroom. All rights reserved.
rendered in 0.0157 sec