Suppose the structure:
/foo/bar/
--file1
--file2
--file3
--folder1
--file4
--folder2
--file5
I want to run the unix zip utility, compressing the bar
folder and all of it's files and subfolders, from foo
folder, but not have the bar
folder inside the zip, using only command line.
If I try to use the -j
argument, it doesn't create the bar folder inside the zip as I want, but doesn't create folder1
and folder2
. Doing -rj
doesn't work.
(I know I can enter inside bar and do zip -r bar.zip .
I want to know if it's possible to accomplish what $/foo/bar/ zip -r bar.zip .
but doing it from $/foo).
You can also create a ZIP file without creating a new folder. Simply select all of the files, open the context menu with a right-click, and click directly on “Send to” and “Compressed (zipped) folder”.
Locate the file or folder that you want to zip. Press and hold (or right-click) the file or folder, select (or point to) Send to, and then select Compressed (zipped) folder. A new zipped folder with the same name is created in the same location.
Syntax : $zip –m filename.zip file.txt 4. -r Option: To zip a directory recursively, use the -r option with the zip command and it will recursively zips the files in a directory. This option helps you to zip all the files present in the specified directory.
You can use -j . -j --junk-paths Store just the name of a saved file (junk the path), and do not store directory names. By default, zip will store the full path (relative to the current directory).
You have to do cd /foo/bar
then zip -r bar.zip .
, however, you can group them with parentheses to run in a subshell:
# instead of: cd /foo/bar; zip -r bar.zip; cd -
( cd /foo/bar; zip -r bar.zip . )
The enclosed (paren-grouped) commands are run in a subshell and cd within it won't affect the outer shell session.
See sh manual.
Compound Commands
A compound command is one of the following:
(list) list is executed in a subshell environment (see COMMAND EXECUTION ENVIRONMENT below).
Variable assignments and builtin commands that affect the shell's environment do not remain in effect after the command completes.
The return status is the exit status of list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With