How To Zip A File In Linux And Exclude Directory Files
- Forums
- Linux
- How To Zip A File In Linux And Exclude Directory Files
i have a windows xp laptop and i want to be able to download an important backup, but i can't open the tar files, so i want to create a zip file, but there is a directory which i dont need to zip, so i want to exclude it so when the zip command runs, i ig [3340], Last Updated: Mon Jun 24, 2024
Lesli
Wed Oct 03, 2012
1 Comments
873 Visits
thanks for your tutorial on how to compress a whole directory with the tar command in linux.
i have a windows xp laptop and i want to be able to download an important backup, but i can't open the tar files, so i want to create a zip file, but there is a directory which i dont need to zip, so i want to exclude it so when the zip command runs, i ignores that particular folder. how do i do it?
../backup
./include
./exclude
to run the command to only include the 'include' the files in the 'include' directory and not put the 'exclude' directory in your zip file, you can run this command to create a file called MyBackups.zip from the
another example:
zip -r MyBackups.zip PathToDirectory/* -x PathToDirectory/.gif\* directoryrname/private\* PathToDirectory/exclude.html
as you can, these command help in excluding files and folders which you dont want to include in your zip command
also, if you need more help you can run the man zip command and you should get more information like this:
Explicitly exclude the specified files, as in:
zip -r foo foo -x *.o
which will include the contents of foo in foo.zip while excluding all the
files that end in .o. The backslash avoids the shell filename substitution,
so that the name matching is performed by zip at all directory levels. If
you do not escape wildcards in patterns it may seem to work but files in
subdirectories will not be checked for matches.
Also possible:
zip -r foo foo [email protected]
which will include the contents of foo in foo.zip while excluding all the
files that match the patterns in the file exclude.lst (each file pattern on
a separate line).