This should be simple, but it's not, unless I'm forgetting something.
Writing a script, an arg is a filename. So
fname=$1
But I want that expanded to include the full path and filename, not just what is given as the arg on the command line.
E.g., if the user's cwd is /home/joe/a/b/c/ and he specifies
../x/file-a.ext
then the function/utility should transform that into the absolute path with filename:
/home/joe/a/b/x/file-a.ext
In the simplest scenario, the answer would be $PWD/file-a.ext, but that would by no means cover a portion of the possible scenarios.
You'd think this functionality would be included already in one or another linux utility. It's kinda like the complement to the 'basename' utility. I've looked into the dark corners of ls, stat, file, bash, type, find, and a few other linux standards, but nothing seems to do this.
Any gurus out there know the utility which does this?
On Tue, Dec 09, 2014 at 03:57:03PM -0500, ken wrote:
You'd think this functionality would be included already in one or another linux utility. It's kinda like the complement to the 'basename' utility. I've looked into the dark corners of ls, stat, file, bash, type, find, and a few other linux standards, but nothing seems to do this.
'readlink -f FILE'
The -f (or --canonicalize) follows symlinks and prints the canonical path.
On 12/09/2014 08:11 PM, Jonathan Billings wrote:
On Tue, Dec 09, 2014 at 03:57:03PM -0500, ken wrote:
You'd think this functionality would be included already in one or another linux utility. It's kinda like the complement to the 'basename' utility. I've looked into the dark corners of ls, stat, file, bash, type, find, and a few other linux standards, but nothing seems to do this.
'readlink -f FILE'
The -f (or --canonicalize) follows symlinks and prints the canonical path.
Perfect! Thanks!!!
I don't know if this is of interest as an alternative.
I did find a cool functionality called locate and updatedb Updatedb creates the database of your files, locate does superfast searches.
It essentially does a superfast "find" on your root filesystem, giving you the fully qualified path of all hits. You can create db's on your other filessytems.
The problem is that it can get stale, but you can update it before doing your searches. Plus it gives you a fully qualified path name with the results.
So if you need to do a set of searches on a filesystem (or whole system)
run updatedb on each target filesystem to create the db for that filesystem. then use locate to search each filesystem "db"... it takes seconds like ls instead of minutes like find....the more files in the FS, the quicker the searches compared to other tools.
the best part is you can run the db's when your systems are quiet, and the databases use minimal diskspace.
On 12/9/2014 2:57 PM, ken wrote:
This should be simple, but it's not, unless I'm forgetting something.
Writing a script, an arg is a filename. So
fname=$1
But I want that expanded to include the full path and filename, not just what is given as the arg on the command line.
E.g., if the user's cwd is /home/joe/a/b/c/ and he specifies
../x/file-a.ext
then the function/utility should transform that into the absolute path with filename:
/home/joe/a/b/x/file-a.ext
In the simplest scenario, the answer would be $PWD/file-a.ext, but that would by no means cover a portion of the possible scenarios.
You'd think this functionality would be included already in one or another linux utility. It's kinda like the complement to the 'basename' utility. I've looked into the dark corners of ls, stat, file, bash, type, find, and a few other linux standards, but nothing seems to do this.
Any gurus out there know the utility which does this?
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
On 2014-12-10, Dan Hyatt dhyatt@dsgmail.wustl.edu wrote:
I don't know if this is of interest as an alternative.
It may or may not be, but it doesn't help the OP, who already knows where the file is, and just wants the full absolute path. locate will not help him there, especially if there are multiple files with the same filename.ext on that filesystem.
I did find a cool functionality called locate and updatedb
locate has been around for many many years, certainly since at least CentOS 4, likely much earlier.
The problem is that it can get stale, but you can update it before doing your searches.
There is (or at least, there should be) a script in /etc/cron.daily which updates it nightly.
So if you need to do a set of searches on a filesystem (or whole system) run updatedb on each target filesystem to create the db for that filesystem.
You can configure locate (in /etc/updatedb.conf) with which directories to index or not index. Then you do not need to maintain your own indexes, you can simply use the single system index.
--keith
On 12/10/2014 04:02 PM, Dan Hyatt wrote:
I don't know if this is of interest as an alternative.
I did find a cool functionality called locate and updatedb Updatedb creates the database of your files, locate does superfast searches.
It essentially does a superfast "find" on your root filesystem, giving you the fully qualified path of all hits. You can create db's on your other filessytems.
The problem is that it can get stale, but you can update it before doing your searches. Plus it gives you a fully qualified path name with the results.
So if you need to do a set of searches on a filesystem (or whole system)
run updatedb on each target filesystem to create the db for that filesystem. then use locate to search each filesystem "db"... it takes seconds like ls instead of minutes like find....the more files in the FS, the quicker the searches compared to other tools.
the best part is you can run the db's when your systems are quiet, and the databases use minimal diskspace.
Dan,
Thanks for responding. I've been using those two utilities for a long time, and they are indispensable. But they don't solve the issue I'm having. Consider the case where there are multiple files with the same name but different paths. Also, it takes quite a while for the data used by those utilities to update, much too long for an interactive script.
On 12/9/2014 2:57 PM, ken wrote:
This should be simple, but it's not, unless I'm forgetting something.
Writing a script, an arg is a filename. So
fname=$1
But I want that expanded to include the full path and filename, not just what is given as the arg on the command line.
E.g., if the user's cwd is /home/joe/a/b/c/ and he specifies
../x/file-a.ext
then the function/utility should transform that into the absolute path with filename:
/home/joe/a/b/x/file-a.ext
In the simplest scenario, the answer would be $PWD/file-a.ext, but that would by no means cover a portion of the possible scenarios.
You'd think this functionality would be included already in one or another linux utility. It's kinda like the complement to the 'basename' utility. I've looked into the dark corners of ls, stat, file, bash, type, find, and a few other linux standards, but nothing seems to do this.
Any gurus out there know the utility which does this?
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos