LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I zip all the files in a directory? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-zip-all-the-files-in-a-directory-558750/)

Russ S. 06-03-2007 01:08 AM

How can I zip all the files in a directory?
 
I have a bunch of files in a single directory, that I need to have a .zip extension, not .gz, how can I do this without zipping each file individually?

jschiwal 06-03-2007 02:07 AM

If there aren't any subdirectories, you could use
for file in *; do
zip "${file}.zip" "${file}"
done

If there are directories or special files (like sockets or links) you can use find to just handle regular files in the current directory:
find ./ -maxdepth 1 -type f -exec zip '{}'.zip '{}' \;

Russ S. 06-03-2007 02:28 AM

Many thanks! I would have never figured that out lol.

jay73 06-03-2007 02:52 AM

gz extensions are supported by most MS/commercial (un)zippers as well; it shouldn't make much of a difference whether you use zip or gzip. Only bzip2 has more limited support.


All times are GMT -5. The time now is 02:18 AM.