command line - deleting folders with spaces in their names using xargs - Ask Ubuntu


why can't xargs delete directories spaces in names, , how fix that?

76 find . -type d |xargs  rm -rf  77 rm -rf fire\ hydrant/  78 rm -rf wine\ glass/  79 rm -rf tennis\ racket/  80 rm -rf traffic\ light/  81 rm -rf parking\ meter/  82 rm -rf teddy\ bear/  83 rm -rf sports\ ball/  84 rm -rf cell\ phone/  85 rm -rf stop\ sign/  86 rm -rf dining\ table/  87 rm -rf potted\ plant/ 

fix using -print0 in find , xargs -0 in xargs tell both commands use null character separator instead of space:

find . -type d -print0 | xargs -0 rm -rf 

here's nice explanation of why breaks , how fix works the linux command line william e. shotts jr.

dealing funny filenames

unix-like systems allow embedded spaces (and newlines!) in filenames. causes problems programs xargs construct argument lists other programs. embedded space treated delimiter, , resulting command interpret each space-separated word separate argument. overcome this, find , xarg allow optional use of null character argument separator. null character defined in ascii character represented number 0 (as opposed to, example, space character, defined in ascii character represented number 32). find command provides action -print0, produces null-separated output, , xargs command has --null option, accepts null separated input. here’s example:

find ~ -iname '*.jpg' -print0 | xargs --null ls -l 

using technique, can ensure files, containing embedded spaces in names, handled correctly.

(-0 short version of --null option)


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User