需要在Debian中删除带空格的文件

时间:2013-02-06 21:07:21

标签: find debian filenames spaces

我需要查找并删除某个文件夹中包含空格的文件。

3 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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

首先,您需要迭代文件,以便无论空格如何都能正确地为您提供文件。查看this question。我赞成这个:

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

然后,使用sed之类的内容将$line更改为您需要的任何内容(例如,没有空格的相同内容)就在command "$line"的位置。

答案 2 :(得分: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

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