Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello everyone,
I want to find the complete path name of the given file. For example "/home/user/madagascar" is a pathname of madagascar. How to find it using command line. Please help. Regards....
I assume you understand that 'madagascar' will only be '/home/user/madagascar' under certain circumstances - e.g. pwd = /home/user
With these reasonable assumptions, a quick web search suggests that the following should work:
Code:
readlink -f partialfilename
eta:
limitations with locate: will not find the file if it has been created since the last run of updatedb; may find lots of other entries; may take significant time
limitations with find: "find . ..." won't do the job - results will be prefixed ./ not the full canonical path; if you supply the full working directory, still it may find other matching entries in subdirectories, and may also take a long time (both unless you include -maxdepth 1)
However, you may want to find multiple files not just the file that bash would look for.
Last edited by SecretCode; 02-01-2012 at 12:53 PM.
Use "find" then the return of files found are listed by the shell including their paths.
Example: --you look for the file named "overlay", issue this:
Quote:
sudo find /usr -type f -iname 'overlay'
Returns:
/usr/share/fluxbox/overlay
You must specify the -type f otherwise folders are included in search results. If you don't want to experience excuses from find you may issue it with 'sudo' as I have done above, you shall be prompted for the password if you are a sudoer.
Since locate uses a database to find the file, it will only find files which where present on the system since the latest update from the database using the command
Code:
updatedb
If you use the old db, you could find files which are deleted or don't find files which are created after the update.
limitations with locate: will not find the file if it has been created since the last run of updatedb; may find lots of other entries; may take significant time
limitations with find: may find other matching entries in subdirectories, and may also take a long time (both unless you include -depth 1)
I think (but have not verified) that some versions of mlocate will update the the data base when a file is created.
The -b option reduces the number of "false positives," but, you will still find every file or directory containing the string "madagasca."
The search is actually quite fast since it takes place in the (indexed) data base of file entries.
Depending on the settings in /etc/updatedb.conf, you might locate entries with "madagasca" in them that are system file or which belong to other users. If this is a problem, you can run udatedb in your home directory to create a "personal" data base, and tell locate to use that instead of the default system=wide data base.
See man locate and man updatedb for more information
and it found nothing. In fact even now, hours later, it's still not in the locate db.
But as ever, there are lots of solutions to the general problem - which is best depends on the OP's specific requirement which wasn't very precise. I interpreted it as "get the canonical full path of a single file specified relative to the pwd".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.