how to add a file to a zip, without including the entire path from root
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how to add a file to a zip, without including the entire path from root
Hi All,
the following command works:
zip /var/www/html/ftp/zipdownloads/zipfile.zip /var/www/html/path/to/file1.png
But when I open the zip file on my desktop, the entire file's path-structure is saved inside the zip file so i have to go through 5 directories (var -> www -> html -> path -> to) to get to the file I zipped.
Is there a way to avoid this and have the file in the "root" of the zipfile?
-j 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 path).
Thanks for the hint, colucix. This got me where I wanted on files, but now I need to expand this to also include entire directories in the zipfile. I need the path info from the working directory, but no further up the tree.
I'll try to "cd" my way into the directory that serves as base directory and then call the path from there without the absolute path.
If anything new comes up, you'll be hearing from me.
another annoyance is that, for security reasons, all files are set to permissions 040, so I need to set them to 440 before zip can even read them. With a single file, this wasn't a problem, but with an entire directory I think I'll be needing a recursive function...
Forgot to mention, I'm using PHP to execute these commands with exec(), but I guess that's not a real problem.
To zip an entire directory preserving its relative structure, just use the -r (recursion) option:
Code:
zip -r name_of_archive.zip path/to/dir/to/archive
To change permission recursively, use the -R option of chmod:
Code:
chmod -R 440 path/to/dir/to/archive
Regarding the PHP part of your question, unfortunately I have not experienced with this language, so I cannot be of much help. But I guess you have a kind of system function to execute commands on the native OS.
Regarding the PHP part of your question, unfortunately I have not experienced with this language, so I cannot be of much help. But I guess you have a kind of system function to execute commands on the native OS.
Indeed; you can call a native linux command using the php function exec() like this:
the great advantage is that you can use PHP to manipulate your file-system through a web-page. I'm now writing a web-based FTP program in PHP, so since a lot of file handling is done, I use the exec() function regularly.
If you like to write code, PHP's a great language to learn.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.