how to remove absolute paths from zip archive

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to remove absolute paths from zip archive
# 1  
Old 10-03-2009
how to remove absolute paths from zip archive


I need to write an bash script which works like it can copy files from remote machine through ssh to the server where script is running in zip format with the structure i want. I don't want to get absolute path in zip archive. Please let me know how it can be possible.

ssh source-ip-address zip /home/dir1/test.txt /home/dir1/test/test2.txt

# /home/dir1/test2/txt is the source.

unzip -l > list.txt

`cat list.txt`

# list.txt contains /home/dir1/test.txt /home/dir1/test/test2.txt

By default zip store absolute paths. While i don't want to store /home/dir1 & /home/dir2/ in zip archive. I need zip file in following format.


I know it is possible if i can change working directory when creating zip but as i am creating zip through remote machine, don't know how to change working directory. like it doesn't works

ssh source-ip-address cd /home/dir1
ssh source-ip-address zip test.txt test/test2.txt

Or is there anyway that i can zip the files from root path means not to include common path in archive i.e. /home/dir1

# 2  
Old 10-03-2009
you can issue commands on one line delimited by semi-colon

ssh source-ip-address cd /home/dir1;zip test.txt test/test2.txt

if you can, perhaps use 'tar', with the -C and z options, instead of zip

ssh source-ip-address tar -cvzf backup.tar.gz -C /home/dir1 test*

Last edited by varontron; 10-03-2009 at 10:39 AM..
# 3  
Old 10-06-2009

Thanks for your reply. Unfortunately the command you gave me didn't worked for me. Let me explain you

Source Machine From Where I need to archive files:

cd /home/user/files

ls -la


Following Command run on Destination Machine:

ssh source-ip cd /home/user/files; zip dir/test.txt dir1/dir2/test2.txt
stdin: is not a tty
zip warning: name not matched: /app/test.txt
zip warning: name not matched: /modules/admin/test2.txt

zip error: Nothing to do! (

The above command i ran where i want to get zip file and where my script runs.

Please help me out to sort this issue. Also i need to get archive in zip format not in tar.


---------- Post updated at 08:44 PM ---------- Previous update was at 08:24 PM ----------

Well, Infact it working for only 1st file and gives errors on others. Like,

ON Source Machine:

cd /home/user/files/

ls -la app/test.txt
ls -la dir/dir2/test2.txt

both files are exist on source

but on remote machine where script exist it says

ON Remote Machine:

ssh source-ip cd /home/user/files/; zip app/test.txt dir/dir2/test2.txt

It gives me following error.

stdin: is not a tty
zip warning: name not matched: stdin: is not a tty
zip warning: name not matched: dir/dir2/test2.txt
adding: app/test.txt (stored 0%)

So, zip archive contains only first file i.e. test.txt. Can you please help me out to get rid of this situation.

# 4  
Old 10-06-2009
try putting the whole command string in quotes:
ssh source-ip-address "cd /home/dir1;zip test.txt test/test2.txt"

if that doesn't work, try putting just the files to be zipped in quotes
ssh source-ip-address cd /home/dir1;zip "test.txt test/test2.txt"

# 5  
Old 10-07-2009

Thanks for your reply. The first command you mentioned works for me. e.g.

ssh source-ip "cd /home/dir1/html; zip /home/ dir2/test.php dir3/dir4/test2.php domains/dir5/test3.php"

this creates zip file when i run from command line as i mentioned multiple file to archive. Now only problem i am facing when i run the same command from script it only creates zip with first file i.e. dir2/test.php , & for the second file i got following error.

bash: line 1: dir3/dir4/test3.php: Permission denied

Can you please help me out what causing this error. FYI, both file permissions is set to root.
Looking to hear from you.

---------- Post updated at 08:12 PM ---------- Previous update was at 08:02 PM ----------

Well, i comeup with the result that in bash script i store path in variable. i.e.

cat path.txt

dir2/test.php dir3/dir4/test2.php domains/dir5/test3.php

# bin/bash

TESTPATH=`cat path.txt`
ssh source-ip "cd /home/dir1/html; zip /home/ $TESTPATH"

it gives me permission denied error. and when i don't use TESTPATH and uses following command in script. it runs without any problem.

# bin/bash

ssh source-ip "cd /home/dir1/html; zip /home/ dir2/test.php dir3/dir4/test2.php domains/dir5/test3.php"
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Show only the filenames under a directory without relative and absolute paths.

I am able to list all the filenames under a directory & its sub-directories except blent.tar on Linux find "/tmp/" -type f | grep -v blent.tar | rev | cut -d '/' -f1 | rev Desired Output: THIRDPARTYLICENSEREADME.txt javaws (3 Replies)
Discussion started by: mohtashims
3 Replies

2. Shell Programming and Scripting

Remove leading dot and slash on relative paths with find

When I specify a directory by name the leading ./ is not shown: $ find somedir/ somedir/a.bin somedir/target/out.binBut when I specify current dir it adds the ./ to the beginning of each result: $ find . | grep somedir ./somedir/a.bin ./somedir/target/out.binIs there any particular reason why... (2 Replies)
Discussion started by: Tribe
2 Replies

3. Shell Programming and Scripting

Zip a list of specific files to an archive

Hi all, i've got the following problem: We've got a shell-script, that creates some different files based on several criteria given, using a sql-script. After creating, those files are individually zipped and stored, then sent to a ftp-server. This is all working since 2010, but now they have... (3 Replies)
Discussion started by: Biggreuda
3 Replies

4. Solaris

exclude absolute paths when extracting Tar file?

Hi, How do I extract data from TAR excluding absolute paths for Tar? (Solaris) Thanks (3 Replies)
Discussion started by: zam
3 Replies

5. UNIX for Dummies Questions & Answers

Absolute and Relative Paths?

Can someone cofirm that I have got the paths correct here? :confused: $PATH_TO_TMP_DIR='/tmp'; #$PATH_TO_TMP_DIR='home/tmp'; $PATH_TO_YOUR_IMG_DIR = '/temp_images'; #$PATH_TO_YOUR_IMG_DIR = 'home/public_html/Midwich/temp_images'; Thanks (1 Reply)
Discussion started by: stubie
1 Replies

6. Shell Programming and Scripting

How to remove ^M characters from a zip file?

Hi All, As all of us know that while moving a file from Windows to Unix some unwanted ^M characters appear in the file. For my case I have release package in zip format which looks like It contains some directory | |--trunk/... (2 Replies)
Discussion started by: bhaskar_m
2 Replies

7. Shell Programming and Scripting

Read specific file from a zip archive without extracting

Hi All, I would like to extract specific file from a zip archive. I have a zip archive "". contains few text files and images... text1.txt, text2.txt, pic.jpg etc... I need to read specific file "text2.txt" from "" WITHOUT EXTRACTING the zip file. ... (4 Replies)
Discussion started by: sridharg
4 Replies

8. 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 Archive: 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

9. AIX

Updating a File in a Zip Archive

Hello everyone, I have a script that pulls a text file out of a zip archive and updates the file. What I need to do is put it back in the zip archive and replace the old one, but I am having no luck. Everything I search on forums or internet points to the command zip, that command is not... (6 Replies)
Discussion started by: dbridle
6 Replies

10. Shell Programming and Scripting

expanding dotted paths to absolute ones in bash or sh

I have a little script to help me manage a gallery of image files. It makes symbolic links to every file in and below the current directory, placing them in a target directory which is passed to the script as a parameter. Unfortunately, the script pukes when I pass a parameter that contains... (4 Replies)
Discussion started by: TanRanger
4 Replies
Login or Register to Ask a Question