There were a few times that I wanted to copy the path of a configuration file, but this simple task seems not as easy as you think. It’s so strange that ls command has no such option for it, i.e. prefixing path, I am sure I have read all options.
A quick workaround I would do is:
echo $PWD foo<TAB> | xsel
In Bash, if you use / instead of space to separate the file name and use auto-completion, it will result a literal text \$PWD/foobar in prompt, which is not I want. And this method may have slight issue when the file is located in symlink (symbolic link) directory if you want to have the canonical path.
You may end up using echo $(pwd -P) foo<TAB>.
1 readlink command
readlink command is the best option in my opinion, I can use it with auto-completion with not problems:
readlink foo<TAB>
It prints out the files with full path. If it involves symlink, then add -f, e.g.:
readlink -f foo<TAB>
2 With find command
For multiple files listing, find is a better option for that, but you will need to specify path to find, or the output would be relative path. Also, same issue for symlink.
Combining with readlink is the best bet, which solves both issues:
find -exec readlink -f {} \;
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.