Can someone please explain me how to use “>” and “|” in linux commands and convert me these three lines into one line of code please?
mysqldump --user=*** --password=*** $db --single-transaction -R > ${db}-$(date +%m-%d-%y).sql
tar -cf ${db}-$(date +%m-%d-%y).sql.tar ${db}-$(date +%m-%d-%y).sql
gzip ${db}-$(date +%m-%d-%y).sql.tar
rm ${db}-$(date +%m-%d-%y).sql (after conversion I guess this line will be useless)
The GNU
tarprogram can itself do the compression normally done bygzip. You can use the-zflag to enable this. So thetarandgzipcould be combined into:Getting
tarto read from standard input for archiving is not a simple task but I would question its necessity in this particular case.The intent of
taris to be able to package up a multitude of files into a single archive file but, since it’s only one file you’re processing (the output stream frommysqldump), you don’t need totarit up, you can just pipe it straight intogzipitself:That’s because
gzipwill compress standard input to standard output if you don’t give it any file names.This removes the need for any (possibly very large) temporary files during the compression process.