So You Downloaded a Thousand TikToks

- 7 mins read

We’ve all been there, a friend sends over a funny TikTok, or you want to share it in your Signal chat and you know people aren’t likely to click the link. Plus who wants all that tracking and hidden redirects in a TT link? So what’s to be done? If you’re like me, a quick long press, and “Save Video” and you’re off to the group chat to laugh with your friends.

And at first, just a few TikToks seem harmless. Then you wake up one day and your GMail is maxed out, your Google Photos aren’t syncing, and every Google Service is covered in a red check mark!

We could run through and delete every TikTok by hand, but that’d take hours. And we could possibly end up deleting another file by accident. Or worse, delete all the .mp4s off our phone and definitely spread the collateral damage around.

Instead, lets look at the standard TikTok file format and see if we can’t find a way to solve this.

The File Name

Every TikTok appears to be named using a 32 character hexadecimal hash. This allows us to hone in on the files that are on our system pretty quickly.

fc957545f9d8beb0dfbb51d37e840144.mp4

A quick regex should be able to fix us up.

If you’re not familiar with a regex, its a regular expression that helps us define rules for searching or input, without knowing exactly what the input will be.

Let’s look at the below regex.

[a-f0-9]{32}\.mp4

Given the above regex, we can start to make a guess at what’s happening.

[ tells the computer “I’m going to give you a search term, it’ll be in between these brackets”

a-z says “I’m looking for any lowercase letter including and between a-f”

0-9 is similar, “Look for any number including and between 0-9”

] closes out the search term

{32} If we have a good idea of how many characters meet our preceding pattern, we can identify that too. In this case, 32 hexadecimal characters.

\ This may be new to some people, but a \ character is often used as an “escape” character. Since the . is used in regex to signify Any Character we need to tell the computer we want a single . not “Any Character”. Escaping the . allows us to do this.

.mp4 and finally an exact expression. This tells the computer, you don’t have to search or look for any specific character, just find .mp4 as is.

Now that we have a way to nail down the files we want to find, lets do a search.

Unfortunately, the standard Android and Samsung UI’s don’t allow for regex searching, but every Linux enthusiasts favorite Android busybox implementation does!

To make this as easy as possible, we’ll be downloading Termux from the Google Play or F-Droid marketplaces.

Note: F-Droid is an open source, privacy and data security focused marketplace for the Android ecosystem. Highly recommend getting up-to-speed with F-Droid although its outside the scope of this article.

Termux allows us to run most Linux packages on Android and gain access to the storage without needing to “root” the device.

Once installed, make sure you’ve visited the App Permissions and granted access to the “Storage” option.

Additionally, you’ll want to run the termex-setup-storage command.
If done correctly, in your home directory, you’ll now have access to a storage folder mapped to your Android Internal Storage folders.

The TikTok files are usually saved to our camera roll with a similar path to storage/dcim/Camera.

We can validate this by long-pressing on a TikTok video in our gallery and looking at the details. If you have a different file path, we’ll need to find that instead.

Move to the correct file location using the cd command like so.

cd storage/dcim/Camera

From here, we’ll be able to search for the files we need. Remember that regex from above? We can make use of it here now.

ls | grep -E "[a-f0-9]{32}\.mp4"

 1$: ls | grep -E "[a-f0-9]{32}\.mp4"
 264d328eae362c905b262fc37173aba7d.mp4
 38f3a1c9e5b7d0246810f5e9a3c2d7b14.mp4
 4a9c7e5d3b1f06428395d7e1a2c4b6f83.mp4
 537f2e9c1d8b5a64027f3e9c1d8b5a640.mp4
 619f7e3d2c0b8a64537f1e9d2c0b8a645.mp4
 7f5e7d9c3b1a8642048e5c9a7b3d1f068.mp4
 82c4b6a8d0f1e3572c4b6a8d0f1e35791.mp4
 99a7b5c3d1e0f2486937b5c3d1e0f2486.mp4
10d1c3b5a7926480e5f1d3c5b7a9264805.mp4
1151e3f7d9b1c3a57842e1f7d9b1c3a578.mp4

Success! Now that we know what files we have, we can start to do something with them!

Note: Now would be a great time to spot check some of these file names and make sure that only TikToks are getting picked up, and your phone doesn’t name every video you take with a 32 character hexadecimal hash. Most Samsung implementations I’ve seen actually use YYYYMMDD_HHMMSS.mp4 or in human, 20250310_210922.mp4

The Deletion

Now we’ve got a good thing going. We can learned a little regex, we’ve installed Termux (which will lead to all kinds of fun future projects) and we’ve figured out how to use ls and grep to find the files we want. Now lets do a little magic.

In bash we have an awesome little trick called command substitution, coupled with inline loops, we can do some pretty neat things.

If you just want the TL;DR here’s the command:

for i in $(ls|grep -E "[a-f0-9]{32}\.mp4"); do rm $i && echo "Removed $i" | tee -a ~/TikTokDelete.txt; done

But let’s break it down.

for i in $( ) This allows the computer to iterate through a task, changing the target of the task for each item presented. In this case, the ()s will return the list of .mp4s we want to delete. So this line could be better understood as for each item on the list, do something.

; do This helps the computer know where the command substitution stops, and where the important work begins.

rm $i This uses a variable $i to tell the computer which file to remove. Remember, in the first line, we told the computer to do something for each item on the list. $i is how we tell it what item to do something to.

&& echo "Removed $i Double ampersands are a great bash trick for saying “If the first thing happens successfully, then do another thing. In this case, we want the echo command to tell us which file got deleted and if the deletion was successful. If the deletion failed for some reason, the echo statement wouldn’t happen, and the computer would jump to the next ;

| This is a pipe, which takes the output of the command to the left and does something with it. In this case, hands the “Removed $i” to the tee command.

tee -a ~/TikTokDelete.txt Tee is a special utility that allows us to both see the output of a file and write it to a file. This way, we’ll have a record of what files were deleted in case things go awry.

; done and finally, the end. This tells the computer we’re done, after sorting through all the files.

 1$: for i in $(ls | grep -E "[a-f0-9]{32}\.mp4"); do rm $i && echo "Removed $i" | tee -a ~/TikTokDelete.txt; done`
 2Removed 64d328eae362c905b262fc37173aba7d.mp4
 3Removed 8f3a1c9e5b7d0246810f5e9a3c2d7b14.mp4
 4Removed a9c7e5d3b1f06428395d7e1a2c4b6f83.mp4
 5Removed 37f2e9c1d8b5a64027f3e9c1d8b5a640.mp4
 6Removed 19f7e3d2c0b8a64537f1e9d2c0b8a645.mp4
 7Removed f5e7d9c3b1a8642048e5c9a7b3d1f068.mp4
 8Removed 2c4b6a8d0f1e3572c4b6a8d0f1e35791.mp4
 9Removed 9a7b5c3d1e0f2486937b5c3d1e0f2486.mp4
10Removed d1c3b5a7926480e5f1d3c5b7a9264805.mp4
11Removed 51e3f7d9b1c3a57842e1f7d9b1c3a578.mp4

Appendix

In order to complete this safely, you should have a working knowledge of the Linux command line and be comfortable with Android app permissions. The work you’re doing here is irreversible and Linux is not particularly forgiving.

If you want to practice running these commands before you try them on a live system, you can create a few files to work with using the following commands.

mkdir test
cd $_ 
touch 64d328eae362c905b262fc37173aba7d.mp4 8f3a1c9e5b7d0246810f5e9a3c2d7b14.mp4 a9c7e5d3b1f06428395d7e1a2c4b6f83.mp4 37f2e9c1d8b5a64027f3e9c1d8b5a640.mp4 19f7e3d2c0b8a64537f1e9d2c0b8a645.mp4 f5e7d9c3b1a8642048e5c9a7b3d1f068.mp4 2c4b6a8d0f1e3572c4b6a8d0f1e35791.mp4 9a7b5c3d1e0f2486937b5c3d1e0f2486.mp4 d1c3b5a7926480e5f1d3c5b7a9264805.mp4 51e3f7d9b1c3a57842e1f7d9b1c3a578.mp4

Run your tests in this folder, and then go back and run against your live files.

I’m an experienced home cook, security engineer, people leader, and dedicated father and husband. I can be found on Mastodon at @IAintShootinMis@DigitalDarkAge.cc and on Signal at DigitalDarkAge.98. An RSS Feed of this blog is available here and a copy of my current OPML file is here.