OS X: list and remove files with spaces

I'd like to do this in OS X:

ls -rt | xargs rm -i

However, rm is choking on the fact that some of the files have whitespaces.

I mention OS X because BSD's version of ls does not have a -Q flag.

Is there a way to do this without having to use find -print0 ?


尝试这个

while read -u 3
do
  rm -i "$REPLY"
done 3< <(ls -rt)

[sgeorge@sgeorge-ld staCK]$ touch "file name"{1..5}.txt
[sgeorge@sgeorge-ld staCK]$ ls -1
file name1.txt
file name2.txt
file name3.txt
file name4.txt
file name5.txt
[sgeorge@sgeorge-ld staCK]$ ls -rt |  xargs -I{} rm -v {}
removed `file name5.txt'
removed `file name4.txt'
removed `file name3.txt'
removed `file name2.txt'
removed `file name1.txt'

要么

[sgeorge@sgeorge-ld staCK]$ ls -1
file a
file b
file c
file d

[sgeorge@sgeorge-ld staCK]$ OLDIFS=$IFS; IFS=$'n'; for i in `ls -1` ; do rm -i $i ; done ; IFS=$OLDIFS
rm: remove regular empty file `file a'? y
rm: remove regular empty file `file b'? y
rm: remove regular empty file `file c'? y
rm: remove regular empty file `file d'? y

If you want to delete all files, what's wrong with rm -i * ?

Don't parse ls

链接地址: http://www.djcxy.com/p/11712.html

上一篇: iOS上的Unity3D,检查Obj中的设备摄像头图像

下一篇: OS X:列出并删除空格的文件