Posts Tagged ‘bash’

Piping hot ball of Tar.

For those who have gotten into the idea of typing commands as little as possible, here’s out to pipe the output from tar straight into a gzip file.

tar cvf - myfile.jpg | gzip > myfile.tar.gz
tar cvf - folder | gzip > folder_backup.tar.gz

Take note of the second example and notice how folder does not contain the trailing forward slash. The forward slash denotes everything inside the folder while leaving it off copies the entire folder itself into the archive. This way causes the extraction process recreate the folder while to former will only extract the files within the folder.

I found the F (-mtime +3)!

forgetting is the bane of my existence. don’t ask why. i’ve forgotten this syntax enough times that i should have it tattooed on my upper arm. in fact, I think i’ve posted it on my own site before and forgotten about that.

find /path/to/files* -mtime +5 -exec rm {} \;

the first argument is, of course, the path to the files that you’re looking to rid yourself. The first flag, -mtime, tells find to look for files older than a certain number of days. the whole “+5″ would indicate five days from today (would -5 be five days in the future then? something to look up later). The second flag, -exec, will tell find to execute the following command when it gets a positive result. in this case, we’re “removing” (rm

i will say though that i should really read the man page a little better to get this straight. this particular command has yielded some strange results at times, and i’m at a loss as to why being that it’s SO straight forward. maybe i’ll just post the man page here for shits and giggles.

BASH: deleting files older than X number of days

find /path/to/folder -mtime +5 -exec rm -f {} \;

A handy utility to stick into the old brain. Thank you, internet, for providing me such a vast and available resource so that I know longer have to rely on my own faculty of memory.