LFCS: How to Archive/Compress Files & Directories, Setting File Attributes and Finding Files in Linux – Part 3

Best Affordable Linux and WordPress Services For Your Business
Outsource Your Linux and WordPress Project and Get it Promptly Completed Remotely and Delivered Online.

If You Appreciate What We Do Here On TecMint, You Should Consider:

  1. Stay Connected to: Twitter | Facebook | Google Plus
  2. Subscribe to our email updates: Sign Up Now
  3. Get your own self-hosted blog with a Free Domain at ($3.45/month).
  4. Become a Supporter - Make a contribution via PayPal
  5. Support us by purchasing our premium books in PDF format.
  6. Support us by taking our online Linux courses

We are thankful for your never ending support.

Gabriel Cánepa

Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

10 Responses

  1. CHIADI says:

    Hi Gabriel,

    Thanks for the nice write-ups. I am new to Linux and scripting, could you help explain this your line of code for a newbie:

    tar X <(for i in $DIR/*; do file $i | grep -i mpeg; if [ $? -eq 0 ]; then echo $i; fi;done) -cjf backupfile.tar.bz2 $DIR/*
    Or could you re-write it in an expanded form?

    Thanks in anticipation.

    • Ravi Saive says:


      Gabriel already provided explanation of that command, see:

      # Pass the directory to backup as first argument.
      # Create the tarball and compress it. Exclude files with the MPEG string in its file type.
      # -If the file type contains the string mpeg, $? (the exit status of the most recently executed command) expands to 0, 
      and the filename is redirected to the exclude option. Otherwise, it expands to 1.
      # -If $? equals 0, add the file to the list of files to be backed up.
      tar X < (for i in $DIR/*; do file $i | grep -i mpeg; if [ $? -eq 0 ]; then echo $i; fi;done) -cjf backupfile.tar.bz2 $DIR/*
      • Chiadi says:


        Thanks a lot for your time and further explanation.

        I understood him, the issue arise because I copied, pasted and ran the script but it gave me some errors.

        On examination, I found out the file was not pasted in its original format. I formatted it and it was fine.

        Thanks once more for your time; ravi means thrilled in French and I am thrilled.

  2. Agil says:

    Dear Gabriel Canepa
    Thank you for excelent material about LFCS exam. Just I would like to know. In your article you wrote that the compressed folder cannot be updated. I would like to know how about tar -rvf ?

    • @Agil,
      Thank you for your question. Note that you can use tar -rvf to append files to an existing TAR file (.tar) but NOT to a compressed file (.tar.gz). If you try to add a file named foo to mycompressedfile.tar.gz as follows:
      tar -rvf mycompressedfile.tar.gz foo
      You’ll get the following error:
      tar: Cannot update compressed archives
      tar: Error is not recoverable: exiting now
      Hope it helps!

  3. Erik Navarrete says:

    Hi Gabriel, thanks for this great course. I want to take the LFCS exam next Friday, Could you help me with some advices?. LFCS is more about your practice skills but I need to know by heart all commands?.

    • Gabriel A. Cánepa says:

      I am glad that you have found this series useful.
      The Linux Foundation just published a QA page about the certification programs http://t.co/1Oa9MwYpaQ. I would advice you to check it out.
      In addition, you should practice amd polish your command line skills until you feel comfortable. You can use different tools during the exam as long as they are in the Allowed list in the QA page mentioned above. So you can choose to perform a certain task using the resources you feel more comfortable with.
      Finally, you may want to check The Linux Command Line from linuxcommand.org.
      Hope it helps and good luck in the exam!

  4. Juan Ignacio says:

    Hi Gabriel , I am studying with this excellent material for examination LFCS surrender next Thursday .
    Congratulations and thank you very much for sharing your knowledge with which we are beginning our way in Linux.
    Greetings from Buenos Aires, viva la patria !


    • @Juan Ignacio,
      Thank you for your kind words about the LFCS series! Please note that I am currently writing another series covering the contents of the LFCE. You’re more than welcome to take a look!
      And best of luck with the exam next Thursday!
      Abrazo de gol.

  5. Khoi D. Dinh says:

    Thank you.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.