Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zip stating absolute paths, but only keeping part of them

Tags:

linux

zip

zip -r 1.zip /home/username/the_folder

At here, when i unzip 1.zip, it will create /home/username/the_folder, from whichever folder i am unzipping from.

How do I zip, stating the full absolute paths, but make the zip only contain the folder structure starting at, in this case for instance, /home/username?

That way I could be at whatever path i wanted, unzip and it would just create the_folder, and not /home/username/the_folder.

like image 497
john-jones Avatar asked Jun 28 '12 17:06

john-jones


People also ask

How do you specify an absolute path?

An absolute path is defined as the specifying the location of a file or directory from the root directory(/). In other words we can say absolute path is a complete path from start of actual filesystem from / directory.

How do I zip an entire folder?

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.

How do you tell if a path is an absolute path?

A path is either relative or absolute. An absolute path always contains the root element and the complete directory list required to locate the file. For example, /home/sally/statusReport is an absolute path. All of the information needed to locate the file is contained in the path string.

How do you convert an absolute path to a relative path?

The absolutePath function works by beginning at the starting folder and moving up one level for each "../" in the relative path. Then it concatenates the changed starting folder with the relative path to produce the equivalent absolute path.


1 Answers

Just use the -j option, works on OSX, I don't know about linux.

zip -j -r 1.zip /home/username/the_folder

like image 194
jackjr300 Avatar answered Nov 16 '22 03:11

jackjr300