create a zip file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting create a zip file
# 1  
Old 10-10-2012
create a zip file

Im fairly new to bash but I wanted to know about an idea I had to stream my file process these days. I modify .html, and .xml files and usually will take the files right click, create .zip, add files, rename, and cut the zip out of the folder and paste into another folder. I KNOW bash should be able to do this but Im still fairly new into HOW and WHAT is going on.

From reading around and searching here I get this idea:
Code:
#!/bin/bash

##Location of files
DIR="/mnt/windows/files"

##Location of files being zipped
PROCESS="/mnt/windows/running"

##completed zipped files
ZIPPED="mnt/windows/zipped"

##original location of files
ORIG="mnt/windows/originals"

cd "$DIR"

## Move files locally
cp -v $DIR/* $PROCESS
mv -v  $DIR/* $ORIG

## check directory being process
cd $PROCESS

for folder in $(ls "$PROCESS"); do
	echo 
	echo ===========================
	echo
	zip -x $PROCESS/$folder
	mv -v $PROCESS/$folder 
	 
done

suggestions, ideas, or direction would be great
# 2  
Old 10-10-2012
Code:
zip file.zip file

try something like this
# 3  
Old 10-10-2012
You can just zip the files and then remove them if the zip process was sucessful, Check out the following example:
Code:
#!/bin/bash
# Location of files to zip
DIR="/mnt/windows/files"

# Location where to create zip files
ZIPPED="/mnt/windows/zipped"


# Zip files
zip $ZIPPED/zipfile $DIR/*

# Remove files zipped
if [ $? -eq 0 ]; then
  rm $DIR/*
else
  echo "**Error occurred during zip..."
fi

# 4  
Old 10-10-2012
Quote:
Originally Posted by spacebar
You can just zip the files and then remove them if the zip process was sucessful, Check out the following example:
Code:
#!/bin/bash
# Location of files to zip
DIR="/mnt/windows/files"

# Location where to create zip files
ZIPPED="/mnt/windows/zipped"


# Zip files
zip $ZIPPED/zipfile $DIR/*

# Remove files zipped
if [ $? -eq 0 ]; then
  rm $DIR/*
else
  echo "**Error occurred during zip..."
fi

i cant even run that for some reason in ubuntu's terminal. I get all kinds of command not found errors.
# 5  
Old 10-10-2012
What command is not found, exactly? If you don't have zip, install it.
# 6  
Old 10-10-2012
I believe I have zip installed. I get a $'\r': command not found
# 7  
Old 10-10-2012
As Corona688 said, Try each line individually from command line and show us(i.e. post) all the output that goes to the screen.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Create zip file from root owned fstab

I want to zip up my fstab file for backup purposes. This does not work because of permission issues. cd /etc/ zip -u fstab.zip fstab Can I use this with zip? echo xxx | sudo -S or change fstab owner to me? (3 Replies)
Discussion started by: drew77
3 Replies

2. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

3. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

4. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

5. UNIX for Dummies Questions & Answers

Zip a file with .zip extension.

Hi, I need to zip a .dat file with .zip extension. I tried using the "zip" command. But shell says. "ksh: zip: not found" Currently I am using gunzip to zip and changing the extension ".gz" to ".zip" as follows. mv $file `echo $file | sed 's/\(.*\.\)gz/\1zip/'` But when I tried... (1 Reply)
Discussion started by: aeroticman
1 Replies

6. AIX

ZIP multiple files and also specify size of zip file

I have to zip many pdf files and the size of zip file must not exceed 200 MB. When size is more than 200 MB then multiple zip files needs to be created. How we can achieve this in UNIX? I have tried ZIP utility but it takes a lot of time when we add individual pdfs by looping through a... (1 Reply)
Discussion started by: tom007
1 Replies

7. Linux

How to create zip file without path?

Hello, I have generated a PHP script that creates files needed for EPUB file. I have a temp directory where these files are created into and then needs to be zipped. The directory structure is: mimetype content.opf index.html stylesheet.css toc.ncx META-INF META-INF/container.xml ... (4 Replies)
Discussion started by: spaze
4 Replies

8. Shell Programming and Scripting

To write a shell script which groups files with certain pattern, create a tar and zip

Hi Guru's, I have to write a shell script which groups file names based upon the certain matching string pattern, then creates the Tar file for that particular group of files and then zips the Tar file created for the respective group of files. For example, In the given directory these files... (3 Replies)
Discussion started by: rahu_sg
3 Replies

9. UNIX for Dummies Questions & Answers

Create zip without including directories

Hi guys, I'm trying to do the following: zip -r /tmp/foo.zip public/accounts/foo But the zip that's been made has the whole "public/accounts/foo" path. I want only the foo folder to be zipped. How can I do this? Thanks, Elías (2 Replies)
Discussion started by: elioncho
2 Replies

10. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies
Login or Register to Ask a Question