Trying to make a script that will copy some files between machines, and unzip them. (Running CentOS 6.7) Everything seems to work except the unzip part,

This is the command giving me some issues,

ssh -i /root/.ssh/qasynd.key file_sync@ 'unzip /home/root/tmp/*.zip'

Ignoring the user/directory structure as that's just for the command, what could cause this? I did try to point it to /usr/bin/unzip as opposed to just unzip.

  • 2
    What issues is it giving you? Please include error messages in your post. – janos Jan 5 '17 at 16:53
  • Thats the thing, it doesnt give a full error, [root@server01 vsoloviev]# ssh -i /root/.ssh/qasynd.key file_sync@ 'unzip /home/root/tmp/*.zip' |-----------------------------------------------------------------| Archive: /home/root/tmp/test.txt.zip replace test? [y]es, [n]o, [A]ll, [N]one, [r]ename: A extracting: test – Vlad S Jan 5 '17 at 16:58
  • 1
    Please edit your question to include the missing information. It's close to unreadable here in comments, which are only intended for comments - not updates to the question. – roaima Jan 5 '17 at 17:08

This is a very common problem with linux zip... if you do

unzip *.zip 

and you have say three files:


it expands to mean

unzip a.zip b.zip c.zip

which looks good, but it tells unzip to unzip b and c from within a, which is incorrect. This will not work. (check it on your local system).

The solution is

unzip '*.zip'. 

You will need to escape the ' in your ssh (e.g. backslash or use doubles).

  • So i did that, And for test reasons made a new zip file, [root@server01 root]# ssh -i /root/.ssh/qasynd.key file_sync@ unzip /home/root/tmp/'*.zip' Archive: /home/root/tmp/test.zip extracting: test1 extracting: test2 But nothing extracted in the zip file directory. – Vlad S Jan 5 '17 at 17:13
  • 1
    @VladS Files are extracted in the directory where you run the unzip command (your home on the remote server), not in the directory where the zip file lies. – xhienne Jan 5 '17 at 17:26
  • Looks like the files do get extracted now, but not in the zip file directory, and not where teh command is run, but appear in the home folder of the user that owns the zip file. – Vlad S Jan 5 '17 at 18:29
  • If you would like your files to be extracted in a particular directory, you need to add the -d flag to unzip. From the help: unzip [-Z] [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]] file[.zip] [file(s) ...] [-x xfile(s) ...] [-d exdir] Note the -d exdir means directory to extract to. – number9 Jan 5 '17 at 18:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.