LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How do you display the full path of a file? (https://www.linuxquestions.org/questions/linux-general-1/how-do-you-display-the-full-path-of-a-file-948842/)

kike_coello 06-06-2012 11:31 AM

How do you display the full path of a file?
 
Hi, I just want to know if there is a command to display the full path or address of a file by just typing in the name of the file or piping or redirecting the name of the file to some command.

The way I get the name of the files is with grep, and I get a bunch of files, but they are just filenames with extensions. What I want is to feed this column of filenames to some command and get the full path and the filename.

Or would I have to write a script, but even then I think I would need a command to basically just give me the full path of the file and then I could write a loop for the rest of the files.

Thanks

Enrique

PS: I don't know if this is the right place to post, sorry.

unSpawn 06-06-2012 11:56 AM

If (s)locate runs as a (daily) cron job and if it covers all areas you want to find items in then you could type 'locate itemname' or 'locate -r ".*name$";'. (Note as unprivileged user you can have your own locate database: 'man updatedb; man locate' for more.) Else 'find /path/somewhere -iname \*item\*;' will work too.

antegallya 06-06-2012 01:17 PM

Hi,

for the problem of getting the full path of the file, you could use unSpawn solution to find them in the whole system. But if those filenames are actually relative paths, you could use
Code:

readlink -f relative_path
But you can't just pipe paths to readlink. However you can avoid the writing of a loop using xargs like this
Code:

grep [...] | xargs -l readlink -f
It will call 'readlink -f' with each output line of your grep.

kike_coello 06-06-2012 02:22 PM

Thanks, I got the full path with find. I couldn't get readlink to work, sorry. And locate didn't find the files I needed, it found other files with similar names, even after running update. But thanks for the help unSpawn and antegallya.


All times are GMT -5. The time now is 03:12 PM.