Tag Info

Hot answers tagged

10

See the man page for updatedb, "If the database already exists, its data is reused to avoid rereading directories that have not changed". Whereas the find command traverses all directories regardless of whether they have changed.


7

You can use : find . -type f -printf '%p::' | sed 's/::$/\n/' The -printf predicate of find will print the file names in a single line delimited by :: and then sed will substitute the last :: with a newline. Example : $ find . -type f -printf '%p\n' ./foo ./test ./bar $ find . -type f -printf '%p::' | sed 's/::$/\n/' ./foo::./test::./bar


5

You can use -o for logical OR. Beware however that all find predicates have logical values, so you'll usually need to group ORed things together with parens. And since parens also have a meaning to the shell, you'll also need to escape them: find /some/dir -maxdepth 1 \( -name '*.c' -o -name '*.h' \) -print


4

The GNU implementation of grep (also found in most modern BSDs though the latest versions are a complete (mostly compatible) rewrite) supports a -o option to output all the matched portions. LC_ALL=C grep -ao CDA | wc -l would then count all the occurrences. LC_ALL=C grep -abo CDA to locate them with their byte offset. LC_ALL=C makes sure grep doesn't ...


3

find <path>/. -type f -size 1033c ! -perm -0001 -ls


3

Get the file size: size="$(stat --printf="%s" "$path")" Get the path without the last extension: path_without_extension="${path%.*}" Compare the two: [ "${path_without_extension}.${size}" = "$path" ]


2

To answer your question, you can use -o option: expr1 -o expr2 Or; expr2 is not evaluated if expr1 is true. expr1 -or expr2 Same as expr1 -o expr2, but not POSIX compliant. like this: $ find . -maxdepth 1 -name "name1" -o -name "name2" ./name1 ./name2


2

One way is to look for one of the file names (pick the rarest one if you know which one it is) then filter the matches to retain only those where the other file exists. find . -name foo -exec sh -c '[ -e "${0%/*}/bar" ] && [ -e "${0%/*}/buz" ] && echo "${0%/*}"' {} \; You can use the shell snippet's return code if you want to use a find ...


2

The use of -perm +mode seems to be deprecated. Maybe the help from man find can help to resolve your doubt: -perm mode File's permission bits are exactly mode (octal or symbolic). Since an exact match is required, if you want to use this form for symbolic modes, you may have to specify a rather complex mode string. For example -perm g=w will ...


2

Try this, fixes the cp parameter order and limits to just root filesystem rather than trying to traverse /proc and the like. find / -xdev -type f -perm a+r -exec cp {} /home/student/abc \;


2

With GNU find and GNU coreutils, and assuming your directories don't have newlines in their names: find ~/foo -mindepth 1 -maxdepth 1 -type d -exec du -ks {} + | awk '$1 <= 50' | cut -f 2- This will list directories with total contents smaller than 50K. If you're happy with the results and you want to delete them, add | xargs rm -rf to the end of the ...


1

What about that dollar sign in front of cmd, as in $cmd = Is the dollar sign a typo? (Sorry for not making this a comment -- no reputation points.)


1

I'm assuming by parent folder you just mean the folder with filename.txt. You can get find to print this folder name with -printf '%h\n' instead of the -exec. You can pipe this into a shell loop or xargs for example: find /path/ -name "filename.txt" -type f -mtime -2 -printf '%h\n' | xargs -i rsync ... {} /destination \; I think you need to add -R to ...


1

So I took your hex string and printed it out to bytes, but I swapped the NULs for <spaces> (mostly because I can't figure on how to get a NUL in a grep pattern): time \ ( set x58 x5e x20 x20 xfe x5a x1e xda \ x48 x20 x20 x20 x0d x20 x03 x20 \ x07 x20 x20 x20 xcd x01 x20 x20 export ...


1

From cp man page: cp [OPTION]... [-T] SOURCE DEST cp [OPTION]... SOURCE... DIRECTORY cp [OPTION]... -t DIRECTORY SOURCE... You are giving parameters to cp in wrong order. Source should come before destination. Correct command is : find / -type f -perm a+r -exec cp {} /home/student/abc \; Also note that you should end -exec parameter with ;



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