Commands.page Logo

Wget Flag to Disable Directory Hierarchies Ubuntu

This article provides a concise explanation for Ubuntu users seeking to control how wget saves downloaded files. It focuses specifically on the command-line option that prevents the tool from recreating the remote server’s folder structure locally. By using this setting, users can ensure all downloaded content lands directly in their current working directory without nested subfolders.

To disable the creation of directory hierarchies in wget, you must use the -nd flag. This is the short form of the --no-directories option. When this flag is active, wget ignores the path information in the URL and saves the file directly into the directory from which you executed the command.

Here is the basic syntax for using this flag:

wget -nd https://example.com/path/to/file.zip

In this example, even though the file exists within a nested path on the server, it will be saved as file.zip in your current local folder. This is particularly useful when downloading multiple files from different depths of a website but wanting to organize them manually later in a single location. Using -nd streamlines the process by eliminating the need to navigate through automatically generated folders after the download completes.