Modifying wget permissions and download directories on Cygwin
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
Related videos on Youtube
Josh Pinto
Updated on September 18, 2022Comments
-
Josh Pinto over 1 year
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 toC:\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.
-
Karan about 9 yearsWhy don't you use Wget for Windows?
-
-
Josh Pinto about 9 yearsShould I add the file extension .sh for this wget-exe file?
-
Anthony Geoghegan about 9 yearsUnix 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.
-
Josh Pinto about 9 yearsI'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 iswget-exe.sh -c -i Downloads.txt
where Downloads.txt is a textfile containing the list of URLs I'd like to download from. -
Anthony Geoghegan about 9 yearsYeah 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 thanC:
. 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 validwget
arguments. -
Anthony Geoghegan about 9 years@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 runls
-- a (loose( corollary of your issue.