.gobump img{ border: 5px solid #ccc; float: left; margin: 15px; -webkit-transition: margin 0.5s ease-out; -moz-transition: margin 0.5s ease-out; -o-transition: margin 0.5s ease-out; border-radius: 5px 5px 5px 5px; } .gobump img:hover { margin-top: 2px; }

twitter

Thursday, June 25, 2009

DIRECTORY COMMANDS IN LINUX

Identifying the Current Directory Path


The pwd (print working directory) command is used to display the full path name of the current directory.


Example
[ Steve@localhost Steve] $ pwd
/home/Steve
[ Steve@localhostb Steve] $ _

Here, /home/Steve is the directory in which the user is currently working.


Changing the Current Directory

The cd (change directory) command changes the current directory to the directory specified.

Assume that Steve has logged in and has given the following command:

Example
[Steve@localhost Steve ] $ pwd
/home/Steve
[ Steve@localhost Steve] $ cd /usr/bin
[ Steve@localhost Steve] $ pwd
/usr/bin
[ Steve@localhost Steve] $ _

Note that the complete path name has been specified with the cd command. Linux also allows the use of relative path names with commands. Let' s look at an example.

Example

[ Steve@localhost /usr ] $ pwd
/usr
[ Steve@localhost /usr ] $ cd bin
[ Steve@localhost bin] $ pwd
/usr/bin
[ Steve@localhost bin ] $ _

In the above example, the user, Steve, changed the working directory from /usr to the directory, /usr/bin. However, he did not mention the full path of the bin directory. Since bin is a sub-directory in the current working directory, Steve just specified the directory name and Linux interpreted that the directory is under the current directory.

You can also use the .. (double dot) option with the cd command to move to the parent directory of your current directory. For example, Steve can enter the following command after logging in, to change to the parent directory of his HOME directory.

Example

[ Steve@localhost Steve ] $ pwd
/home/Steve
[ Steve@localhost Steve ] $ cd . .
[ Steve@localhost /home ] $ pwd
/home
[ Steve@localhost /home ] $ cd . .
[ Steve@localhost / ] $ pwd
/
[ Steve@localhost / ] $ _

The two dots refere to the parent directory of the current directory. Note that there has to be a space between cd and two dots, but not between the dots.

The cd command without any path name always takes a user back to the HOME directory.

Example

[ Steve@localhost bin ] $ pwd
/usr/bin
[ Steve@localhost bin ] $ cd
[ Steve@localhost Steve ] $ pwd
/home/Steve
[ Steve@localhost Steve] $ _

Recollect that the tilde ( - ) sign is used to denote the full path for your HOME directory. Let' s say there are two directories, baseball and basketball, under Steve' s HOME directory.

Example
[ Steve@localhost vga ] $ pwd
/etc/vga
[ Steve@localhost vga ] $ cd -/baseball
[ Steve@localhost baseball ] $ pwd
/home/Steve/baseball
[ Steve@localhost baseball ] $ cd -
[ Steve@localhost Steve ] $ pwd
/home/Steve
[ Steve@localhost Steve ] $ _

You can use a combination of all the above options in your cd command. Let us look at an example, if Steve wants to move from the directory data1 to data2, he would issue the following cd command.

Example
[ Steve@localhost data1 ] $ pwd
/home/steve/data1
[ Steve@localhost data1 ] $ cd . . /data2
[ Steve@localhost data2 ] $ pwd
/home/steve/data2
[ Steve@localhost data2 ] $ _




Twitter Delicious Facebook Digg Stumbleupon Favorites More

 

Categories