0

I have Cygwin installed on my Windows 7 64 bit PC and I often download large files using wget. wget, however, saves all files with permissions that forbid me from executing the files when they're Windows executable files (.exe or .msi). Is there any way for me to set the permissions such that I can execute these files automatically? Can I also change the default directory to which they're saved? Presently they are saved to the cygwin folder C:\cygwin64\home\Brenton and I'd like to save them to C:\Users\Brenton\Downloads.

For clarity's sake I know how to move these files to my desired directory manually after they're saved (e.g., using:

mv filename C:\Users\Brenton\Downloads

where filename is the file name that needs to be transferred) and I know how to change permissions manually via:

chmod 755 filename

but what I want is an automatic way so that all files downloaded via wget from henceforth would be downloaded to my preferred directory with my preferred permissions.

  • Why don't you use Wget for Windows? – Karan Apr 16 '15 at 8:00
1

Destination directory

You can use the -P prefix / --directory-prefix=prefix option to direct wget to save to a certain directory.

Set directory prefix to prefix. The directory prefix is the directory where all other files and subdirectories will be saved to, i.e. the top of the retrieval tree. The default is . (the current directory).

Example to save a single file to your download directory:

wget -p $(cygpath -u "C:\Users\Brenton\Downloads") http://host.name/setup.exe

File permissions

On my system, umask is set to 0022 so when I use wget to download files to my Cygwin home directory, the files have -rw-r--r-- permissions – as expected.

However, if I download to my Windows Downloads directory, the executable permissions are set. I’m not sure why but I suspect that somehow the permissions are being by influenced by NTFS ACLs. This behaviour may also work to your favour on your system. If it does, you could use a simple shell alias such as:

alias wget-exe='wget -P $(cygpath -u "C:\Users\Brenton\Downloads") '

Suggested shell script / function

If you still have to change permissions, you could use the following code as the basis for a shell script or function (called something like wget-exe):

#!/bin/sh
downloads=$(cygpath -u "C:\Users\Brenton\Downloads")
wget -P "$downloads" "$@"

dir="$PWD"
cd "$downloads"
chmod 755 *.exe *.msi
cd "$dir"
# Alternative version using find to change permissions of all .msi and .exe files
# downloaded in the last day.
# find "$downloads" -mtime -1 \( -name '*.exe' -o -name '*.msi' \) -print0 | xargs -0 chmod +w
  • Should I add the file extension .sh for this wget-exe file? – BH2017 Apr 16 '15 at 9:43
  • Unix programs don't really pay attention to file extensions. However, it doesn't do any harm and some text editors will use the extension to apply appropriate syntax highlighting. – Anthony Geoghegan Apr 16 '15 at 9:53
  • I'd like to suggest a little edit. The shell script should have the cygpath -u removed and the command (from the command line) that seems to be working is wget-exe.sh -c -i Downloads.txt where Downloads.txt is a textfile containing the list of URLs I'd like to download from. – BH2017 Apr 16 '15 at 11:47
  • Yeah sure. I used the cygpath command for the benefit of anyone else who wants to do something similar but whose profile is stored in a drive other than C:. In your case, it makes perfect sense to just use /cygdrive/c/Users/Brenton/Downloads. Both the alias and script / function should work with any number of valid wget arguments. – Anthony Geoghegan Apr 16 '15 at 14:14
  • @BrentonHorne So, did the suggestions work out for you? I'd be curious to know if simply using the -P flag to download to directly to your Windows "Downloads" directory set the execute permissions. One of my Cygwin Todo tasks is to figure out NTFS ACLs so that the Windows-generated files don't display in green (for executable) when I run ls -- a (loose( corollary of your issue. – Anthony Geoghegan Apr 18 '15 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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