uutils / uutils/coreutils

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

Open
#11,321 2 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - mv
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the mv command entry point and reproduce the issue with the supplied shell script, using a mode-0555 target and stdin redirected from /dev/null. Review the related rm issue #7326 and fix in PR #7492 for relevant behavior. Done means mv completes without prompting, moves source over target, and leaves the replacement content in target.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.