Showing posts with label unzip. Show all posts
Showing posts with label unzip. Show all posts

Tuesday, February 17, 2015

Extract Multiple Zip Files With Ark

Made with some of the graphics I downloaded and needed to extract.
The other day I needed some fresh backgrounds, clip art, and various vector graphics. I found a site named Vector Portal and downloaded close to 200 different vector graphic packs. Each graphic pack was zipped and contained some eps,svg, and ai files that needed to be extracted. I started the process of clicking each file and opening each individual graphics pack in ARK and after doing about 15 of them, I realized this was going to be an all day affair. Boring, not fun, and definitely not what I was planning on doing all day.

I tried highlighting all the files and opening them all at the same time in ARK but that didn't work. Then discovered that you can do a batch extract from the command line. It was really easy and what would of took all day was now accomplished in under 2 minutes. Here's what you do.

1) Create a directory for your compressed files, and move all the compressed files that you want to extract into that directory.

2) Open up a terminal program and go to the directory you created with all your compressed files. For me it was

cd graphics/vectors

3) Now we use ARK from the command line, and execute a batch extract like so.

ark -b -a *.zip

Here's what we did. ark runs the ark program -b tells ark to use the batch interface from the command line, -a creates a subfolder if ark detects it's not a single folder archive. Finally I used a wild card *.zip so ark extracts every file with the .zip extension in that directory. This command saved me a ton of time.

I should note two things. One, make sure you're in the right directory when you run this command or you risk extracting every zip file in your system. The other thing is this can take a little bit of time. In my case with close to 200 files it took about a minute and a half for the command to complete. Be patient, and let your computer do the work. 

If you want to learn more about using ARK from the command line just type man ark in your terminal for all the different options that are available for this powerful program.

Saturday, February 8, 2014

Using unzip in the command line for multiple zip files

One reason for using Linux and the command line in a terminal program is the amount of time you can save doing redundant tasks. One of my resolutions for 2014 was to start using the command line more, to save time and of course learn a few tricks.

Today I tried two new things I never did with the command line. The first one was a total fail, and I'll shamefully explain what I tried to accomplish. The other thing I did was a success and saved me about a half hour of work.

The first thing I tried was downloading a bunch of zip files from a website at the same time, or with one command. There were roughly 30 zip files I needed to download, and I was planning on using wget to download all the files while I worked on other things. I have no clue what went wrong, but no matter what I tried, I just couldn't get wget to get the zip files I needed. I think it had something to do with the websites php server and some security features set on the server end. I'll be trying this again because I know it can be done, I'm fairly sure I was doing it correct, I just had to tweak something. I'll try it on an easier project in the future. So that was the fail.

Now for the success. I downloaded the 30 zip files manually, and placed them all in a temp directory. Normally I use Ark in KDE and it works great but unzipping 30 files with Ark would of taken at least 20 to 30 minutes. Instead I used "unzip" from the command line and it took about 30 seconds!!! The files I'm unzipping are jpg image files, so the filename really isn't that important, as long as I don't overwrite the duplicates and lose them.

Not knowing what I was doing I made a dir called temp-test and copied all the files to the temp-test directory I created. Then for the sake of simplicity and not making this post overly complicated and confusing for anyone newer to this like me, I used unzip -B "*.zip" and unzip did the entire job in about 30 seconds. I now had every file unzipped and ready to use.

A couple things worth mentioning. You need the quotes around the "*.zip" so that the shell won't recognize it as a wild card. Without the quotes I got

caution: filename not matched:  filename.zip

I also needed to ad the -B modifier to add a ~ to the end of any duplicate filenames. This left me with 300 files with duplicate names, but I unzipped over 1000 files. So I got a little more than a third of my files in 30 seconds.

This is the command I used.

unzip -B "*.zip"

unzip is the command to unzip the file, -B is the modifier to make a backup of duplicate named files. So if you have multiple files named 03.jpg it will create a backup of 03.jpg~ 03.jpg~1 etc. etc. Finally the "*.zip" is the wild card to unzip every file with the .zip extension.

If you have no duplicate file names in your multiple zips that's great. I had some duplicate names, which left me with close to 300 backup files that I needed. I couldn't figure out how to fix this using the command line, but a quick fix using the Dolphin file manager, (I think this will work with any file manager though) was to move all the backup files into its own folder and then highlight them all, right click and select rename, this will pop up a window that will allow you to add a filename#. The hashtag will add a sequential number. So I named it dupe#.jpg which created dupe1.jpg dupe2.jpg up to 300. Luckily they were all jpg's, any name would work as long as I had the jpg extension, and this technique worked great.

I do a lot of image work so this worked perfectly for me. All in all, what took a few minutes with unzip and renaming the dupes in Dolphin would of took about 20 to 30 minutes using Ark. I'll be using this a lot for different work projects.