Hot answers tagged

5

Use sort | uniq -c to count identical lines: find "$path" -type f -exec file -b {} + | sort | uniq -c | sort -nr


4

With zsh, I'd do: files=($(do_something to find filenames)) (($#files)) && find $files ... With tcsh: set files=(`do_something to find filenames`) if ($#files) find $files:q ... With bash, mksh or ksh93, set -f; files=($(do_something to find filenames)) ((${#files[@]})) && find "${files[@]}" ... POSIXly: set -f; set -- ...


3

How about doing this: paths=$(do_something to find filenames) if [ "$paths" ]; then find "$paths" ... fi This works independent from the find implementation. Note that find "$paths" with more than a single path name causes problems. If the path names do not contain spaces, you may use: find $paths, otherwise, a working alternative is this function: ...


3

? is a special character in pattern matching, which match any single character. So the command means find all files and directories in /foo/path and its subdirectories, whose names are exactly one character long. The \? is used to prevent your shell from performing filename generation. You can use other quoting mechanisms: find /foo/path -name '?' or: ...


2

The ? is part of a mechanism called "pathname expansion" in the shell. Colloquially, the shell mechanism is called "globing". The basic glob makes use just of three characters: * ? and [ that build "patterns". An asterisk * means: Any character in any quantity (any string). A question mark (?) means: Any character one time. The square braces ...


2

Not really. Consider that find doesn't know what is in the directory tree, but finds out by reading recursively through all directory listing. (sorry for the pun.) For example there could be two first-level directories, one of which has 1 file, and another that has 1000000 files. Something like copying the tree would be different, since a program could ...


2

less $(find . -name myfile.txt) less `find . -name myfile.txt` The first is, I believe, both POSIX-compliant and nest-able. The second, I believe, is more portable.


2

Similar to @coffeeMug, this is the more up-to-date way to doing this as it is apparently faster: find . -name "*.log" -exec ls -l '{}' + I'll also point you to CommandLineFu, which is always helpful with these things.


1

You can achieve this using find's -exec flag: find . -name "*.log" -exec ls -l '{}' \; In this example find searches for all log files in current directory and then list them using ls -l. In your case you should replace ls with less. See the ACTION part of find man page here find(1) man page.


1

Bash 4 solution utilizing associative arrays and for environments with the zero delimiter extensions. First parameter is the target directory, all following parameters are forwarded to file: #!/bin/bash # USAGE: script.sh PATH [PARAMS_FOR_FILE_CMD...] # EXAMPLE 1: ./script.sh . # EXAMPLE 2: ./script.sh /tmp --mime-type path=$1 shift if [[ ! -d "$path" ...


1

+ is the end marker , {} is replaced with the filenames the current directory is the path. so $PWD = /home/jesse/hacking/sh_sandbox/ $0 = /home/jesse/hacking/sh_sandbox/save_params.sh $1 = ./zero_param.txt $2 = ./first_param.txt $3 = ./second_param.txt $4 = ./third_param.txt or something like that... re-reading the question it seems that the script is ...


1

Based on L.Levrel response, using the tools supplied in OS X (this should also work in Ubuntu). find . -type f -name '*.pdf' -exec grep -alE '/Producer \(pdfTeX|/Producer\(pdfTeX' {} +



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