Use the -prune
primary. For example, if you want to exclude ./misc
:
find . -path ./misc -prune -o -name '*.txt' -print
To exclude multiple directories, OR them between parentheses.
find . -type d \( -path ./dir1 -o -path ./dir2 -o -path ./dir3 \) -prune -o -name '*.txt' -print
And, to exclude directories with a specific name at any level, use the -name
primary instead of -path
.
find . -type d -name node_modules -prune -o -name '*.json' -print
Related Posts:
- How to exclude a directory in find . command
- How do I find all files containing specific text on Linux?
- How can I recursively find all files in current and subfolders based on wildcard matching?
- How to perform grep operation on all files in a directory?
- subprocess.Popen(): OSError: [Errno 8] Exec format error in python?
- How to substitute shell variables in complex text files
- How can I recursively find all files in current and subfolders based on wildcard matching?
- Curl command for https ( SSL )
- “sed” command in bash
- How can I find all *.js file in directory recursively in Linux?
- Shell command to tar directory excluding certain files/folders
- Explaining the ‘find -mtime’ command
- Pseudo-terminal will not be allocated because stdin is not a terminal
- Given two directory trees, how can I find out which files differ by content?
- Diff command along with Grep gives “Binary file (standard input) matches”
- Pseudo-terminal will not be allocated because stdin is not a terminal
- screen Cannot open your terminal ‘/dev/pts/0’ – please check
- ./configure : /bin/sh^M : bad interpreter
- How to use regex with find command?
- What is the difference between “#!/usr/bin/env bash” and “#!/usr/bin/bash”?
- Is there a “goto” statement in bash?
- Implementing shell in C and need help handling input/output redirection
- Command to change the default home directory of a user
- Writing a simple shell in C using fork/execvp
- Implementation of multiple pipes in C
- chmod: changing permissions of ‘my_script.sh’: Operation not permitted
- What does “&” at the end of a linux command mean?
- What does set -e mean in a bash script?
- What does set -e mean in a bash script?
- Syntax error near unexpected token ‘then’
- “find: paths must precede expression:” How do I specify a recursive search that also finds files in the current directory?
- How to use sed to extract substring
- How do I know the script file name in a Bash script?
- Shell command to monitor changes in a file
- What is “-bash: !”: event not found”
- What does ‘set -e’ do, and why might it be considered dangerous?
- How to add a timestamp to bash script log?
- Colors in bash after piping through less?
- How can I kill all stopped jobs?
- How to run command as user who has /usr/sbin/nologin as Shell?
- Is there a way to do a remote “ls” much like “scp” does a remote copy?
- How do I join two named pipes into single input stream in linux
- How do I deal with a filename that starts with the hyphen (-) character?
- Chmod 777 to a folder and all contents [duplicate]
- Bash: No such file or directory?
- Cannot connect to the Docker daemon at unix:/var/run/docker.sock. Is the docker daemon running?
- Confused about stdin, stdout and stderr?
- What’s a .sh file?
- Amazon Linux: apt-get: command not found
- How to set the environmental variable LD_LIBRARY_PATH in linux
- What’s a .sh file?
- How can I symlink a file in Linux? [closed]
- How to fix ‘sudo: no tty present and no askpass program specified’ error?
- Kill detached screen session [closed]
- How do I grep recursively?
- How do I grep recursively?
- Why do you need to put #!/bin/bash at the beginning of a script file?
- How to get the url of the current svn repo?
- What does pss mean in /proc/pid/smaps
- apt-get error: Sub-process /usr/bin/dpkg returned an error code (1)
- How to unmount a busy device
- “Couldn’t find a file descriptor referring to the console” on Ubuntu bash on Windows
- How to unmount a busy device
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- performing HTTP requests with cURL (using PROXY)
- Where can I find php.ini?
- gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
- error: ‘Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)’ — Missing /var/run/mysqld/mysqld.sock
- No space left on device
- How do I grep recursively?
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- Amazon Linux: apt-get: command not found
- How to install grub after installing Windows 10
- Linux: ‘Username’ is not in the sudoers file. This incident will be reported
- how to find libstdc++.so.6: that contain GLIBCXX_3.4.19 for RHEL 6?
- How to extract C source code from .so file?
- Pass a password to ssh in pure bash
- “E: Unable to locate package python-pip” on Ubuntu 18.04 [duplicate]
- -bash: syntax error near unexpected token `newline’ for display command
- Using find to locate files that match one of multiple patterns
- How do I use grep to search the current directory for all files having the a string “hello” yet display only .h and .cc files?
- SSH using python script
- How can I exclude directories from grep -R?
- How can I exclude directories from grep -R?
- Changing the resolution of a VNC session in linux
- gcc: error: unrecognized command line option
- mysql_config not found when installing mysqldb python interface
- Linux error while loading shared libraries: cannot open shared object file: No such file or directory
- How to set proxy for wget?
- Argument list too long error for rm, cp, mv commands
- QEMU: /bin/sh: can’t access tty; job control turned off
- How to change permissions for a folder and its subfolders/files in one step
- Difference between using “chmod a+x” and “chmod 755”
- Meaning of exit status 1 returned by linux command
- Building HelloWorld C++ Program in Linux with ncurses
- How does “cat << EOF" work in bash?
- ssh: Could not resolve hostname [hostname]: nodename nor servname provided, or not known
- Docker can’t connect to docker daemon
- Need a good hex editor for Linux
- tar removing leading ‘/’ from member names