0

我需要在某个文件夹中查找并删除带有空格的文件。

4

3 回答 3

1
$ 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
于 2013-02-06T21:16:24.917 回答
0

在处理空格时,你必须处理 bash 的细节......

首先,您需要迭代文件,以一种无论空格如何都能正确地为您提供文件的方式。看看这个问题。我赞成这个:

find ... | while read line ; do command "$line" ; done

然后就是使用类似的东西sed来改变$line你需要的任何东西(比如没有空格的相同东西)就在哪里command "$line"

于 2013-02-06T21:21:42.803 回答
0

这就是我删除带有空格的文件的方式

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

使用“\”正斜杠转义任何空格

于 2013-02-25T21:28:09.883 回答