Android/Linux: Delete multiple files containing the @, except for 2 files

1

I'm trying to delete with Terminal Emulator or Termux files located in /data/dalvik-cache/arm. I want to delete all files except for 2 of them: "system@framework@boot.art" and "system@framework@boot.oat". The problem is with the special character "@" found 2 times in the name of the files.

My goal is to write a very rudimentary script for bash, in which I just mount the system, delete everything except those 2, unmount and reboot. Could someone please help me? I'm rather new to all of this. I've searched many websites, man-pages without any luck mixing the removal of multiple file containing special characters and in the same time excluding some.

Here's what I'm trying:

#/system/bin/sh
mount -o rw,remount,rw /system
cd /data/dalvik-cache/arm
shopt -s extglob
rm -v !("system@framework@boot.art"|"system@framework@boot.oat")        --> Syntax error
mount -o ro,remount,ro /system
reboot

As indicated, the rm command (with the extended wildcard) gets a "Syntax error".

Alien

Posted 2018-07-11T20:57:15.907

Reputation: 13

Answers

0

  1. The first line of your script is a comment.  If you mean for it to be a “she-bang”, it must begin with #! (you left out the !).
  2. … and then it might work better if you say #!/system/bin/bash.

Scott

Posted 2018-07-11T20:57:15.907

Reputation: 17 653

Thank you very much! I wrote the script in a hurry and must have forgotten about the !. I used the bash provided by Termux and it worked! Thanks again! – Alien – 2018-07-11T22:57:42.973