1

This question already has an answer here:

I am trying to follow the installation instruction for a piece of software:

cp SOFTWARE-yyyymmdd.linux.tar.gz /usr/local/.
cd /usr/local
gunzip -c SOFTWARE-yyyymmdd.linux.tar.gz > SOFTWARE-yyyymmdd.linux.tar

But when I try to do that, I get the following error:

-bash: SOFTWARE-yyyymmdd.linux.tar: Permission denied

What could be the problem here?

marked as duplicate by David Foerster, Eric Carvalho, Zanna, Kevin Bowen, karel Aug 23 '17 at 6:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What's the output of ls -ld . SOFTWARE-yyyymmdd.linux.tar executed with the same working directory as the gunzip command? – David Foerster Aug 22 '17 at 10:19
  • the copy is exsist, but there is no .tar. ls -ld for the gz is rwxr-xr-x 12 root root 4096 Aug 21 15:02 . -rw-r--r-- 1 root root 81860966 Aug 21 15:04 – Lona Gy Aug 22 '17 at 10:27
  • Could you please edit your post, when you want to add information? Especially file or program output listings (with the help of the {} button in the editor toolbar) will be much more readable there; alternatively you can use a pastie service for longer listings and include the link of your pastie in your question. Overall it’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons. Thanks. – David Foerster Aug 22 '17 at 10:34
2

The target directory of the file redirection in your last command is owned by root and your current user account doesn't appears to have super-user privileges to create files in it. Hence you need to use sudo to decompress the file.

  • To decompress the file without extracting the archive:

    sudo gunzip -k SOFTWARE-yyyymmdd.linux.tar.gz
    

    The option -k prevents the deletion of the source file just like -c. Otherwise gunzip deletes SOFTWARE-yyyymmdd.linux.tar.gz after its successful decrompression.

  • To decompress and extract the archive:

    sudo tar -xf SOFTWARE-yyyymmdd.linux.tar.gz
    
  • If you really want to use file redirection to decompress the file you need to perform the redirection as super-user. A common way to achieve that is the “abuse” of tee:

    gunzip -c SOFTWARE-yyyymmdd.linux.tar.gz | sudo tee SOFTWARE-yyyymmdd.linux.tar > /dev/null
    

    For alternative approaches see When using sudo with redirection, I get 'permission denied'.

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