The find command doesn't have an option to escape special characters, but if it did, it's choice of what to escape might not match the exact needs of your program. There are many different answers, depending on how exactly you want to use the output, as well as what assumptions you are making about what odd characters aren't in the filenames. find has some very useful fine-grained searching capabilities, and is mandatory for tens of thousands of files (at which point you'll run into the shell's maximum number of arguments), but for day-to-day usage it is often unnecessary. *.txt instead, to use every *.txt in the working directory. If you don't want recursiveness, obviously just use. bashrc, so this is always enabled for me (and so are extended globs, which are also useful). I have a line saying shopt -s globstar extglob in my. **/*.txt # feeds all *.txt files to somecommand, recursively In bash, you have to set this: shopt -s globstar If you have a modern shell (bash 4+, zsh, ksh), you can get recursive globbing with globstar ( **). You may find that you are better off using globbing in many cases. The first of the following will feed the filenames to somecommand one at a time, while the second will expand to a list of files: find. Using -print0 is one option, but not all programs support using nullbyte-delimited data streams, so you'll have to use xargs with the -0 option for some things, as Gnouc's answer noted.Īn alternative would be to use find's -exec or -execdir options.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |