ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Location: Margaritaville (a state of mind west of Las Vegas), NV
Distribution: Linux Mint
Posts: 61
Rep:
Shell script to zip files from input file?
I'm trying to write a single line shell script to backup my browser profile using zip. I don't want to backup the whole thing (way too many cache files, and other non-essential stuff) - I just want the bare essentials. So I created a text file "profile_files" and populated it with all the file and directory names I want to backup. But several of these files and directories have spaces in the name. I tried wrapping each line in double quotes. That didn't work. I tried escaping the space with a preceding "" and when that didn't work I tried a back-tick instead of a back slash. No matter what I do, it skips over any file or subdirectory that has a space in the name.
It'll help to see the script, but pass the paths and file names using null as a terminator rather than the default of whitespace.
If you are using find then you can use -print0. If you are using xargs thenn see the --null option. Again, it would help to see the script. Please remember to use [code] [/code] tags around it.
Location: Margaritaville (a state of mind west of Las Vegas), NV
Distribution: Linux Mint
Posts: 61
Original Poster
Rep:
Problem solved.
This:
zip -r ChromeProfile.zip $(cat profile_files)
doesn't work
But this:
zip -r ChromeProfile -@ < profile_files
does.
Not sure why but I have a follow up question... when I create that zip file, it's creating the path within the zip file. I.e. when I open the zip file, all I see is a directory - "home". When I double click that, it takes me to [user name]. When I double click that, it takes me to ".config", etc. I'd much prefer, when I open the zip file, to just see the files and (recursed) subdirectories in /home/username/.config/google-chrome/Default
After the $ substitution the shell splits the result into words according to IFS (defaults to whitespace), and then (by default) attempts filename generation.
You can improve it with
Code:
IFS=; set -f; zip -r ChromeProfile.zip $(cat profile_file)
But it still can overflow with "two many arguments".
Reading the filenames from stdin or an input file is much better.
Do not create entries in the zip archive for directories. Directory entries are created by default so that their attributes can be saved in the zip archive.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.