Batch files in Android

Search This thread

Anderson2

Senior Member
Feb 25, 2012
1,042
90
I've searched Google but have not found a clear answer. I need an *example* of what a simple batch file would look like in Android.

For instance I would like to have a "batch file" to do the following:

1 Search root and its subfolders for files whose names include 'flurry'
2. Delete these files.

I currently use a file manager to do the above, but I would like to automate the process so I could just click on a shortcut to do it. I know how to do that in DOS or Windows but how do I do it in Android?

- What tool would I use to write and run such a "batch file"?
- Where would I learn the proper syntax for batch files in Android?

My devices are rooted and run 4.4.2
Thank you for help suitable for an Android newbie.
 

Aerowinder

Senior Member
Aug 11, 2012
3,322
1,329
I've searched Google but have not found a clear answer. I need an *example* of what a simple batch file would look like in Android.

For instance I would like to have a "batch file" to do the following:

1 Search root and its subfolders for files whose names include 'flurry'
2. Delete these files.

I currently use a file manager to do the above, but I would like to automate the process so I could just click on a shortcut to do it. I know how to do that in DOS or Windows but how do I do it in Android?

- What tool would I use to write and run such a "batch file"?
- Where would I learn the proper syntax for batch files in Android?

My devices are rooted and run 4.4.2
Thank you for help suitable for an Android newbie.

I thought about writing a batch file for cleaning my intsd of all the junk apps put there. But in the end, I decided to use Tasker instead because it's just easier to maintain. I find myself adding entries all the time, and Root Explorer's text editor is awful.

You can also implement logic that will only delete a folder if children folders are empty.

Easier to make, easier to maintain, no computer or barely usable text editor required.
 
Last edited:

danarama

Senior Member
Aug 22, 2010
31,277
18,811
Oxenhope, West Yorkshire, UK
A Batch file is a windows term. Windows "cmd" commands can be batched into a "script" called a "batch file". Meaning a batch file runs cmd commands in sequence as a batch.

Android is Linux kernel based so what you are looking for are 2 things following the same premise as windows.

1) "windows cmd command" becomes "Linux terminal command".

Once you have found the Linux terminal commands to do what you want, you then can look at...

2) "batch file" becomes "bash shell script".

I believe this information should give you the start you're looking for

Sent from my Nexus 5 using Tapatalk

---------- Post added at 03:02 PM ---------- Previous post was at 02:37 PM ----------

Searching root would take some time by the way.... why "root"

Sent from my Nexus 5 using Tapatalk
 

Anderson2

Senior Member
Feb 25, 2012
1,042
90
A Batch file is a windows term. Windows "cmd" commands can be batched into a "script" called a "batch file". Meaning a batch file runs cmd commands in sequence as a batch.

Android is Linux kernel based so what you are looking for are 2 things following the same premise as windows.

1) "windows cmd command" becomes "Linux terminal command".

Once you have found the Linux terminal commands to do what you want, you then can look at...

2) "batch file" becomes "bash shell script".

I believe this information should give you the start you're looking for

Sent from my Nexus 5 using Tapatalk

---------- Post added at 03:02 PM ---------- Previous post was at 02:37 PM ----------

Searching root would take some time by the way.... why "root"

Sent from my Nexus 5 using Tapatalk
Thank you. That's helpful.

I started with root because being an android newbie, I was not sure where the flurry files would be and didn't want to miss any. Once I got a handle on that I planned to modify the search path to avoid such a total search.

I'm still feeling my way around Android file structure.
 

Anderson2

Senior Member
Feb 25, 2012
1,042
90
I thought about writing a batch file for cleaning my intsd of all the junk apps put there. But in the end, I decided to use Tasker instead because it's just easier to maintain. I find myself adding entries all the time, and Root Explorer's text editor is awful.

You can also implement logic that will only delete a folder if children folders are empty.

Easier to make, easier to maintain, no computer or barely usable text editor required.

That is very helpful. Thank you.

Would you be willing to share your Tasker profiles? I purchased Tasker to support the developer but have not yet learned how to use it. Seems reasonably simple but I'm sure there's a learning curve to avoid unexpected errors. Seeing your profile as an example would give me a headstart.
 

danarama

Senior Member
Aug 22, 2010
31,277
18,811
Oxenhope, West Yorkshire, UK
Well tasker has the ability to run tasks such as script > shell - which will run multiple Linux terminal commands as a shell script in much the same way as a bash.sh bash shell script would...

Im not sure if that's what @Aerowinder is specifically referring to but I do this also.

Some script I use bash.sh that I run via tasker and other commands using tasks like this directly...

Sent from my Nexus 5 using Tapatalk
 

Aerowinder

Senior Member
Aug 11, 2012
3,322
1,329
I have some shell commands for FK tunables that I'm currently not using, but my cleanup profile is pretty basic.

Code:
Task: Temporary File Cleanup (18)
	A1: Delete Directory [ Dir:.torque Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A2: Delete Directory [ Dir:AI Factory Stats Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A3: Delete Directory [ Dir:crosswords Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A4: Delete Directory [ Dir:data/flixster Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A5: Delete Directory [ Dir:DCIM/.thumbnails Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A6: Delete Directory [ Dir:DCIM/100ANDRO Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A7: Delete Directory [ Dir:Download Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A8: Delete Directory [ Dir:franco.kernel_updater Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A9: Delete Directory [ Dir:LazyList Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A10: List Files [ Dir:Pictures/reddit_sync Match: Include Hidden Files:eek:ff Variable:%pics Continue Task After Error:eek:n ] 
	A11: If [ %pics1 ! Set ]
	A12: Delete Directory [ Dir:Pictures Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A13: End If 
	A14: Delete Directory [ Dir:SpeedSoftware Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A15: Delete Directory [ Dir:tapatalk4 Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A16: Delete Directory [ Dir:torqueLogs Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A17: Delete Directory [ Dir:TS3 Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A18: Delete Directory [ Dir:Turbo Client Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A19: Delete File [ File:.bugsense Shred Level:0 Use Root:eek:ff Continue Task After Error:eek:n ] 
	A20: Delete Directory [ Dir:Android/data/com.aws.android.elite Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A21: Delete Directory [ Dir:Android/data/com.google.android.apps.googlevoice Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A22: Delete Directory [ Dir:Android/data/com.google.android.gallery3d Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A23: Delete Directory [ Dir:Android/data/com.laurencedawson.reddit_sync.pro Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A24: Delete Directory [ Dir:Android/data/com.quoord.tapatalkHD Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A25: Delete Directory [ Dir:Android/data/com.speedsoftware.rootexplorer Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A26: Delete Directory [ Dir:Android/data/net.zedge.android Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A27: Delete Directory [ Dir:Android/data/_com.maxmpz.audioplayer Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A28: Delete Directory [ Dir:Android/data/com.dropbox.android Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A29: Delete Directory [ Dir:Android/data/com.google.android.apps.maps Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A30: Delete Directory [ Dir:Android/data/com.google.android.googlequicksearchbox Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A31: Delete Directory [ Dir:Android/data/com.google.android.youtube Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A32: Delete Directory [ Dir:Android/data/com.lsdroid.cerberus Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A33: Delete Directory [ Dir:Android/data/com.android.chrome Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ] 
	A34: Delete Directory [ Dir:Android/data/com.android.gallery3d Recurse:eek:n Use Root:eek:ff Continue Task After Error:eek:n ]

That smiley bug is really annoying.
 

danarama

Senior Member
Aug 22, 2010
31,277
18,811
Oxenhope, West Yorkshire, UK
Ah ok. I've found it. It sends anonymous usage statistics and bug reports to the developer. It looks like it will only ever be in /data/data or /data/user if my phone is anything to go on

Sent from my Nexus 5 using Tapatalk
 

Anderson2

Senior Member
Feb 25, 2012
1,042
90
Android runs sandboxed. Apps cant install themselves without user input. Which means they must be included in apps on the play store. Please name some example apps that do this.

Sent from my Nexus 5 using Tapatalk

They are from apps installed from Google play. I'm still new at this and therefore hesitate to name names.

Install logging checker by trevE and you'll find them too.
https://play.google.com/store/apps/details?id=com.treve.loggingkey
 

Anderson2

Senior Member
Feb 25, 2012
1,042
90
Ah ok. I've found it. It sends anonymous usage statistics and bug reports to the developer. It looks like it will only ever be in /data/data or /data/user if my phone is anything to go on

Sent from my Nexus 5 using Tapatalk

Thank you. Maybe I'm paranoid about privacy but I don't like any app sending stuff out without asking me first.
 

danarama

Senior Member
Aug 22, 2010
31,277
18,811
Oxenhope, West Yorkshire, UK
Thank you. Maybe I'm paranoid about privacy but I don't like any app sending stuff out without asking me first.

To each their own. Personally for me I don't mind. I expect usage statistics to be helpful for developers to bring us better products in the future. It is anonymous too, but it's your prerogative if you would rather it didn't.

I don't know how apps will act without the flurryagent by the way. It may cause force closes at some times... It may not. But a script should be pretty easy now we've narrowed it down to 2 directories.
 

Anderson2

Senior Member
Feb 25, 2012
1,042
90
Thanks rootSu. I don't know enough to be sure they are anonymous or will remain so. If developers want bug reports they can ask the users to send them openly.
I've been deleting them with no ill effects

Would you be willing to write the script till I learn how?
 

danarama

Senior Member
Aug 22, 2010
31,277
18,811
Oxenhope, West Yorkshire, UK
Would you be willing to write the script till I learn how?


Sure, no problem.

I took the Tasker approach since you said you owned it. This is best as you can run it on schedules etc.

So in Tasker create a Task....

New Task > Script > Run Shell

ensure you check / tick / select the "use root" option.

The command field must contain the below:

Code:
find /data/data -iname "*flurry*" -exec rm -rf {} \; && find /data/user -iname "*flurry*" -exec rm -rf {} \;

This will find and delete any file OR directory with "flurry"" in the title. It will search directories recursively too.

Actually, it runs pretty quickly to be fair, so you could even just:

Code:
find /data/ -iname "*flurry*" -exec rm -rf {} \;

..which will cover /sdcard too.

Tested and working, but keeping the previous method with the 2 commands in the post for your learning :)

Edit > I created 2 tasker profiles to run on new package and package updated, however I cannot figure out where the export option has been moved to,
 
Last edited:

Anderson2

Senior Member
Feb 25, 2012
1,042
90
Thank you so much rootSU. This gives me a good start and an example to work from. Not having used Linux or Tasker it was intimidating to start completely from scratch.

Tasker seems superb and I will spend time learning how to use it.
 

danarama

Senior Member
Aug 22, 2010
31,277
18,811
Oxenhope, West Yorkshire, UK
Thank you so much rootSU. This gives me a good start and an example to work from. Not having used Linux or Tasker it was intimidating to start completely from scratch.

Tasker seems superb and I will spend time learning how to use it.

Yes it's great. I run a few scripts using Tasker, including taking nandroid backups and flashing multiple zips. I love it.

Edit> Important thing to note in my command... Linux is case sensitive. I used -iname to do a case insensitive in this instance. You would normally use -name but then in this case, you'd need to run the command for "flurry" and "Flurry" etc.