Skip to content

mv: prompts to overwrite read-only file when stdin is not a terminal #11321

Description

@siraben

When mv tries to overwrite a file with mode 0555 (read-only), it prompts for confirmation even when stdin is not a terminal. GNU mv silently proceeds in this scenario.

This is the mv equivalent of #7326, which was fixed for rm in PR #7492.

Expected behavior (GNU coreutils)

$ touch target && chmod 555 target
$ echo content > source
$ mv source target < /dev/null
$ # No promprt, file is moved
$ cat target

Actual behavior (uutils)

$ touch target && chmod 555 target
$ echo content > source
$ mv source target < /dev/null
mv: replace 'target', overriding mode 0555 (r-xr-xr-x)?
$ # Prompts and waits/fails, file is NOT moved

Reproducing script

#!/usr/bin/env bash
set -e

WORKDIR=$(mktemp -d)
cd "$WORKDIR"
trap "rm -rf $WORKDIR" EXIT

# Create a read-only target file
echo "original" > target
chmod 555 target

# Create source file
echo "replacement" > source

echo "=== Testing mv with stdin redirected from /dev/null ==="
echo "Running: mv source target < /dev/null"

# This should NOT prompt when stdin is not a terminal
if timeout 2 mv source target < /dev/null 2>&1; then
    echo "PASS: mv completed without prompting"
    echo "target contents: $(cat target)"
else
    echo "FAIL: mv prompted or timed out (exit code: $?)"
    echo "GNU mv would silently overwrite the file"
fi

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions