Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-09-2011, 12:59 PM   #16
Nominal Animal
Senior Member
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946Reputation: 946

Originally Posted by giantanakim View Post
It split this up into three different zip files. -1 was 1.3G, -2 was 800MB, and -3 was 2.39GB.
Like michaelk said, audio files tend not to compress much.

The script does not group the files based on their compressed sizes, but on their uncompressed size. It will not split a file between two archives, nor will it reorder the files to get better distribution between archives. (Like I said, those options are possible, but result in a much more complex and often very much slower script.)

I suggest you try with a maximum size limit about 400M smaller.

Originally Posted by giantanakim View Post
Can I run this for another directory? For instance, if I put in ./ /home/foo/bar/recordings
You can. The zip files will be created in the current working directory. The zip contents will have a home folder, a foo folder inside that, then a bar folder, and a recordings folder inside that, and then you get the files and subfolders under the recordings folder and its subfolders.

If you want to create a zip file in /home/foo/bar/recordings, containing the files in that directory or its subdirectories, use
( cd /home/foo/bar/recordings ; /path/to/ . )
This way you only get the files and folders under recordings.

The parentheses tell your shell to use a subshell, and the cd will then change the working directory only for the subshell, not for the script or shell you run the above from. Effectively, the working directory is only changed for the script.
Originally Posted by giantanakim View Post
Can this script be modified so that once a file is added to the zip, the original can be moved to a different directory?
Of course. Look at the zip commands in the script. The "${FILES[@]}" will expand to the list of files contained in the zip archive.

Because the files may reside in subdirectories, a normal copy often does not work, since it will not create the intermediate directories. However, you can use tar. For example, if you insert the following line after each line containing a zip command in the script,
tar -cf - "${FILES[@]}" | tar -xf - -C where-to-move || exit $?
the files are copied to under where-to-move, keeping the same relative directory structure. You can add
rm -f "${FILES[@]}"
after that to remove files that were successfully zipped and copied.

Since the above will not remove empty directories, you can replace the last two lines of the script to remove (only) empty directories. It is safe: it will not remove a directory with files (or subdirectories with files), even if the files are "hidden" (not listed in a standard directory listing). The two lines would be changed to
) || exit $?
find "$@" -depth -type d -print0 | xargs -r0 rmdir &>/dev/null
exit 0
It is safe to change the end of the script, even if you did not do the other changes above. Then it would not move the files, just remove empty directories after zipping the files.


archive, zip

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux zip program's -d -tt option deletes all files from zip archive Arun Gupta Linux - Software 4 04-27-2011 08:06 PM
Shell Script how to remove absolute paths from zip archive hi_irf Linux - Newbie 1 10-03-2009 06:59 AM
browse zip archive louisJ Linux - Newbie 3 10-18-2008 04:47 AM
Script to Add files to a Zip archive with out unzipping it !! prashix Programming 12 10-23-2007 10:19 AM
What Are files? kajensen Linux - General 1 09-21-2003 05:00 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:21 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration