【发布时间】:2013-02-06 21:07:21
【问题描述】:
我需要在某个文件夹中查找并删除带有空格的文件。
【问题讨论】:
-
您必须更具体。文件 名称 带有空格?还是 文件 本身带有空格?
-
我下面的回答显然是假设前者。
标签: find debian filenames spaces
我需要在某个文件夹中查找并删除带有空格的文件。
【问题讨论】:
标签: find debian filenames spaces
$ ls -l
total 16
-rw-r--r-- 1 smw staff 10 Feb 6 16:10 Foo Bar
-rw-r--r-- 1 smw staff 11 Feb 6 16:10 foobar
$ ls -l *\ *
-rw-r--r-- 1 smw staff 10 Feb 6 16:10 Foo Bar
$ rm -i *\ *
remove Foo Bar? y
$ ls -l
total 16
-rw-r--r-- 1 smw staff 11 Feb 6 16:10 foobar
【讨论】:
在处理空格时,你必须处理 bash 的细节......
首先,您需要遍历文件,以一种无论空格如何都能正确提供文件的方式。查看this question。我赞成这个:
find ... | while read line ; do command "$line" ; done
然后就是使用sed 之类的东西将$line 更改为command "$line" 所在的任何你需要的东西(比如没有空格的相同东西)。
【讨论】:
这就是我删除带有空格的文件的方式
pi@raspberrypi ~/Music $ ls -l
-rw-r--r-- 1 pi pi 0 Feb 25 16:05 Sleep Away.mp3
pi@raspberrypi ~/Music $ rm Sleep\ Away.mp3
使用“\”正斜杠转义任何空格
【讨论】: