Blog by Daniel Hauck. Sysadmin, Developer, Blogger.

WTF: /bin/rm: Argument list too long

Imagine you got a directory, with millions of files in it. If you ever had the error message “/bin/rm: Argument list too long”,
you’ll know what I mean.

Here’s a workaround with find.

For example you wanted to delete all pdf files in the directory, here is how to do with find:

find -mindepth 1 -maxdepth 1 -type f -name '*.pdf' -delete

Let’s split the command:

find --> sure, the name of the command
-mindepth 1 --> find will search at least 1 level in depth
-maxdepth 1 --> find will search maximum 1 level in depth
-type f --> search only for files(see man find for other types)
-name '*.pdf' --> search for files ending with .pdf(use -iname for case insensitive search --> damn slow)
-delete --> deletes all matching files

With find you have the full control, and no need to be afraid, that you accidentally delete more files.

Have Fun!

Quick and dirty MySQL Backup

When you just need a simple backup of all your databases, this three lines do the job for you.

Just save it to a file and run it as a cron every night
00 01 * * * /srv/scripts/mysql_backup
and you get a zipped dump of every database with a timestamp.

It is easy extendable, if you want to exclude a database just write it into the grep regex
grep -Ev "(information_schema|performance_schema|another_database)"

Have fun! 🙂