e****d 发帖数: 333 | 1 how to find all sub directories, where the target file lives, but no deepper
level?
for example, we have timestamp files for each directory, but we don't want
to find subfolder timestamp files any more. the files look like this
/usr/local/timestamp
/usr/local/bin/timestamp
/usr/local/lib/timestamp
/usr/name/timestamp
/media/v1/
/home/jk/
now we run a find command: find ???? timestamp
we get two files
/usr/local/timestamp
/usr/name/timestamp
all deeper level timestamps are not shown.
how to do this find??? |
d***a 发帖数: 13752 | 2 find . -name timestamp -depth 3 |
e****d 发帖数: 333 | 3 this does not work, in reality, the directory can be arbitrarily deep,
timestamp can show up for the first time in any depth, any level. we just
want to have the parent level, all child level should be ignored.
【在 d***a 的大作中提到】 : find . -name timestamp -depth 3
|
d***a 发帖数: 13752 | 4 find . -name timestamp -prune
【在 e****d 的大作中提到】 : this does not work, in reality, the directory can be arbitrarily deep, : timestamp can show up for the first time in any depth, any level. we just : want to have the parent level, all child level should be ignored.
|
e****d 发帖数: 333 | 5 that does not work. we don't want to discard all path including timestamp
we want to have a subset of path which include timestamp.
The subset are the parent level of timestamp folders. if any timestamp file
is in a subfolder, the subfolder will be discarded in the results.
for example:
/parent/timestamp
/parent/children/timestamp
we want to have only /parent/timestamp in results.
thanks.
【在 d***a 的大作中提到】 : find . -name timestamp -prune
|
e*******o 发帖数: 4654 | 6 写个脚本吧 为啥非得用find
file
【在 e****d 的大作中提到】 : that does not work. we don't want to discard all path including timestamp : we want to have a subset of path which include timestamp. : The subset are the parent level of timestamp folders. if any timestamp file : is in a subfolder, the subfolder will be discarded in the results. : for example: : /parent/timestamp : /parent/children/timestamp : we want to have only /parent/timestamp in results. : thanks.
|
d***a 发帖数: 13752 | 7 find . -name timestamp -prune | awk -F/ '{print $2"/timestamp";}' | awk '!x[
$0]++'
file
【在 e****d 的大作中提到】 : that does not work. we don't want to discard all path including timestamp : we want to have a subset of path which include timestamp. : The subset are the parent level of timestamp folders. if any timestamp file : is in a subfolder, the subfolder will be discarded in the results. : for example: : /parent/timestamp : /parent/children/timestamp : we want to have only /parent/timestamp in results. : thanks.
|
e****d 发帖数: 333 | 8 this does not work. timestamp is a file, once we find such a file in a
folder, say folder A, all subfolders of this found folder will be skiped.
【在 d***a 的大作中提到】 : find . -name timestamp -prune | awk -F/ '{print $2"/timestamp";}' | awk '!x[ : $0]++' : : file
|
d***a 发帖数: 13752 | 9 find . -name timestamp -prune | awk -F/ '{print $2"/timestamp";}' | awk '!x[
$0]++'
【在 e****d 的大作中提到】 : this does not work. timestamp is a file, once we find such a file in a : folder, say folder A, all subfolders of this found folder will be skiped.
|
d***a 发帖数: 13752 | 10 呵呵,想起以前做coding project的时候,最大的问题不是编程,而是用户需求分析。 |
n*****t 发帖数: 22014 | 11 find | sort | awk
比较 last current 两行的 dirname,好像想不出更巧妙的办法 。。。
deepper
【在 e****d 的大作中提到】 : how to find all sub directories, where the target file lives, but no deepper : level? : for example, we have timestamp files for each directory, but we don't want : to find subfolder timestamp files any more. the files look like this : /usr/local/timestamp : /usr/local/bin/timestamp : /usr/local/lib/timestamp : /usr/name/timestamp : /media/v1/ : /home/jk/
|