简体   繁体   English

在find命令中的路径中使用带有〜的符号链接

[英]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). 我正在尝试编写一个命令,该命令将对所有用户起作用,以给定名称的最近文件列表定位,其路径为〜/ work(每个用户映射到/ mnt / data / username /)。 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. 使用-H选项,该选项告诉find在命令行参数中遵循符号链接。

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). ...如果-H有效,并且在命令行上指定的路径之一是指向目录的符号链接,则将检查该目录的内容(尽管-maxdepth 0可以防止此情况)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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