Exercise 8/10 mv command



When moving batman.txt into spiderman.txt it renames batman.txt to spiderman.txt, where does the data in each file go?


There are two possible scenarios, where one file exists and you want to rename it, and when both exist and you want to overwrite one with the other.

In the first scenario, by 'moving' one file to another, as yet non-existent file, you just change the name of your file. All the file contents remain untouched.

In the second, more complex scenario the first file's contents stay the same, but the name of the file changes. The other file that used to have that name ceases to exist.

You can test this yourself. Create 2 files in the same directory, batman.txt and spiderman.txt. Put a quote in each file to identify them such as:

Where's Rachel?!

With great power comes great responsibility.

Now in your command shell type $ mv batman.txt spiderman.txt. Then do an $ ls. You'll see that there no longer is a batman.txt file, just a spiderman.txt. If you open spiderman.txt you'll find the batman quote.


Thank you. That was a perfect explanation.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.