logo
  • Home
  • About
  • Training
  • Programming
  • CS
  • IT
  • IS
  • ECE
  • EEE
  • EE
  • Civil
  • Mechanical
  • Chemical
  • Metallurgy
  • Instrumentation
  • Aeronautical
  • Aerospace
  • Biotechnology
  • Agriculture
  • MCA
  • BCA
  • Internship
  • Contact

Questions & Answers

C Interview Questions
C++ Questions
Linux MCQs
C# Quiz
Java MCQs
JavaScript MCQs
SAN Questions
PHP Questions
Python Quiz

Computer Science Questions

Operating System Quiz
Computer Architecture MCQs
Software Architecture MCQs
Software Engineering MCQs
Artificial Intelligence MCQs
LISP Programming MCQs
Database Management MCQs
Computer Network MCQs
Microprocessor MCQs

C Programming Examples

Simple C Programs
C - Arrays
C - Matrix
C - Strings
C - Bitwise Operations
C - Linked Lists
C - Stacks & Queues
C - Searching & Sorting
C - Trees
C - Strings
C - File Handling
C - Mathematical Functions
C - Puzzles & Games
C Programs - Recursion
C Programs - No Recursion

Java Algorithms

Java - Numerical Problems
Java - Combinatorial Problems
Java - Graph Problems
Java - Hard Graph Problems
Java - Computation Geometry
Java - Sets & Strings
Java - Data-Structures
Java - Collection API Problems

C++ Algorithms

C++ - Numerical Problems
C++ - Combinatorial Problems
C++ - Graph Problems
C++ - Hard Graph Problems
C++ - Computation Geometry
C++ - Sets & Strings
C++ - Data-Structures
C++ - STL Library

C Algorithms

C - Numerical Problems
C - Combinatorial Problems
C - Graph Problems
C - Hard Graph Problems
C - Computation Geometry
C - Sets & Strings
C - Data-Structures

« Prev Page
Next Page »

5+ Practical “pwd” Command Usage Examples in Linux

Posted on July 28, 2013 by Manish

This tutorial explains Linux “pwd” command, options and its usage with examples.

“pwd” command is used T. This post describes “pwd” command used in Linux along with usage examples and/or output.

Description:

In Unix-like and some other operating systems, the pwd command (print working directory) is used to output the path of the current working directory.

The command is a shell builtin in certain Unix shells such as sh, and bash. It can be implemented easily with the POSIX C functions getcwd() and/or getwd().

Users who are familiar with MS-DOS or the Windows command prompt may type cd alone to print the working directory. However, typing cd alone in Linux and Unix will return you to the home directory.

Synopsis:

pwd [OPTION]…

OPTIONS:

-L
Logical Links

-P
Physical Links

Examples:

1. To print name of current/working directory(pwd):

sanfoundry-> pwd
/home/himanshu
sanfoundry-> cd SAN/
sanfoundry-> pwd
/home/himanshu/SAN
sanfoundry-> /bin/pwd
/home/himanshu/SAN

2. To show the full path when symlinks are there(pwd OR pwd -L):

sanfoundry-> ln -s folder/ linked_folder
sanfoundry-> ls -l linked_folder
lrwxrwxrwx 1 himanshu himanshu 7 Jul 28 17:15 linked_folder -> folder/
sanfoundry-> cd linked_folder
sanfoundry-> pwd 
/home/himanshu/SAN/linked_folder
sanfoundry-> pwd -L
/home/himanshu/SAN/linked_folder

Here “-L” stands for “–logical” and we can see that whole path upto the linked folder is shown with “-L” option.
But if you want to see the path to the original folder for the linked folder use “-P” option.

3. To see the original folder of the linked folder(pwd -P):

sanfoundry-> ln -s folder/ linked_folder
sanfoundry-> ls -l linked_folder
lrwxrwxrwx 1 himanshu himanshu 7 Jul 28 17:15 linked_folder -> folder/
sanfoundry-> cd linked_folder
sanfoundry-> pwd 
/home/himanshu/SAN/linked_folder
sanfoundry-> pwd -P
/home/himanshu/SAN/folder

Here “-P” stands for “–physical” ans we can see that the path upto the folder directory is shown instead to the path of the linked directory linked_folder.

Note:Shell pwd vs /bin/pwd:
To use the binary version, type full path /bin/pwd:

