Archiving file commands in Linux using tar

Archiving file commands in Linux using tar

Last Blog Review

In the last blog we understood, the basics of archiving what it does and how archiving is done in Linux using Tar command. Tar command syntax and it’s option which is used to modify the tar command. Later on in coming blogs we will see the use of tar command to archiving files and directories and extracting it.

Linux commands for Archiving files

  1. To create tar archive file

     tar -cvf my_archive.tar /home/user/project
    
  2. To extract the archive file on desired location

     tar -xvf my_archive.tar -C /home/user/logs
    
  3. To extract the archive file on default location

     tar -xvf my_archive.tar
    
  4. To create a tar archive file with compress in size using gzip

     tar -czvf my_archive.tar.gz /home/user/project
    
  5. To extract a compress archive file in gzip

     tar -xzvf my_archive.tar.gz
    
  6. To create a tar archive file with compress in size using bz2

     tar -cjvf my_archive.tar.bz2 /home/user/my_folders
    
  7. To extract a compress archive file in bz2

     tar -xjvf my_archive.tar.bz2
    
  8. To show the file size in human readable format

     du -sh /home/user/my_projects
    
  9. To create a compress archive file in xz

     tar -cJvf my_archive.tar.xz /home/user/my_folders
    
  10. To extract a compress archive file in xz

    tar -xJvf my_archive.tar.xz
    

Conclusion →

In the blog we understood the commands to archive a file using tar in Linux along with different compression techniques.

💡
That’s a wrap for today’s post! I hope this has given you some valuable insights. Be sure to explore more articles on our blog for further tips and advice. See you in the next post!