Trying to create an AppImage for OpenSpace led to many learnings. Among them - how to delete the files found with the "find" command -
find . -name '*.cpp' -print0 | xargs -0 -P2 rm
Explanation -
"If you're on Linux or have the GNU find and xargs commands, then use -print0 with find and -0 with xargs to handle file names containing spaces and other odd-ball characters." - https://stackoverflow.com/questions/864316/how-to-pipe-list-of-files-returned-by-find-command-to-cat-to-view-all-the-files
"xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or new‐lines, and executes the command (default is echo) one or more times with any initial-arguments followed by items read from standard input. Blank lines on the standard input are ignored." ... "Because Unix filenames can contain blanks and newlines, this de‐ fault behaviour is often problematic; filenames containing blanks and/or newlines are incorrectly processed by xargs. In these situations it is better to use the -0 option, which prevents such problems. When using this option you will need to ensure that the program which produces the input for xargs also uses a null character as a separator. If that program is GNU find for example, the -print0 option does this for you." - https://www.man7.org/linux/man-pages/man1/xargs.1.html
and the -P option is "-P max-procs, --max-procs=max-procs
Run up to max-procs processes at a time"
No comments:
Post a Comment