[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: command for swapping of two files or two dirs?
From: |
Alex fxmbsw7 Ratchev |
Subject: |
Re: command for swapping of two files or two dirs? |
Date: |
Fri, 26 Mar 2021 21:59:49 +0100 |
i agree to all excepts the srandom thingy
a [[ -e loop passthru maybe.. like always
On Fri, Mar 26, 2021 at 9:58 PM Greg Wooledge <greg@wooledge.org> wrote:
>
> On Fri, Mar 26, 2021 at 09:18:10PM +0100, Alex fxmbsw7 Ratchev wrote:
> > swap() { declare t= tt= ; [[ $# != 2 ]] && return 1
> > mv "$1" "${t:=/tmp/$SRANDOM}"
> > mv "$2" "${tt:=/tmp/$SRANDOM}"
> > mv "$t" "$2"
> > mv "$tt" "$1"
> > }
>
> 1) Use mktemp(1) or tempfile(1) or whatever. Your $SRANDOM hack has
> security problems.
>
> 2) Don't move the file to /tmp. That might be on a different file system.
> You want to keep the file within its current directory, as that's the
> only place you can be sure isn't on another file system.
>
> 3) There should only need to be three moves.
>
> 4) You probably want && between the moves, to abort if something goes
> wrong.
>
- command for swapping of two files or two dirs?, Peng Yu, 2021/03/26
- Re: command for swapping of two files or two dirs?, Alex fxmbsw7 Ratchev, 2021/03/26
- Re: command for swapping of two files or two dirs?, Alex fxmbsw7 Ratchev, 2021/03/26
- Re: command for swapping of two files or two dirs?, Greg Wooledge, 2021/03/26
- Re: command for swapping of two files or two dirs?, Reuti, 2021/03/26
- Re: command for swapping of two files or two dirs?, Alex fxmbsw7 Ratchev, 2021/03/26
- Re: command for swapping of two files or two dirs?, Peng Yu, 2021/03/26
- Re: command for swapping of two files or two dirs?, Reuti, 2021/03/26
Re: command for swapping of two files or two dirs?, Alex fxmbsw7 Ratchev, 2021/03/26