the slash (/) after a directory name on shell commands
Yes, this is a bit inconsistent, even within the GNU tools.
One problem with your proposal is that non-empty directories cannot be removed. Apart from that, -T
(in GNU land, anyway) approximates what you want (the first case):
$ ls dira/ dirb/
dira/:
a
dirb/:
b
$ mv -iT dira/ dirb/
mv: overwrite `dirb/'? y
mv: cannot move `dira/' to `dirb/': Directory not empty
$ rm dirb/b
$ mv -iT dira/ dirb/
mv: overwrite `dirb/'? y
$ ls dira/ dirb/
ls: cannot access dira/: No such file or directory
dirb/:
a
Related videos on Youtube
phunehehe
Updated on September 17, 2022Comments
-
phunehehe almost 2 years
I have a little question here.
If I have two files, say
filea
andfileb
,mv filea fileb
would- delete
fileb
- rename
filea
tofileb
Then if I have two directories, say
dira
anddirb
,mv dira dirb
would- move
dira
intodirb
(it will becomedirb/dira
)
Noting that in both cases there are no notice or message, then this is pretty inconsistent to me. I think
mv dira dirb
should just overwritedirb
with the contents ofdira
(or merge the two directories under a directory nameddirb
).I remember reading somewhere that a directory name with a slash (like
dira/
) is treated like a directory, and name with no slash (likedira
) is treated like a file (to certain extents, of course). Anyway now I want to make the shell (zsh and possibly bash) respect my notation of a directory by using a slash. Is there a terminal option which enable me to enforce that?To clarify, here is my desired behaviour:
mv dira dirb
results indirb
being overwritten with the contents ofdira
mv dira dirb/
results indira
being moved intodirb
(indirb/dira
)
Has anyone thought the same way as me? Or am I just weird?
-
ElBel almost 14 yearsI think your desired behavior would be rather dangerous.
-
phunehehe almost 14 years@starblue: yes I agree that it is dangerous, but I'd rather live with something dangerous, than inconsistency
- delete
-
Jan Berkel almost 14 yearsYour command would miss all dotfiles.
-
Robert Massaioli almost 14 yearsWho needs dot files anyway ;)
-
Jerb almost 14 yearsAnd if it's an issue,
shopt -s dotglob
in bash will fix that. -
Mikel about 13 yearsYou could also add an alias, e.g.
alias ren=mv -T
.