Looking for a Bash script to delete files with bold filenames

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
Trapster
Posts: 228
Joined: Sat Aug 01, 2020 7:44 pm
Location: Texas
Has thanked: 2 times
Been thanked: 71 times

Looking for a Bash script to delete files with bold filenames

Post by Trapster »

I just unarchived a file and it threw about 1,000 files into my /root/Downloads directory.
Luckily, Rox will bold all files that are new. I had to hunt them down to delete them all.

Can a bash script find and delete files with bold filenames?

User avatar
Flash
Moderator
Posts: 1023
Joined: Tue Dec 03, 2019 3:13 pm
Location: Arizona, U.S.
Has thanked: 58 times
Been thanked: 138 times

Re: Looking for a Bash script to delete files with bold filenames

Post by Flash »

Clicking the "Last Modified" column in Rox might concentrate all the new files together, making it easy to select all of them and then delete them.

Chaos coordinator :?
User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Looking for a Bash script to delete files with bold filenames

Post by MochiMoppel »

Flash wrote: Tue Jul 16, 2024 5:27 pm

Clicking the "Last Modified" column in Rox might concentrate all the new files together, making it easy to select all of them and then delete them.

This would work only if all the copied files have the same "Last Modified" timestamp, which is very unlikely.
What would work is to sort the files by "Last Changed", in this case that's the time the files were copied. Even without a dedicated "Last Changed" column sorting can be done using the right click menu: Display > Sort by Date (ctime). The ctime is also used by ROX for its bold formatting. All files with a "Last Changed" time of less than 5 minutes ago are displayed in bold font.

If the files are concentrated in one folder it's easy. It becomes tricky when the unarchived files are copied all over the place, and things get worse when you discover the mistake days later. A script could help. Basically it could use the find command to find all files in the system with a particular Changed date, then delete them. It's not as trivial as it sounds, but possible.

User avatar
Flash
Moderator
Posts: 1023
Joined: Tue Dec 03, 2019 3:13 pm
Location: Arizona, U.S.
Has thanked: 58 times
Been thanked: 138 times

Re: Looking for a Bash script to delete files with bold filenames

Post by Flash »

Thanks for the clarification. :)

Rather than let the 'find' script delete the files, it might be prudent to instead have it move them to a directory where they could be inspected before deletion.

Chaos coordinator :?
Doggy
Posts: 30
Joined: Thu Dec 02, 2021 7:00 pm
Been thanked: 7 times

Re: Looking for a Bash script to delete files with bold filenames

Post by Doggy »

I recently had a similar situation where I unarchived a folder, and it felt like I was drowning in new files. Unfortunately, you can’t really target bold filenames with a bash script since that’s just how the file manager shows them. A good workaround is to look for files based on when they were created. For instance, you could use find /root/Downloads -type f -mtime -1 -exec rm {} + to find and delete files modified in the last day.

Post Reply

Return to “Programming”