- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- HPUX command to return full pathname of a file
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 10:55 AM
тАО11-01-2002 10:55 AM
Here's an example of what realpath does:
$ cd /long/directory/name
$ touch testfile
$ realpath testfile
/long/directory/name/testfile
I've been through the man pages ("man -k pathname") and searched the forums a couple of different ways, but couldn't find an obvious answer. Any suggestions on where to look?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 10:54 AM
тАО11-01-2002 10:54 AM
Re: HPUX command to return full pathname of a file
'dirname' is what you are seeking. Its counterpart is 'basename'.
The same thing can be achieved with shell builtin parameter substitution (faster) too.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 10:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 11:06 AM
тАО11-01-2002 11:06 AM
Re: HPUX command to return full pathname of a file
For portability, you could write a shell script but filenames that include . .. and soft links wouldn't be easy to handle.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 11:10 AM
тАО11-01-2002 11:10 AM
Re: HPUX command to return full pathname of a file
>'dirname' is what you are seeking. Its counterpart is 'basename'.
Unfortunately, this doesn't quite do what I want. Since the file is in the current working directory, all it returns is ".".
> The same thing can be achieved with shell builtin parameter substitution (faster) too.
I don't quite follow you here. Could you give an example?
From John Poff:
> Have you tried 'whence'? I think whence just looks in the directories specified in your $PATH variable.
I thought this as well, but whence will search for nonexecutable files that are not in the PATH.
This does just what I need, thanks!
Too bad the whence command doesn't exist in linux. Oh, well, that's why we have if statements...
-- Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 11:28 AM
тАО11-01-2002 11:28 AM
Re: HPUX command to return full pathname of a file
Yes, I read your post's title and made the assumption I did. Sorry. Here's what I meant:
#!/usr/bin/sh
F=/var/adm/syslog/syslog.log
echo `dirname $F`
echo ${F%/*}
echo `basename $F`
echo ${F##*/}
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 11:32 AM
тАО11-01-2002 11:32 AM
Re: HPUX command to return full pathname of a file
try making a file called "realpath.sc" with this content:
function realpath
{
if [ $# = 1 ]
then
( cd $(dirname $1); echo "$PWD/$(basename $1)"; )
else
echo "Usage: realpath
fi
}
source it, e.g.:
# . ./realpath.sc
Then try:
# realpath
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 11:33 AM
тАО11-01-2002 11:33 AM
Re: HPUX command to return full pathname of a file
echo `pwd -H`/testfile
Since "cd" follows logical links, "pwd -H" will display the current path of the REAL directories.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 11:36 AM
тАО11-01-2002 11:36 AM
Re: HPUX command to return full pathname of a file
John K: That looks like an excellent suggestion. I may have to try that. ;-)
-- Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 11:39 AM
тАО11-01-2002 11:39 AM
Re: HPUX command to return full pathname of a file
If you are not concerned with symlinks then as indicated, it's relatively simple.
Regards,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-01-2002 11:44 AM
тАО11-01-2002 11:44 AM
Re: HPUX command to return full pathname of a file
That's a good suggestion, but it would break if the user put in an absolute filename. I.e. /path/to/file would be reinterpreted as (potentially) /path/to/path/to/file.
-- Steve