Reputation: 763
I have a special requirement where I have to use a separate command to filter out all folders and their files from the search result in Linux!
Example: I have the following folders, and they all have a file called test
/testfolder/f1
/testfolder/f1_0VT0_hc1
/testfolder/f1_0VT0_hc2
So for example if I run ls testfolder/*
the initial results would be:
/testfolder/f1:
test
/testfolder/f1_0VT0_hc1:
test
/testfolder/f1_0VT0_hc2:
test
I need to pipe in another command (e.g. grep
) that would take in that result and filter out all directories that have the _0VT0_ and their files!
I was able to ignore the directories using :
ls testfolder/* | grep -R --exclude-from='.*_0VT0_.*'
but I still got the files!
Question: how can I modify my grep command or what command should I use to ignore the folders and the files within them!
Clarification I will be given an ls
or find
command and I need another command to execute after them that will filter out such folders and their files. So something I can pipe or do in a batch file.
Upvotes: 0
Views: 73
Reputation: 780688
Use the -prune
option to find
.
find * -name '*_0VT0_*' -prune -o -print
You can use this as part of another command with ordinary command substitution:
ls -d $(find * -name '*_0VT0_*' -prune -o -print)
Upvotes: 2