Friday, April 19, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 8567  / 2 Years ago, fri, march 18, 2022, 2:02:14

I have a lot of directories on my system, with a structure looking like this:



-----data
------- 001abc
------- 002abc
------- 003abc
------- 004abc
------- 005abc
....


When I want find a certain directory, I just type find . -iname "002abc*" but how can I find a directory excluding certain name matches?



Something like this in MySQL select * from folder where filename != '0021bc'


More From » bash

 Answers
6

Use ! in a find command to negate (invert) the option following after. In your case:



find . ! -iname "002abc*"


and optionally, only matching folders:



find . ! -iname "002abc*" -type d


will list all folders except the ones named matching the pattern 002abc*.



The ! can be problematic in shell scripting sometimes, so as Flimm pointed out, the -not parameter is a very useful synonym to it.


[#33185] Friday, March 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oargrou

Total Points: 336
Total Questions: 105
Total Answers: 113

Location: Vietnam
Member since Sun, Oct 18, 2020
4 Years ago
oargrou questions
Thu, May 13, 21, 16:38, 3 Years ago
Wed, Jul 21, 21, 01:38, 3 Years ago
Sat, May 15, 21, 17:39, 3 Years ago
Tue, May 24, 22, 14:58, 2 Years ago
Sat, Mar 19, 22, 05:22, 2 Years ago
;