Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude a directory from find linux [duplicate]

Tags:

linux

find

bash

I want to exclude all directories from the find command target. I can use this:

find / -not -path /my/path -name name

But this still keep looking at all subdirectories of /my/path. Is there a way to exclude the directory and all its subdirectories from find?

like image 313
St.Antario Avatar asked Aug 24 '17 08:08

St.Antario


People also ask

How do I exclude a directory in Find command?

To exclude multiple directories, OR them between parentheses. And, to exclude directories with a specific name at any level, use the -name primary instead of -path .

How do I copy and exclude a directory in Linux?

We can also use cp command to copy folders from one location to another excluding specific directories. Go your source directory i.e ostechnix in our case. The above command will copy all contents of the current folder ostechnix except the sub-directory dir2 and saves them to /home/sk/backup/ directory.

How do you exclude a directory?

Go to Start > Settings > Update & Security > Windows Security > Virus & threat protection. Under Virus & threat protection settings, select Manage settings, and then under Exclusions, select Add or remove exclusions. Select Add an exclusion, and then select from files, folders, file types, or process.

How do you use prune in Find command?

Prune usage:$ find . -prune . The find command works like this: It starts finding files from the path provided in the command which in this case is the current directory(.). From here, it traverses through all the files in the entire tree and prints those files matching the criteria specified.


1 Answers

with -prune

find . -name directory_to_exclude -prune -o ...

to exclude many directories

find . \( -name dir1_to_exclude -o -name dir2 ... \) -prune -o ...
like image 83
Nahuel Fouilleul Avatar answered Sep 29 '22 22:09

Nahuel Fouilleul