How can I create a zip archive of a whole directory via terminal without hidden files?
up vote
195
down vote
favorite
I have a project with lots of hidden folders / files in it. I want to create a zip-archive of it, but in the archive shouldn't be any hidden folders / files. If files in a hidden folder are not hidden, they should also not be included.
I know that I can create a zip archive of a directory like this:
zip -r zipfile.zip directory
I also know that I can exclude files with the -x option, so I thought this might work:
zip -r zipfile.zip directory -x .*
It didn't work. All hidden directories were still in the zip-file.
command-line zip
add a comment |
up vote
195
down vote
favorite
I have a project with lots of hidden folders / files in it. I want to create a zip-archive of it, but in the archive shouldn't be any hidden folders / files. If files in a hidden folder are not hidden, they should also not be included.
I know that I can create a zip archive of a directory like this:
zip -r zipfile.zip directory
I also know that I can exclude files with the -x option, so I thought this might work:
zip -r zipfile.zip directory -x .*
It didn't work. All hidden directories were still in the zip-file.
command-line zip
add a comment |
up vote
195
down vote
favorite
up vote
195
down vote
favorite
I have a project with lots of hidden folders / files in it. I want to create a zip-archive of it, but in the archive shouldn't be any hidden folders / files. If files in a hidden folder are not hidden, they should also not be included.
I know that I can create a zip archive of a directory like this:
zip -r zipfile.zip directory
I also know that I can exclude files with the -x option, so I thought this might work:
zip -r zipfile.zip directory -x .*
It didn't work. All hidden directories were still in the zip-file.
command-line zip
I have a project with lots of hidden folders / files in it. I want to create a zip-archive of it, but in the archive shouldn't be any hidden folders / files. If files in a hidden folder are not hidden, they should also not be included.
I know that I can create a zip archive of a directory like this:
zip -r zipfile.zip directory
I also know that I can exclude files with the -x option, so I thought this might work:
zip -r zipfile.zip directory -x .*
It didn't work. All hidden directories were still in the zip-file.
command-line zip
command-line zip
asked Aug 27 '11 at 18:01
Martin Thoma
6,184154771
6,184154771
add a comment |
add a comment |
8 Answers
8
active
oldest
votes
up vote
99
down vote
accepted
This also excludes hidden files in unhidden directories:
find /full_path -path '*/.*' -prune -o -type f -print | zip ~/file.zip -@
1
Thanks for your answer. The command (find community-chess/ -path '*/.*' -prune -o -type f -print | zip ~/community-chess.zip -@
) is longer than expected, but it works fine. Subdirectories are also included, so +1 and an accepted answer :-)
– Martin Thoma
Aug 28 '11 at 9:17
add a comment |
up vote
79
down vote
First of all if you don't have installed zip install it first as follows:
sudo apt-get install zip
Then for simply creating a zip file:
zip -r compressed_filename.zip foldername
If you want to exclude hidden files:
find /folder_path -path '*/.*' -prune -o -type f -print | zip ~/compressed_filename.zip -@
Excluding Files from a Zip Archive
The basics of file exclusion when creating a zip archive are centered around the -x
flag, which is used to exclude files from the archive that match a specific name or pattern. At it’s most basic, it will look like this:
zip archive.zip files -x "ExcludeMe"
Meaning you could exclude a single file, say it’s named “Nothanks.jpg”
zip archive.zip images/ -x "Nothanks.jpg"
Let’s cover a few specific examples where this is useful.
Exclude .DS_Store Files from Zip Archives
This will prevent the typically invisible Mac metadata .DS_Store
files from being included in a zip archive, which are bundled in by default:
zip -r archivename.zip archivedirectory -x "*.DS_Store"
If the directory includes subdirectories however, you’ll want to use another variation of that command to exclude the the ds_store files from subdirectories as well:
zip -r archive.zip directory -x "*/.DS_Store"
Note: not all shells require the quotations for this command to work properly, but in the bash shell (the default for OS X) you will need to use the quotes for excluding with wildcards and patterns.
Exclude Specific File Types from a Zip Archive
With wildcards, you can also exclude all files of a certain type by focusing on the extension. For example, this command will zip an entire directory, minus any .jpg
files:
zip -r archive.zip directory -x "*.jpg"
That could be modified for any specific file extension or pattern matched in a file name.
Exclude the .git or .svn Directory from a Zip Archive
Zip a directory, minus .git
and it’s contents:
zip -r zipdir.zip directorytozip -x "*.git*"
Zip a folder, without including the .svn
directory:
zip -r zipped.zip directory -x "*.svn*"
Exclude All Hidden Files from a Zip Archive
Since patterns and wildcards can be used, you could also exclude any or all invisible files and folders that are made so by being prefixed with a period, whether it’s a directory like .svn
or an individual file like .bash_profile
or .htaccess
.
zip -r archivename.zip directorytozip -x "*.*"
Or to exclude all invisible files from all subdirectories:
zip -r archive.zip directory -x "*/.*"
5
Thank you for your effort to help a fellow Ubuntu user. Please keep in mind that re-stating the accepted answer in a new answer just adds to the clutter and has a high probability of being flagged for removal.
– hmayag
Aug 11 '15 at 7:04
add a comment |
up vote
52
down vote
Add "
to the .*
(otherwise, your shell expands .*
to the dot files in the current directory), and also exclude hidden files in subdirectories:
zip -r zipfile.zip . -x ".*" -x "*/.*"
This will result in files starting with a .
not to be added into your zip file.
rinzwind@discworld:~/tmp$ ls -la
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 tmp
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 .tmp
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x .*
adding: .tmp/ (stored 0%)
adding: tmp/ (stored 0%)
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x ".*" -x "*/.*"
updating: tmp/ (stored 0%)
1
I don't think your last statement is correct..*
would get expanded by the shell.
– hammar
Aug 27 '11 at 22:11
1
I think it is likely to be correct but I removed it (not sure about it) :)
– Rinzwind
Aug 27 '11 at 22:22
this didn't work. The .svn-directories were added
– Martin Thoma
Aug 28 '11 at 9:13
1
@moose The exclude pattern matches the full path, not just the file base name, so you need to exclude*/.*
as well as.*
(*/
matches any non-empty sequence of directories).
– Gilles
May 8 '14 at 17:21
This runs without changing anything! Best answer.
– Whitecat
Oct 7 '17 at 4:12
add a comment |
up vote
8
down vote
This one includes all "." directories, subdirectories, and "." files or directories within directories...
Essentially the first answer but includes top level "." files.
find /full_path -path '*.*/.*' -prune -o -type f -print | zip ~/file.zip -@
add a comment |
up vote
8
down vote
Example for excluding all folders begining with . :
tar cvpzf folder.tgz folder/ --exclude '.*'
Better compress but slower :
tar cvpjf folder.tar.bz2 folder/ --exclude '.*'
add a comment |
up vote
5
down vote
The correct method would be:
zip -r zipfile.zip directory -x directory/.*
@downvoter: What's wrong, this seems to be working for me.
– jobin
May 8 '14 at 16:55
Same problem as with Rinzwind's original answer (now corrected): you aren't excluding subdirectories. And as Rinzwind noted, you need to quote the wildcards, otherwise the shell will expand them.
– Gilles
May 8 '14 at 17:25
add a comment |
up vote
4
down vote
While zipping dirs excluding some file extension:
$ cd /path/to/dir
$ zip -r dir.zip . -x "*.log" -x "*.cache"
add a comment |
up vote
3
down vote
Without hidden folders and files in directory:
zip -r zipfile.zip directory/*
directory:
|── .git
│
├── src
│ └── Work.file
├── .test
│ └── .file
└── test.file
$ zip -r zipfile.zip directory/*
adding: directory/src/ (stored 0%)
adding: directory/src/Work.file (stored 0%)
adding: directory/test.file (stored 0%)
add a comment |
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
99
down vote
accepted
This also excludes hidden files in unhidden directories:
find /full_path -path '*/.*' -prune -o -type f -print | zip ~/file.zip -@
1
Thanks for your answer. The command (find community-chess/ -path '*/.*' -prune -o -type f -print | zip ~/community-chess.zip -@
) is longer than expected, but it works fine. Subdirectories are also included, so +1 and an accepted answer :-)
– Martin Thoma
Aug 28 '11 at 9:17
add a comment |
up vote
99
down vote
accepted
This also excludes hidden files in unhidden directories:
find /full_path -path '*/.*' -prune -o -type f -print | zip ~/file.zip -@
1
Thanks for your answer. The command (find community-chess/ -path '*/.*' -prune -o -type f -print | zip ~/community-chess.zip -@
) is longer than expected, but it works fine. Subdirectories are also included, so +1 and an accepted answer :-)
– Martin Thoma
Aug 28 '11 at 9:17
add a comment |
up vote
99
down vote
accepted
up vote
99
down vote
accepted
This also excludes hidden files in unhidden directories:
find /full_path -path '*/.*' -prune -o -type f -print | zip ~/file.zip -@
This also excludes hidden files in unhidden directories:
find /full_path -path '*/.*' -prune -o -type f -print | zip ~/file.zip -@
answered Aug 27 '11 at 19:27
arrange
11.5k23127
11.5k23127
1
Thanks for your answer. The command (find community-chess/ -path '*/.*' -prune -o -type f -print | zip ~/community-chess.zip -@
) is longer than expected, but it works fine. Subdirectories are also included, so +1 and an accepted answer :-)
– Martin Thoma
Aug 28 '11 at 9:17
add a comment |
1
Thanks for your answer. The command (find community-chess/ -path '*/.*' -prune -o -type f -print | zip ~/community-chess.zip -@
) is longer than expected, but it works fine. Subdirectories are also included, so +1 and an accepted answer :-)
– Martin Thoma
Aug 28 '11 at 9:17
1
1
Thanks for your answer. The command (
find community-chess/ -path '*/.*' -prune -o -type f -print | zip ~/community-chess.zip -@
) is longer than expected, but it works fine. Subdirectories are also included, so +1 and an accepted answer :-)– Martin Thoma
Aug 28 '11 at 9:17
Thanks for your answer. The command (
find community-chess/ -path '*/.*' -prune -o -type f -print | zip ~/community-chess.zip -@
) is longer than expected, but it works fine. Subdirectories are also included, so +1 and an accepted answer :-)– Martin Thoma
Aug 28 '11 at 9:17
add a comment |
up vote
79
down vote
First of all if you don't have installed zip install it first as follows:
sudo apt-get install zip
Then for simply creating a zip file:
zip -r compressed_filename.zip foldername
If you want to exclude hidden files:
find /folder_path -path '*/.*' -prune -o -type f -print | zip ~/compressed_filename.zip -@
Excluding Files from a Zip Archive
The basics of file exclusion when creating a zip archive are centered around the -x
flag, which is used to exclude files from the archive that match a specific name or pattern. At it’s most basic, it will look like this:
zip archive.zip files -x "ExcludeMe"
Meaning you could exclude a single file, say it’s named “Nothanks.jpg”
zip archive.zip images/ -x "Nothanks.jpg"
Let’s cover a few specific examples where this is useful.
Exclude .DS_Store Files from Zip Archives
This will prevent the typically invisible Mac metadata .DS_Store
files from being included in a zip archive, which are bundled in by default:
zip -r archivename.zip archivedirectory -x "*.DS_Store"
If the directory includes subdirectories however, you’ll want to use another variation of that command to exclude the the ds_store files from subdirectories as well:
zip -r archive.zip directory -x "*/.DS_Store"
Note: not all shells require the quotations for this command to work properly, but in the bash shell (the default for OS X) you will need to use the quotes for excluding with wildcards and patterns.
Exclude Specific File Types from a Zip Archive
With wildcards, you can also exclude all files of a certain type by focusing on the extension. For example, this command will zip an entire directory, minus any .jpg
files:
zip -r archive.zip directory -x "*.jpg"
That could be modified for any specific file extension or pattern matched in a file name.
Exclude the .git or .svn Directory from a Zip Archive
Zip a directory, minus .git
and it’s contents:
zip -r zipdir.zip directorytozip -x "*.git*"
Zip a folder, without including the .svn
directory:
zip -r zipped.zip directory -x "*.svn*"
Exclude All Hidden Files from a Zip Archive
Since patterns and wildcards can be used, you could also exclude any or all invisible files and folders that are made so by being prefixed with a period, whether it’s a directory like .svn
or an individual file like .bash_profile
or .htaccess
.
zip -r archivename.zip directorytozip -x "*.*"
Or to exclude all invisible files from all subdirectories:
zip -r archive.zip directory -x "*/.*"
5
Thank you for your effort to help a fellow Ubuntu user. Please keep in mind that re-stating the accepted answer in a new answer just adds to the clutter and has a high probability of being flagged for removal.
– hmayag
Aug 11 '15 at 7:04
add a comment |
up vote
79
down vote
First of all if you don't have installed zip install it first as follows:
sudo apt-get install zip
Then for simply creating a zip file:
zip -r compressed_filename.zip foldername
If you want to exclude hidden files:
find /folder_path -path '*/.*' -prune -o -type f -print | zip ~/compressed_filename.zip -@
Excluding Files from a Zip Archive
The basics of file exclusion when creating a zip archive are centered around the -x
flag, which is used to exclude files from the archive that match a specific name or pattern. At it’s most basic, it will look like this:
zip archive.zip files -x "ExcludeMe"
Meaning you could exclude a single file, say it’s named “Nothanks.jpg”
zip archive.zip images/ -x "Nothanks.jpg"
Let’s cover a few specific examples where this is useful.
Exclude .DS_Store Files from Zip Archives
This will prevent the typically invisible Mac metadata .DS_Store
files from being included in a zip archive, which are bundled in by default:
zip -r archivename.zip archivedirectory -x "*.DS_Store"
If the directory includes subdirectories however, you’ll want to use another variation of that command to exclude the the ds_store files from subdirectories as well:
zip -r archive.zip directory -x "*/.DS_Store"
Note: not all shells require the quotations for this command to work properly, but in the bash shell (the default for OS X) you will need to use the quotes for excluding with wildcards and patterns.
Exclude Specific File Types from a Zip Archive
With wildcards, you can also exclude all files of a certain type by focusing on the extension. For example, this command will zip an entire directory, minus any .jpg
files:
zip -r archive.zip directory -x "*.jpg"
That could be modified for any specific file extension or pattern matched in a file name.
Exclude the .git or .svn Directory from a Zip Archive
Zip a directory, minus .git
and it’s contents:
zip -r zipdir.zip directorytozip -x "*.git*"
Zip a folder, without including the .svn
directory:
zip -r zipped.zip directory -x "*.svn*"
Exclude All Hidden Files from a Zip Archive
Since patterns and wildcards can be used, you could also exclude any or all invisible files and folders that are made so by being prefixed with a period, whether it’s a directory like .svn
or an individual file like .bash_profile
or .htaccess
.
zip -r archivename.zip directorytozip -x "*.*"
Or to exclude all invisible files from all subdirectories:
zip -r archive.zip directory -x "*/.*"
5
Thank you for your effort to help a fellow Ubuntu user. Please keep in mind that re-stating the accepted answer in a new answer just adds to the clutter and has a high probability of being flagged for removal.
– hmayag
Aug 11 '15 at 7:04
add a comment |
up vote
79
down vote
up vote
79
down vote
First of all if you don't have installed zip install it first as follows:
sudo apt-get install zip
Then for simply creating a zip file:
zip -r compressed_filename.zip foldername
If you want to exclude hidden files:
find /folder_path -path '*/.*' -prune -o -type f -print | zip ~/compressed_filename.zip -@
Excluding Files from a Zip Archive
The basics of file exclusion when creating a zip archive are centered around the -x
flag, which is used to exclude files from the archive that match a specific name or pattern. At it’s most basic, it will look like this:
zip archive.zip files -x "ExcludeMe"
Meaning you could exclude a single file, say it’s named “Nothanks.jpg”
zip archive.zip images/ -x "Nothanks.jpg"
Let’s cover a few specific examples where this is useful.
Exclude .DS_Store Files from Zip Archives
This will prevent the typically invisible Mac metadata .DS_Store
files from being included in a zip archive, which are bundled in by default:
zip -r archivename.zip archivedirectory -x "*.DS_Store"
If the directory includes subdirectories however, you’ll want to use another variation of that command to exclude the the ds_store files from subdirectories as well:
zip -r archive.zip directory -x "*/.DS_Store"
Note: not all shells require the quotations for this command to work properly, but in the bash shell (the default for OS X) you will need to use the quotes for excluding with wildcards and patterns.
Exclude Specific File Types from a Zip Archive
With wildcards, you can also exclude all files of a certain type by focusing on the extension. For example, this command will zip an entire directory, minus any .jpg
files:
zip -r archive.zip directory -x "*.jpg"
That could be modified for any specific file extension or pattern matched in a file name.
Exclude the .git or .svn Directory from a Zip Archive
Zip a directory, minus .git
and it’s contents:
zip -r zipdir.zip directorytozip -x "*.git*"
Zip a folder, without including the .svn
directory:
zip -r zipped.zip directory -x "*.svn*"
Exclude All Hidden Files from a Zip Archive
Since patterns and wildcards can be used, you could also exclude any or all invisible files and folders that are made so by being prefixed with a period, whether it’s a directory like .svn
or an individual file like .bash_profile
or .htaccess
.
zip -r archivename.zip directorytozip -x "*.*"
Or to exclude all invisible files from all subdirectories:
zip -r archive.zip directory -x "*/.*"
First of all if you don't have installed zip install it first as follows:
sudo apt-get install zip
Then for simply creating a zip file:
zip -r compressed_filename.zip foldername
If you want to exclude hidden files:
find /folder_path -path '*/.*' -prune -o -type f -print | zip ~/compressed_filename.zip -@
Excluding Files from a Zip Archive
The basics of file exclusion when creating a zip archive are centered around the -x
flag, which is used to exclude files from the archive that match a specific name or pattern. At it’s most basic, it will look like this:
zip archive.zip files -x "ExcludeMe"
Meaning you could exclude a single file, say it’s named “Nothanks.jpg”
zip archive.zip images/ -x "Nothanks.jpg"
Let’s cover a few specific examples where this is useful.
Exclude .DS_Store Files from Zip Archives
This will prevent the typically invisible Mac metadata .DS_Store
files from being included in a zip archive, which are bundled in by default:
zip -r archivename.zip archivedirectory -x "*.DS_Store"
If the directory includes subdirectories however, you’ll want to use another variation of that command to exclude the the ds_store files from subdirectories as well:
zip -r archive.zip directory -x "*/.DS_Store"
Note: not all shells require the quotations for this command to work properly, but in the bash shell (the default for OS X) you will need to use the quotes for excluding with wildcards and patterns.
Exclude Specific File Types from a Zip Archive
With wildcards, you can also exclude all files of a certain type by focusing on the extension. For example, this command will zip an entire directory, minus any .jpg
files:
zip -r archive.zip directory -x "*.jpg"
That could be modified for any specific file extension or pattern matched in a file name.
Exclude the .git or .svn Directory from a Zip Archive
Zip a directory, minus .git
and it’s contents:
zip -r zipdir.zip directorytozip -x "*.git*"
Zip a folder, without including the .svn
directory:
zip -r zipped.zip directory -x "*.svn*"
Exclude All Hidden Files from a Zip Archive
Since patterns and wildcards can be used, you could also exclude any or all invisible files and folders that are made so by being prefixed with a period, whether it’s a directory like .svn
or an individual file like .bash_profile
or .htaccess
.
zip -r archivename.zip directorytozip -x "*.*"
Or to exclude all invisible files from all subdirectories:
zip -r archive.zip directory -x "*/.*"
edited Nov 3 at 5:36
answered Aug 11 '15 at 6:28
M.A.K. Ripon
1,440822
1,440822
5
Thank you for your effort to help a fellow Ubuntu user. Please keep in mind that re-stating the accepted answer in a new answer just adds to the clutter and has a high probability of being flagged for removal.
– hmayag
Aug 11 '15 at 7:04
add a comment |
5
Thank you for your effort to help a fellow Ubuntu user. Please keep in mind that re-stating the accepted answer in a new answer just adds to the clutter and has a high probability of being flagged for removal.
– hmayag
Aug 11 '15 at 7:04
5
5
Thank you for your effort to help a fellow Ubuntu user. Please keep in mind that re-stating the accepted answer in a new answer just adds to the clutter and has a high probability of being flagged for removal.
– hmayag
Aug 11 '15 at 7:04
Thank you for your effort to help a fellow Ubuntu user. Please keep in mind that re-stating the accepted answer in a new answer just adds to the clutter and has a high probability of being flagged for removal.
– hmayag
Aug 11 '15 at 7:04
add a comment |
up vote
52
down vote
Add "
to the .*
(otherwise, your shell expands .*
to the dot files in the current directory), and also exclude hidden files in subdirectories:
zip -r zipfile.zip . -x ".*" -x "*/.*"
This will result in files starting with a .
not to be added into your zip file.
rinzwind@discworld:~/tmp$ ls -la
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 tmp
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 .tmp
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x .*
adding: .tmp/ (stored 0%)
adding: tmp/ (stored 0%)
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x ".*" -x "*/.*"
updating: tmp/ (stored 0%)
1
I don't think your last statement is correct..*
would get expanded by the shell.
– hammar
Aug 27 '11 at 22:11
1
I think it is likely to be correct but I removed it (not sure about it) :)
– Rinzwind
Aug 27 '11 at 22:22
this didn't work. The .svn-directories were added
– Martin Thoma
Aug 28 '11 at 9:13
1
@moose The exclude pattern matches the full path, not just the file base name, so you need to exclude*/.*
as well as.*
(*/
matches any non-empty sequence of directories).
– Gilles
May 8 '14 at 17:21
This runs without changing anything! Best answer.
– Whitecat
Oct 7 '17 at 4:12
add a comment |
up vote
52
down vote
Add "
to the .*
(otherwise, your shell expands .*
to the dot files in the current directory), and also exclude hidden files in subdirectories:
zip -r zipfile.zip . -x ".*" -x "*/.*"
This will result in files starting with a .
not to be added into your zip file.
rinzwind@discworld:~/tmp$ ls -la
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 tmp
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 .tmp
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x .*
adding: .tmp/ (stored 0%)
adding: tmp/ (stored 0%)
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x ".*" -x "*/.*"
updating: tmp/ (stored 0%)
1
I don't think your last statement is correct..*
would get expanded by the shell.
– hammar
Aug 27 '11 at 22:11
1
I think it is likely to be correct but I removed it (not sure about it) :)
– Rinzwind
Aug 27 '11 at 22:22
this didn't work. The .svn-directories were added
– Martin Thoma
Aug 28 '11 at 9:13
1
@moose The exclude pattern matches the full path, not just the file base name, so you need to exclude*/.*
as well as.*
(*/
matches any non-empty sequence of directories).
– Gilles
May 8 '14 at 17:21
This runs without changing anything! Best answer.
– Whitecat
Oct 7 '17 at 4:12
add a comment |
up vote
52
down vote
up vote
52
down vote
Add "
to the .*
(otherwise, your shell expands .*
to the dot files in the current directory), and also exclude hidden files in subdirectories:
zip -r zipfile.zip . -x ".*" -x "*/.*"
This will result in files starting with a .
not to be added into your zip file.
rinzwind@discworld:~/tmp$ ls -la
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 tmp
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 .tmp
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x .*
adding: .tmp/ (stored 0%)
adding: tmp/ (stored 0%)
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x ".*" -x "*/.*"
updating: tmp/ (stored 0%)
Add "
to the .*
(otherwise, your shell expands .*
to the dot files in the current directory), and also exclude hidden files in subdirectories:
zip -r zipfile.zip . -x ".*" -x "*/.*"
This will result in files starting with a .
not to be added into your zip file.
rinzwind@discworld:~/tmp$ ls -la
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 tmp
drwxr-xr-x 2 rinzwind rinzwind 4096 2011-08-28 00:15 .tmp
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x .*
adding: .tmp/ (stored 0%)
adding: tmp/ (stored 0%)
rinzwind@discworld:~/tmp$ zip -r zipfile.zip . -x ".*" -x "*/.*"
updating: tmp/ (stored 0%)
edited May 8 '14 at 17:22
Gilles
44.1k1398138
44.1k1398138
answered Aug 27 '11 at 19:17
Rinzwind
201k26385517
201k26385517
1
I don't think your last statement is correct..*
would get expanded by the shell.
– hammar
Aug 27 '11 at 22:11
1
I think it is likely to be correct but I removed it (not sure about it) :)
– Rinzwind
Aug 27 '11 at 22:22
this didn't work. The .svn-directories were added
– Martin Thoma
Aug 28 '11 at 9:13
1
@moose The exclude pattern matches the full path, not just the file base name, so you need to exclude*/.*
as well as.*
(*/
matches any non-empty sequence of directories).
– Gilles
May 8 '14 at 17:21
This runs without changing anything! Best answer.
– Whitecat
Oct 7 '17 at 4:12
add a comment |
1
I don't think your last statement is correct..*
would get expanded by the shell.
– hammar
Aug 27 '11 at 22:11
1
I think it is likely to be correct but I removed it (not sure about it) :)
– Rinzwind
Aug 27 '11 at 22:22
this didn't work. The .svn-directories were added
– Martin Thoma
Aug 28 '11 at 9:13
1
@moose The exclude pattern matches the full path, not just the file base name, so you need to exclude*/.*
as well as.*
(*/
matches any non-empty sequence of directories).
– Gilles
May 8 '14 at 17:21
This runs without changing anything! Best answer.
– Whitecat
Oct 7 '17 at 4:12
1
1
I don't think your last statement is correct.
.*
would get expanded by the shell.– hammar
Aug 27 '11 at 22:11
I don't think your last statement is correct.
.*
would get expanded by the shell.– hammar
Aug 27 '11 at 22:11
1
1
I think it is likely to be correct but I removed it (not sure about it) :)
– Rinzwind
Aug 27 '11 at 22:22
I think it is likely to be correct but I removed it (not sure about it) :)
– Rinzwind
Aug 27 '11 at 22:22
this didn't work. The .svn-directories were added
– Martin Thoma
Aug 28 '11 at 9:13
this didn't work. The .svn-directories were added
– Martin Thoma
Aug 28 '11 at 9:13
1
1
@moose The exclude pattern matches the full path, not just the file base name, so you need to exclude
*/.*
as well as .*
(*/
matches any non-empty sequence of directories).– Gilles
May 8 '14 at 17:21
@moose The exclude pattern matches the full path, not just the file base name, so you need to exclude
*/.*
as well as .*
(*/
matches any non-empty sequence of directories).– Gilles
May 8 '14 at 17:21
This runs without changing anything! Best answer.
– Whitecat
Oct 7 '17 at 4:12
This runs without changing anything! Best answer.
– Whitecat
Oct 7 '17 at 4:12
add a comment |
up vote
8
down vote
This one includes all "." directories, subdirectories, and "." files or directories within directories...
Essentially the first answer but includes top level "." files.
find /full_path -path '*.*/.*' -prune -o -type f -print | zip ~/file.zip -@
add a comment |
up vote
8
down vote
This one includes all "." directories, subdirectories, and "." files or directories within directories...
Essentially the first answer but includes top level "." files.
find /full_path -path '*.*/.*' -prune -o -type f -print | zip ~/file.zip -@
add a comment |
up vote
8
down vote
up vote
8
down vote
This one includes all "." directories, subdirectories, and "." files or directories within directories...
Essentially the first answer but includes top level "." files.
find /full_path -path '*.*/.*' -prune -o -type f -print | zip ~/file.zip -@
This one includes all "." directories, subdirectories, and "." files or directories within directories...
Essentially the first answer but includes top level "." files.
find /full_path -path '*.*/.*' -prune -o -type f -print | zip ~/file.zip -@
answered Nov 1 '12 at 3:19
cosimnot
8111
8111
add a comment |
add a comment |
up vote
8
down vote
Example for excluding all folders begining with . :
tar cvpzf folder.tgz folder/ --exclude '.*'
Better compress but slower :
tar cvpjf folder.tar.bz2 folder/ --exclude '.*'
add a comment |
up vote
8
down vote
Example for excluding all folders begining with . :
tar cvpzf folder.tgz folder/ --exclude '.*'
Better compress but slower :
tar cvpjf folder.tar.bz2 folder/ --exclude '.*'
add a comment |
up vote
8
down vote
up vote
8
down vote
Example for excluding all folders begining with . :
tar cvpzf folder.tgz folder/ --exclude '.*'
Better compress but slower :
tar cvpjf folder.tar.bz2 folder/ --exclude '.*'
Example for excluding all folders begining with . :
tar cvpzf folder.tgz folder/ --exclude '.*'
Better compress but slower :
tar cvpjf folder.tar.bz2 folder/ --exclude '.*'
edited May 21 '14 at 17:34
AzkerM
7,69742044
7,69742044
answered May 21 '14 at 16:51
Tigrouzen
7913
7913
add a comment |
add a comment |
up vote
5
down vote
The correct method would be:
zip -r zipfile.zip directory -x directory/.*
@downvoter: What's wrong, this seems to be working for me.
– jobin
May 8 '14 at 16:55
Same problem as with Rinzwind's original answer (now corrected): you aren't excluding subdirectories. And as Rinzwind noted, you need to quote the wildcards, otherwise the shell will expand them.
– Gilles
May 8 '14 at 17:25
add a comment |
up vote
5
down vote
The correct method would be:
zip -r zipfile.zip directory -x directory/.*
@downvoter: What's wrong, this seems to be working for me.
– jobin
May 8 '14 at 16:55
Same problem as with Rinzwind's original answer (now corrected): you aren't excluding subdirectories. And as Rinzwind noted, you need to quote the wildcards, otherwise the shell will expand them.
– Gilles
May 8 '14 at 17:25
add a comment |
up vote
5
down vote
up vote
5
down vote
The correct method would be:
zip -r zipfile.zip directory -x directory/.*
The correct method would be:
zip -r zipfile.zip directory -x directory/.*
edited May 8 '14 at 16:54
jobin
19k1274108
19k1274108
answered May 8 '14 at 16:49
Rômulo Neves
6711
6711
@downvoter: What's wrong, this seems to be working for me.
– jobin
May 8 '14 at 16:55
Same problem as with Rinzwind's original answer (now corrected): you aren't excluding subdirectories. And as Rinzwind noted, you need to quote the wildcards, otherwise the shell will expand them.
– Gilles
May 8 '14 at 17:25
add a comment |
@downvoter: What's wrong, this seems to be working for me.
– jobin
May 8 '14 at 16:55
Same problem as with Rinzwind's original answer (now corrected): you aren't excluding subdirectories. And as Rinzwind noted, you need to quote the wildcards, otherwise the shell will expand them.
– Gilles
May 8 '14 at 17:25
@downvoter: What's wrong, this seems to be working for me.
– jobin
May 8 '14 at 16:55
@downvoter: What's wrong, this seems to be working for me.
– jobin
May 8 '14 at 16:55
Same problem as with Rinzwind's original answer (now corrected): you aren't excluding subdirectories. And as Rinzwind noted, you need to quote the wildcards, otherwise the shell will expand them.
– Gilles
May 8 '14 at 17:25
Same problem as with Rinzwind's original answer (now corrected): you aren't excluding subdirectories. And as Rinzwind noted, you need to quote the wildcards, otherwise the shell will expand them.
– Gilles
May 8 '14 at 17:25
add a comment |
up vote
4
down vote
While zipping dirs excluding some file extension:
$ cd /path/to/dir
$ zip -r dir.zip . -x "*.log" -x "*.cache"
add a comment |
up vote
4
down vote
While zipping dirs excluding some file extension:
$ cd /path/to/dir
$ zip -r dir.zip . -x "*.log" -x "*.cache"
add a comment |
up vote
4
down vote
up vote
4
down vote
While zipping dirs excluding some file extension:
$ cd /path/to/dir
$ zip -r dir.zip . -x "*.log" -x "*.cache"
While zipping dirs excluding some file extension:
$ cd /path/to/dir
$ zip -r dir.zip . -x "*.log" -x "*.cache"
answered Dec 8 '14 at 17:49
K-Gun
606712
606712
add a comment |
add a comment |
up vote
3
down vote
Without hidden folders and files in directory:
zip -r zipfile.zip directory/*
directory:
|── .git
│
├── src
│ └── Work.file
├── .test
│ └── .file
└── test.file
$ zip -r zipfile.zip directory/*
adding: directory/src/ (stored 0%)
adding: directory/src/Work.file (stored 0%)
adding: directory/test.file (stored 0%)
add a comment |
up vote
3
down vote
Without hidden folders and files in directory:
zip -r zipfile.zip directory/*
directory:
|── .git
│
├── src
│ └── Work.file
├── .test
│ └── .file
└── test.file
$ zip -r zipfile.zip directory/*
adding: directory/src/ (stored 0%)
adding: directory/src/Work.file (stored 0%)
adding: directory/test.file (stored 0%)
add a comment |
up vote
3
down vote
up vote
3
down vote
Without hidden folders and files in directory:
zip -r zipfile.zip directory/*
directory:
|── .git
│
├── src
│ └── Work.file
├── .test
│ └── .file
└── test.file
$ zip -r zipfile.zip directory/*
adding: directory/src/ (stored 0%)
adding: directory/src/Work.file (stored 0%)
adding: directory/test.file (stored 0%)
Without hidden folders and files in directory:
zip -r zipfile.zip directory/*
directory:
|── .git
│
├── src
│ └── Work.file
├── .test
│ └── .file
└── test.file
$ zip -r zipfile.zip directory/*
adding: directory/src/ (stored 0%)
adding: directory/src/Work.file (stored 0%)
adding: directory/test.file (stored 0%)
edited Feb 15 '17 at 9:00
answered Feb 15 '17 at 8:45
Umanshield
313
313
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f58889%2fhow-can-i-create-a-zip-archive-of-a-whole-directory-via-terminal-without-hidden%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown