adb command fail to execute if path contain spaces

2020-04-11 10:26发布

I am trying to delete the file using adb command. But the file contain spaces. So adb command throws an error after reading half of the file name till space. Is there a way to overcome this issue. I am executing following adb command

When I execute

adb shell rm /sdcard/samsung_Nexus S_converter.xml

Error message: rm failed for /sdcard/samsung_Nexus, No such file or directory

How ever when I execute:

adb shell rm /sdcard/samsung_Nexus_S_converter.xml

File deletion is successful

I searched for solution for this, if there is any workaround. How ever I couldnt find any.

3条回答
贼婆χ
2楼-- · 2020-04-11 11:06

Did you tried escaping the space

adb shell rm /sdcard/samsung_Nexus\ S_converter.xml

查看更多
再贱就再见
3楼-- · 2020-04-11 11:11

By me it wasn't enough to escape spaces with backslashes:

$ adb shell ls /storage/sdcard1/audio/Die\ Toten\ Hosen/
/storage/sdcard1/audio/Die: No such file or directory
Toten: No such file or directory
Hosen/: No such file or directory        

For some reason I also had to surround the path with '':

$ adb shell ls '/storage/sdcard1/audio/Die\ Toten\ Hosen/'                                                                                                                       
03 - Boxed Set                                                                                                                                                                                                     
04 - Compilations                                                                                                                                                                                                  
05 - Live Albums                             

While surrounding without escaping didn't work:

$ adb shell ls '/storage/sdcard1/audio/Die Toten Hosen'                                                                                                                       
/storage/sdcard1/audio/Die: No such file or directory                                                                                                                                                              
Toten: No such file or directory                                                                                                                                                                                   
Hosen: No such file or directory      
查看更多
甜甜的少女心
4楼-- · 2020-04-11 11:26

Since you are using command line, you need to know that spaces must be escaped by using (backslash before the special character like "space"), so, in your case this should work too:

adb shell rm /sdcard/samsung_Nexus\ S_converter.xml

Hope it helps!

Regards!

查看更多
登录 后发表回答