Typically, mv is one of the first Linux commands you learn.

But one little slip, and things can get surprisingly confusing for the user.

Sometimes it looks like moved files have simply vanished.

A magnifying glass pointed at the Linux mascot next to a file folder

Lucas Gouveia / How-To Geek

How This Particular Problem Foxes People

Moving a file on thecommand line is pretty simple.

You specify the file you want to move, and where you want to move it to.

But still, its easy for a new user to find themselves exasperated and frustrated over mv.

Moving a file with the mv command

They make a run at move a file into a directory, and it seems to work.

They dont get a confirmation message, but neither do they get an oops message.

Linux often takes the no news is good news approach.

A moved file in its new directory.

If you dont get an error alert, it must have worked.

When they cd into the target directory, the file isnt there.

And of course, because mv moves the file from the original directory, its not there either.

Trying to use the mv command with a typo in the final directory name.

Its starting to look like the file has been lost in the ether.

This is usually the point where the frustrated user reaches out for help.

Youre going to keep the same filename.

Using ls to look for the file in the original and new directories.

By default, mv uses the original filename.

Weve got a file in the ~/Downloads/src directory.

We move it to the ~/Documents/backup directory.

The location of the missing and misspelled file.

As expected, its now in the backup directory, and it has been removed from the src directory.

Thats nice and simple, and everything works as expected.

But let’s say our Linux newcomer isnt usingtab completion.

Moving and renaming the misspelled file

They’re typing the directory paths by hand.

If they misspell the name of the final directory, we get a very different behavior.

Theyve made a typo with the target directory name, but mv exits silently back to the command prompt.

The trailing slash on the mv command line flags errors with the final directory name

On the face of it, it looks like the file move worked.

The original and target directories are both empty.

Where did the file go?

Bash tries to find a directory called backpu, but can’t find one.

It concludes you want to rename your moved file to backpu.

Youll find a file called backpu one directory level higher than your target directory.

That way, if you make a typo, Bash reports an error.

The trailing slash explicitly tells Bash that this is a directory name, not a filename.

Because Bash cant find the misspelled directory, it reports the error to you and doesnt move anything.

This is a better outcome for failures.

Youre alerted to the error, and the original file remains touched.

All the directory names are automatically spelled correctly, and a trailing slash is added to the final directory.

Its Not Exactly Slashs Fault

Slash didnt make the typo, after all.