0

I find the --strip-trailing-slashes option of the mv command confusing.

According to the official GNU manual, this option is "useful when a source argument may have a trailing slash and specify a symbolic link to a directory." So I try the following:

$ mkdir a
$ ln -s a b 
$ mv --strip-trailing-slashes b/ c

and I get mv: cannot move 'b' to 'c': Not a directory, while I expect b to be renamed as c.

Do I misunderstand this option? Are there any examples of how to use this option?

  • 1
    Cannot reproduce with coreutils 8.28. The link gets renamed and I don't get any errors. – muru Jul 1 '20 at 2:09
  • 1
    With b as a symlink, as per the question, I can reproduce with GNU coreutils 8.30. – John1024 Jul 1 '20 at 2:41
0

The command mv may become confusing sometimes.

There are two alternatives to a mv command with two arguments:

mv one two

One, and the default, is to move the file one into the directory two.

If directory two doesn't exist, then mv one two may be interpreted as move the file one to the file two (a rename). Of course, if file two already exists, the user may be prompted if he wants to overwrite it (or other options).

It seems that when the option --strip-trailing-slash is used, the meaning is lock into move one file into a directory (not a rename).

If you still want to rename a directory while using --strip-trailing-slash, you must declare that there is no directory:

mv -T one two

Example:

$ mkdir one
$ ln -s one two
$ mv two/ yes
mv: cannot move 'two/' to 'yes': Not a directory

$ mv --strip-trailing-slash two/ yes
mv: cannot move 'two' to 'yes': Not a directory

$ mv -T --strip-trailing-slash two/ yes

$ ls -la
total 12
drwxr-xr-x 3 isaac isaac 4096 Jul 01 03:38 .
drwxr-xr-x 6 isaac isaac 4096 Jul 01 03:37 ..
drwxr-xr-x 2 isaac isaac 4096 Jul 01 03:38 one
lrwxrwxrwx 1 isaac isaac    3 Jul 01 03:38 yes -> one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.