Commands.page Logo

How to Prevent Wget From Overwriting Files in Ubuntu

This article explains how to protect existing data when downloading with wget on Ubuntu. It identifies the specific command-line flag required to stop the utility from replacing files that are already present in your directory.

The flag that prevents wget from overwriting existing files is -nc. This is short for “no clobber.” You may also use the full command --no-clobber to achieve the same result.

When you include this flag in your command, wget checks the destination folder before initiating a download. If the file already exists, wget skips the download process for that specific file and moves on. This ensures that your local data remains intact and is not replaced by a new download.

Command Example

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

Using this flag is essential for automation scripts or when managing unstable connections. It allows you to run download commands repeatedly without worrying about duplicating data or accidentally losing previous versions of a file.