sanfoundry-> /bin/pwd 
/home/himanshu/SAN

By typing pwd, you end up using the shell builtin provided by bash or ksh:

pwd

4. To see all locations containing an executable named pwd:

sanfoundry-> type -a pwd
pwd is a shell builtin
pwd is /bin/pwd

The /bin/pwd version of pwd command has a two more additional options.

5. To see the version of pwd command:

sanfoundry-> /bin/pwd  --version 
pwd (GNU coreutils) 8.13
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later .
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
 
Written by Jim Meyering.

6. To get the help:

sanfoundry-> /bin/pwd --help 
Usage: /bin/pwd [OPTION]...
Print the full filename of the current working directory.
 
  -L, --logical   use PWD from environment, even if it contains symlinks
  -P, --physical  avoid all symlinks
      --help     display this help and exit
      --version  output version information and exit
 
NOTE: your shell may have its own version of pwd, which usually supersedes the version described here.  Please refer to your shells documentation for details about the options it supports.
 
Report pwd bugs to bug-coreutils@gnu.org
GNU coreutils home page: 
General help using GNU software: 
For complete documentation, run: info coreutils pwd invocation'

Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.

If you wish to look at all Linux commands and their usage examples, go to Linux Commands Tutorial.
« Prev Page - 20 Practical “ls” Command Usage Examples in Linux
» Next Page - “arp” Command Usage Examples in Linux
« Java Program to Implement Find all Forward Edges in a Graph
C++ Program to Traverse a Graph using BFS »

Deep Dive @ Sanfoundry:

  1. C Programming Examples on Graph Problems & Algorithms
  2. C Programming Examples
  3. C# Programming Examples on LINQ
  4. C Programming Examples on Puzzles & Games
  5. C Programming Examples on Hard Graph Problems & Algorithms
  6. C# Programming Examples
  7. C Programming Examples on File Handling
  8. Linux Questions and Answers
  9. C# Programming Examples on Files
  10. Linux Command Tutorials with Examples and Explanations
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage & Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him below:
LinkedIn | Facebook | Twitter | Google+

Best Careers

Developer Tracks
SAN Developer
Linux Kernel Developer
Linux Driver Developer
Linux Network Developer

Live Training Photos
Mentoring
Software Productivity
GDB Assignment
Sanfoundry is No. 1 choice for Deep Hands-ON Trainings in SAN, Linux & C, Kernel Programming. Our Founder has trained employees of almost all Top Companies in India such as VMware, Citrix, Oracle, Motorola, Ericsson, Aricent, HP, Intuit, Microsoft, Cisco, SAP Labs, Siemens, Symantec, Redhat, Chelsio, Cavium, ST-Micro, Samsung, LG-Soft, Wipro, TCS, HCL, IBM, Accenture, HSBC, Mphasis, Tata-Elxsi, Tata VSNL, Mindtree, Cognizant and Startups.

Best Trainings

SAN I - Technology
SAN II - Admin
Linux Fundamentals
Advanced C Training
Linux-C Debugging
System Programming
Network Programming
Linux Threads
Kernel Programming
Kernel Debugging
Linux Device Drivers

Best Reference Books

Computer Science Books
Algorithm & Programming Books
Electronics Engineering Books
Electrical Engineering Books
Chemical Engineering Books
Civil Engineering Books
Mechanical Engineering Books
Industrial Engineering Books
Instrumentation Engg Books
Metallurgical Engineering Books
All Stream Best Books

Questions and Answers

1000 C Questions & Answers
1000 C++ Questions & Answers
1000 C# Questions & Answers
1000 Java Questions & Answers
1000 Linux Questions & Answers
1000 Python Questions
1000 PHP Questions & Answers
1000 Hadoop Questions
Cloud Computing Questions
Computer Science Questions
All Stream Questions & Answers

India Internships

Computer Science Internships
Instrumentation Internships
Electronics Internships
Electrical Internships
Mechanical Internships
Industrial Internships
Systems Internships
Chemical Internships
Civil Internships
IT Internships
All Stream Internships

About Sanfoundry

About Us
Copyright
TOS & Privacy
Jobs
Bangalore Training
Online Training
SAN Training
Developers Track
Mentoring Sessions
Contact Us
Sitemap
© 2011 Sanfoundry