≡ Menu

pwd command

Linux / Unix Shell Script: Get The Current Directory

I am working on a shell script. I need to find out the current working directory. How do I get the current working directory under Bash or Ksh shell running on Linux or Unix like operating systems?
[click to continue…]

Sysadmin because even developers need heroes!!!

HowTo: Use pwd Command In Linux / UNIX

How do I use the pwd command in Linux or Unix like operating systems? How can I use pwd command in UNIX or Linux shell scripts for automation purpose?
[click to continue…]

Unix / Linux Shell: Get Third Field Separated by Forward Slash (/) Delimiter

I‘m writing a shell script for automation purpose. The output the path of the current working directory is stored in $PWD or it can be obtained using the pwd command. How do I find out find out 3rd field separated by the forward slash (/) delimiter using $PWD under Unix like operating systems?
[click to continue…]

Delete All Files And Folders In Linux

How do I delete all files and folders stored in /home/jerry/movies directories under Linux operating systems?
[click to continue…]

Find Out Linux Kernel Modules ( Drivers ) Location / Directory

Can you tell me an exact location of Linux kernel driver under Linux file system? Where to find all available modules under Linux operating systems?
[click to continue…]

Understanding Linux / UNIX Relative Pathname

Q. Can you explain the term relative pathname under UNIX or Linux oses?

A. The relative pathnames are opposite to absolute pathname. A reative pathname does not begin with a slash ( / ). Generally you specifies location relative to your current working directory. This is most useful to short a path name. For example if your current working directory is /home/tom and if you would like to change directory to /home/tom/docs/bio you can enter command cd docs/bio instead of cd /home/tom/docs/bio .

So you can use a relative path name as a shortcut to the location of files and directories.

Relative pathname example

To refer to a file in a subdirectory of the current working directory, use the name of the subdirectory followed by a slash (/) and the name of the file. For example, to display a file called foo.text in a subdirectory called bar that is located in the current directory /home/tom, enter:
$ pwd
Output:

/home/tom

Now, enter the command:
$ cat bar/foo.txt

.. directory name

To refer to a file in the parent directory of the current directory, use “../” followed by the name of the file. For example,if you are in /home/tom/bar and would like to display /home/tom/file.txt use pathnane ../file.txt:
$ pwd
Output:

/home/tom/bar

Now, enter the command:
$ cat ../file.txt

Home-relative pathname with tilde (~)

The tilde character (~) can be used to refer to your home directory, For example, the pathname ~/file.txt refers to a file named file.txt in your home directory /home/tom/file.txt.
$ pwd
Output:

/tmp

Now, enter the command:
$ cat ~/file.txt

UNIX / Linux: Absolute Pathnames

Q. Can you explain the term absolute pathname under UNIX or Linux oses?

A. An absolute pathname, is the location of a filesystem object relative to the root directory. All absolute pathnames always begin with a slash (/). With Absolute pathname you have access to complete file system objects such as directories and files.

Absolute Pathnames

You can use absolute pathnames to specify full file path such as /etc/passwd. It is believed that UNIX pathname looks and feels like Internet addresses, thus result into compatibility. The absolute pathname of the current directory can be found by using the pwd command:
pwd

Absolute Pathnames Examples

Try following commands:
pwd
ls /etc
ls /usr/share/games
cd /usr/share/games
pwd
cd ~
pwd
cat /etc/passwd
cp /etc/passwd /tmp
cd /tmp
pwd
cat passwd

Linux / UNIX: Print Current Working Directory with pwd command

Q. How do I display the absolute path to the current working directory under Linux or UNIX operating system?

A. The pwd command displays the absolute pathname of the current working directory to the computer screen.

Print name of current/working directory

Type pwd command:
pwd
Output:
/home/vivek

Above command print the full filename of the current working directory i.e /home/vivek.

Display actual directory location

Use -P option to display the physical current working directory (all symbolic links resolved). For example, /home/lighttpd is /var/www/root/lighttpd:
cd /home/lighttpd
pwd

Output:

/home/lighttpd

Now run with -P option
pwd -P
Output:

/var/www/root/lighttpd