简体   繁体   中英

Using a symlink with ~ in path in a find command

I am trying to write a command that will work for all users to locate a list of recent files with a given name with a path of ~/work (which maps to /mnt/data/username/ for each user). So the following command will work if I am inside the directory for myself:

find . -name "data.csv" -exec ls -ltr {} +

However, when I try to generalize this so it can be run for any user from any location with the following

find ~/work -name "data.csv" -exec ls -ltr {} +

the command returns nothing. How can I get it to use this symlink available for all users?

Thank you.

Use the -H option, which tells find to follow symlinks in the command line arguments.

find -H ~/work -name "data.csv" -exec ls -ltr {} +

From the man page:

-H
Do not follow symbolic links, except while processing the command line arguments. ... If -H is in effect and one of the paths specified on the command line is a symbolic link to a directory, the contents of that directory will be examined (though of course -maxdepth 0 would prevent this).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM