Using Find But Only in Subdirectories Matching Certain Pattern

using find but only in subdirectories matching certain pattern

Nested find might work for you

find . -type d -name "cpp" -exec find {} -type f \;

How to find all files in subdirectories that match pattern and replace pattern

From man rename you see this command gets options and 3 positional parameters:

SYNOPSIS
rename [options] expression replacement file...

So in your case the first parameter is being interpreted as an option. You may use this syntax:

rename -- '-featurette' '' *-featurette.mkv

to rename the files. -- indicates that any options are over and what follows are only positional parameters.


Totally, to copy the files with one mv process and rename them:

mkdir -p target/dir
find . -maxdepth 2 -type f -name "*-featurette.mkv" -exec mv -t target/dir {} +
cd target/dir && rename -- '-featurette' '' *-featurette.mkv

If you want to rename many files located into different subdirectories, you can use this syntax:

find . -name "*-featurette.mkv" -print0 | xargs -r0 rename -- '-featurette' ''  

How to only find files in a given directory, and ignore subdirectories using bash

If you just want to limit the find to the first level you can do:

 find /dev -maxdepth 1 -name 'abc-*'

... or if you particularly want to exclude the .udev directory, you can do:

 find /dev -name '.udev' -prune -o -name 'abc-*' -print

find recursively, but with specific sub-folder name

You could use a regular expression.

find . -regex '.*/f2/log_7'

This will only match if log_7 is directly nested under f2

Using find to find files WITH a certain pattern and not other pattern

Your attempt does "matches _101_, or does not end in .jpg, or does not end in .wsq". That'll match every single file, based on the two extensions alone, as a file can only have one.

You have to group differently:

find . -type f -name '*_101_*' -not -name '*.jpg' -not -name '*.wsq'

This applies all rules (logical AND is implied).

You also should quote the parameters to -name, or they might be expanded by the shell instead of find.

How can I recursively find all files in current and subfolders based on wildcard matching?

Use find:

find . -name "foo*"

find needs a starting point, so the . (dot) points to the current directory.

Solaris: Find files matching a pattern but only display the directory name

To display the directories of .c files:

find . -name \*.c -exec dirname {} \; | uniq

To display the directories of .html files:

find . -name \*.html -exec dirname {} \; | uniq

If you want to use that in a script,

#/bin/bash

ext=$1
find . -name \*.${ext} -exec dirname {} \; | uniq

Using find to locate files that match one of multiple patterns

Use -o, which means "or":

find Documents \( -name "*.py" -o -name "*.html" \)

You'd need to build that command line programmatically, which isn't that easy.

Are you using bash (or Cygwin on Windows)? If you are, you should be able to do this:

ls **/*.py **/*.html

which might be easier to build programmatically.



Related Topics



Leave a reply



Submit