Android - Running TRIM from shell

WARNING: I have not tested this procedure.

You would need to have fstrim in system/bin. This XDA post has a DropBox download link.

start up adb and then switch users to root.

$ adb shell from your os terminal.

$ su to switch to the root user.

To copy fstrim to your /system/bin path you first need to mount the system path as Read/Write from adb or some other file manager

# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system to mount /system as R/W

Then copy fstrim to the system path.

# cp <pathtofstrim>/fstrim /system/bin

Next you need to change permissions of fstrim to include execute.

# chmod 766 /system/bin/fstrim to make fstrim executable by root

After setting the correct permissions on fstrim you can run these commands from adb (as root):

# fstrim -v /data
# fstrim -v /cache
# fstrim -v /system


OR, you could go the EASY WAY. Install the LagFix app, and trigger fstrim on demand, provided your device has fstrim support!


On newer versions, Android runs fstrim with a daily schedule, provided that the conditions meet. Or it should run on a reboot if not run for 3+ days. See this answer for details.

However if you want to do TRIM manually, use Android's commandline tool sm fstrim. Previously this was vdc fstrim dotrim but added to Storage Manager in Oreo (1) and removed from vold in Pie (2).

In order to send FITRIM ioctl to selected filesystem(s) only, use fstrim tool; a busybox applet.

Both commands require root, or sm fstrim can be executed from adb shell.