Tag Info

Hot answers tagged

6

Assuming you are using GNU find or another find which has these options, find . -mindepth 8 -maxdepth 8 -name '*XYZ*' If you don't have such a find command, you can use this POSIX version: # must contain exactly 7 slashes find . -path '*/*/*/*/*/*/*/*' -prune -name '*XYZ*' -path '*/*/*/*/*/*/*/*' selects paths that are at least 8 levels deep (contain ...


5

since the find arguments are positional a function would be a better solution. find(){ command find "$1" -regextype posix-egrep "${@:2}" } since you want to "overwrite" the original command you need to use the full path of find so that your new function doesn't create an infinite loop of calling itself. by using a function instead of an alias we can ...


3

You can't use capture groups from the regexp in the command to execute. If you use find -regex to restrict matches, you'll have to do some extra matching in the command. You can do that by invoking a shell and using its own pattern matching constructs. For example, if foo and bar are constant strings and regex1 can't match bar: find … -exec sh -c ' ...


2

GNUly: find . -iname '*.gif' -print0 | grep -z loader | xargs -r0 cp -t /home/me POSIXly: find . -name '*.[gG][iI][fF]' -path '*loader*' -exec sh -c ' exec cp "$@" /home/me' sh {} + (I used -path so it be equivalent with the grep solution, but it sounds like you want loader to be found in the name of the file as opposed to its directory components, ...


1

You could do something like: efind() ( found=false for arg do if [ "$arg" = -regex ] && ! "$found"; then set -- "$@" -regextype posix-egrep found=true fi set -- "$@" "$arg" shift done exec find "$@" ) To insert -regex-type posix-egrep before the first occurrence of -regex.


1

I think xargs is the more simple and direct solution: find . -iname *.gif | grep loader | xargs cp -t /home/me


1

mv path_to_example_dir/*_jony /jony


1

The possible duplicate Link answered the question partly. To provide multiple name patterns to 'find' use this find $directory -type f \( -name "*.zip" -o -name "*.rar" \) The complete answer to the question is: find $directory -type f \( -name "*.zip" -o -name "*.rar" \) -print0 | xargs -0 -n1 du -b | sort -n -r with $directory being comp_tuts/ dir


1

With zsh you could use the function age to print only the names of files that have been modified on a certain date: autoload age print -rl -- *.php(.e:age 2011/02/08:) or, if you want to search recursively: autoload age setopt extendedglob print -rl -- **/*.php(.e:age 2011/02/08:)



Only top voted, non community-wiki answers of a minimum length are eligible