01 May
Exclude directory while making tar
tar command basically used on Linux to compress/uncompress any folder. Normally if we want to make a tar of whole folder then we can use follow steps
- open Linux shell or do ssh with root access
- go to directory which you want to compress
- run your tar command
Example
[root@www ~]# cd /home/myfolder/ [root@www myfolder]# tar -cvf my_tar_file_name.tar *
it will make a tar file with the name my_tar_file_name.tar which contain all files and folders in “myfolder” directory.
Now suppose your “myfolder” have list something like as below
test
test1
test_file.php
index.php
And you want to exclude test1 folder at the item on compression then you can do by following command
[root@www myfolder]# tar -cvf my_tar_file_name.tar * --exclude test1
 Note: Don’t use slash / , otherwise it will not exclude that folder
like below is wrong format
[root@www myfolder]# tar -cvf my_tar_file_name.tar * --exclude test1/
you can exclude multiple folder also, something like
[root@www myfolder]# tar -cvf my_tar_file_name.tar * --exclude test1 --exclude test
More example like:-
tar -pczf MyBackup.tar.gz /home/user/public_html/ --exclude "/home/user/public_html/tmp" tar --exclude='file1' --exclude='patter*' --exclude='file2'
For more help you can visit http://www.centos.org/docs/2/rhl-gsg-en-7.2/s1-zip-tar.html
I am a software engineer who specializes in Internet applications. I have worked with a wide variety of technologies and programming languages to open source LAMP environments. I have more than 6 years of object-oriented programming experience and am highly proficient in ActionScript, PHP, MYSQL, JavaScript, Jquery and a multitude of other technologies used in modern web applications.
Follow me
Latest posts by Rajeev Achra (see all)
- Jquery webcam plugin - June 19, 2016
- How To Add and Delete Users on a CentOSServer - June 5, 2016
- How To Set Up vsftpd on CentOS 6 - June 5, 2016