14 Matching Annotations
- Nov 2022
-
stackoverflow.com stackoverflow.com
-
find . -regextype posix-extended -regex ".*\.(jpg|gif|png|jpeg)"
-
That's an important remark. find /path/to/ -iname '*.gif' -o -iname '*.jpg' -print0 will only print the jpg files! You need brackets here: find /path/to/ \( -iname '*.gif' -o -iname '*.jpg' \) -print0
-
- Jul 2022
-
stackoverflow.com stackoverflow.com
-
Always use a while read construct: find . -name "*.txt" -print0 | while read -d $'\0' file do …code using "$file" done The loop will execute while the find command is executing. Plus, this command will work even if a file name is returned with whitespace in it. And, you won't overflow your command line buffer.
-
- Aug 2020
-
stackoverflow.com stackoverflow.com
-
Speed example -- over 829 files, the "find -exec" method took 26 seconds while the "find -print0 | xargs --null" method tool 0.7 seconds. Significant difference.
-
- Apr 2020
-
stackoverflow.com stackoverflow.com
-
I had never considered it that in nearly a decade of using GNU find! Thank you for that! It will definitely change the way I think about -prune from now on.
-
I think this structure is much easier and correlates to the right approach
-
it isn't actually -prune itself that causes this, by the way. The issue is that the or operator "short-circuits", and or has lower precedence than and. The end result is that if a file called .snapshot is encountered it will match the first -name, -prune will then do nothing (but return true), and then the or returns true since its left-argument was true. The action (eg: -print) is part of its second argument, so it never has a chance to execute.
-
If all you want to do is print the results you might be used to leaving out the -print action. You generally don't want to do that when using -prune.
-
which means that it'll also print out the name of the directory you're pruning, which usually isn't what you want. Instead it's better to explicitly specify the -print action if that's what you want
-
The thing I'd found confusing about -prune is that it's an action (like -print), not a test (like -name). It alters the "to-do" list, but always returns true.
-
-
www.theunixschool.com www.theunixschool.com
-
Did you expect the temp directory to get printed? In the last example, we saw the directories ./temp and ./C/temp got printed, but not now. This is the effect of the -print option. By default, the find command prints all the files matching the criteria. However, once the -print option is specified, it will print files only on explicit print instructions. In this find command, -print is associated in the other side of the OR condition, and hence nothing will get printed from the 1st part of the condition.
-
12. Same using the wholename option and prune to exclude directory: $ find . -wholename "./temp" -prune -o -perm 644 -print ./area.pm ./C/temp ./C/f2.c find has a switch with the name 'wholename'. Say, in your directory tree, there might be more than one temp directory. The earlier approaches will prune all the temp dierctories. In case, if the requirement is to prune a specific temp directory, then you can give the path of the directory itself. Note: The path specified in the wholename option should be relative to the search path specified, not the absolute path.
-
- Dec 2019
-
unix.stackexchange.com unix.stackexchange.com
-
Using find and cpio is a more unix-y approach in that you let find do the file selection with all the power that it has, and let cpio do the archiving. It is worth learning this simple use of cpio, as you find it easy to solve problems you bang your ahead against when trying tar.
-
find
-