LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942

Quote:
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.

Quote:
Originally Posted by giantanakim View Post
Can I run this for another directory? For instance, if I put in ./nominalanimal.sh /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
Code:
( cd /home/foo/bar/recordings ; /path/to/nominalanimal.sh . )
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 nominalanimal.sh script.
Quote:
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,
Code:
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
Code:
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
Code:
) || 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.
 
  


Reply

Tags
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 07:06 PM
Shell Script how to remove absolute paths from zip archive hi_irf Linux - Newbie 1 10-03-2009 05:59 AM
browse zip archive louisJ Linux - Newbie 3 10-18-2008 03:47 AM
Script to Add files to a Zip archive with out unzipping it !! prashix Programming 12 10-23-2007 09:19 AM
What Are archive.zip files? kajensen Linux - General 1 09-21-2003 04:00 AM


All times are GMT -5. The time now is 03:05 PM.

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