[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Actual Directory Location

Ok, here is a fairly easy question question that may have different answers depending on the expert.

A directory is actually a link, for example /var/test links to /opt/somedirectory/another/another/test

In unix, in this case Solaris, a user cds to the link using "cd /var/test"
While in that directory the user does a "pwd" and the output shows /var/test  

What simple command would you tell the user to use to find their actual location in the file system?
0
arthurjb
Asked:
arthurjb
  • 2
  • 2
  • 2
  • +2
5 Solutions
 
ahoffmannCommented:
df .
0
 
arthurjbAuthor Commented:
df .
is an easy command, but (at least in my version) only shows the mount point of the top of the current file system.

for example, in this case if the filesystem was mounted at /opt/somedirectory a df . while in /opt/somedirectory/another/another/test    only shows    /opt/somedirectory

Good try.
0
 
ravenplCommented:
/bin/pwd works for me ;) (instead shell internal command pwd)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
swethCommented:
As ravenpl says, the stock /bin/pwd on most Unices will return the current directory after dereferencing symlinks.  If for some reason you can't access that, you can figure it out fairly easily by doing an "ls -ld $PWD"; if you need to have something that actually returns just the string representing the dereferenced path, then you'd probably have to parse the output of that using awk or perl.  Also, it's worth noting that most shells do have options to tell the shell to "chase" the link when cd-ing into a symlink, so that a pwd will return the dereferenced path; in ksh/bash, it's -P (option PHYSICAL), and zsh uses "-w" (option CHASE_LINKS).
0
 
ahoffmannCommented:
which path would you like to see?
a) just the physical partition
b) the physical partition/mount point including full path on that partition/mount point
c) the complete path reach by using some a ptah which contains symlinks

according your question:
> What simple command would you tell the user to use to find their actual location in the file system?
the answers are:
a) df .
b) pwd # or /bin/pwd
c) echo $cwd; echo $PWD   # depends on your shell
anything else need a bit shell programming
0
 
biraCommented:
ls -l $PWD
0
 
arthurjbAuthor Commented:

Good answers from all, but ravenpl hit the easy answer, and got it first.


the ls -l $PWD does not work, at least on Solaris 10  all it does is list the files in the current directory, it does not list the name of the current directory.

0
 
ravenplCommented:
usually You need: ls -ld $PWD # or: ls -ld `pwd`
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now