GNU bug report logs - #5926
feature request: mv -p to create missing target dir

Previous Next

Package: coreutils;

Reported by: Rodolfo Borges <rodolfo.borges <at> gmail.com>

Date: Sun, 11 Apr 2010 14:10:02 UTC

Severity: wishlist

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 5926 <at> debbugs.gnu.org (full text, mbox):

From: Rodolfo Borges <rodolfo.borges <at> gmail.com>
To: Bob Proulx <bob <at> proulx.com>
Cc: 5926 <at> debbugs.gnu.org
Subject: Re: bug#5926: feature request: mv -p to create missing target dir
Date: Fri, 16 Apr 2010 08:30:47 -0300
On Thu, Apr 15, 2010 at 8:13 PM, Bob Proulx <bob <at> proulx.com> wrote:
> Rodolfo Borges wrote:
>> $ mv foo ~/some/path/
>> mv: cannot create regular file `/home/bart9h/some/path/': Is a directory
>
> No target directory exists.
>
>> $ mkdir -p ~/some/path/
>> $ mv foo ~/some/path/
>
> That seems like the best way to do it.
>
>> $ :(
>> bash: syntax error near unexpected token `newline'
>> ...
>> $ :)
>> bash: syntax error near unexpected token `)'
>
> Using this format to tell us what you are thinking is very confusing!
>

It seems you haven't got the writing style.
I know the cause of the error in the first `mv` and, sheesh!, I
frigging know bash doesn't understand emoticons.
Better to fallback to plain boring English, then.


>> $ mv -vp foo ~/some/path/
>> mv: created directory `/home/bart9h/some'
>> mv: created directory `/home/bart9h/some/path/'
>> `foo' -> `/home/bart9h/some/path/foo'
>
> I don't think this is a good idea.  It could be added.  But does it
> really gain you anything over calling mkdir -p?
> I don't think so.
> It would simply add code bloat to the program.

You don't have to type the path twice, and more importantly, you don't
have to know beforehand that the path doesn't exist yet.
The use case if fairly common: you start typing `mv
my-first-salsa-album/ ~/music/sal<tab><tab>` ops!, I have no salsa
subdir yet in my music collection: I have to cancel the command,
create the directory, then type it again.

> Plus it wouldn't be portable.  Other implementations wouldn't have it.
> It is only of marginal benefit if at all and so other implementations
> might never have it.  In any case you would need to wait years before
> the feature trickled down to where you could use it reliably.

The GNU utilities already have a bunch of features that other
implementations don't have.

> Also you can always accomplish this yourself with a shell script.  In
> general things that can be easily encapsulated in a shell script are
> not good additions to the utilities.

cat <<EOF >> ~/.bashrc
function mv() {
    local target="${!#}"
    local dir
    if [[ "$target" =~ '/$' ]]; then
        dir="$target"
    else
        dir="$(dirname "$target")"
    fi
    test -d "$dir" || mkdir -vp "$dir"
    $(which mv) "$@"
}
EOF


> Adding that option is counter to The Unix Philosophy.  Small is
> beautiful.  Make each program do one thing well.  Choose portability
> over efficiency.  Use shell scripts to increase leverage and
> portability.

`cp` does create directories, shouldn't it restrict itself to copying
files then?




This bug report was last modified 10 years and 218 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.