1

I have accidentally run mv command in folder to rename files. But I have forgot to specify absolute path (I did just mv old_name new_name). Now the files are gone. Any idea where those files are?

Thanks for any help.

7
  • When you run the mv command without specifying a new folder location, all it does is rename the file and it stays in the current directory. You're not seeing the renamed file at all in the same directory where the file was initially?
    – n8te
    Feb 10, 2017 at 11:27
  • Yes, I cannot see the files in the folder.
    – Marek Zak
    Feb 10, 2017 at 11:29
  • 1
    Ok, type history, and you can see exactly what move command you actually ran. Use history | less if you've typed so much you can't see the history in full anymore. - Did you run this command multiple times on different files, with the same 'new_name' ? Feb 10, 2017 at 11:31
  • 1
    ll is an alias which may not exist, use ls -a to display all files including those starting with . (hidden). Feb 10, 2017 at 11:35
  • 1
    Yes, I run the command on multiple files in a loop. I inspected the script and realized, that I was missing '$' in front of variable so I have renamed all files to the variable name. Will restore from backups. Feel so stupid, thanks for help.
    – Marek Zak
    Feb 10, 2017 at 11:36

2 Answers 2

5

They'll be in the same directory, if you didn't provide any directory designation such as .. or ../..

So mv oldFile newFile stays in the same directory (basically renaming it),

Note: If newFile already existed, you've just overwritten it - mv won't ask before doing so unless you supply -i as an argument.

mv oldFile ../newFile moves it into the parent directory,

mv oldFile ./existingSubDirectory/newFile moves it into the directory existingSubDirectory with the newFile name,

mv oldFile -p ./newSubDirectory/newFile creates the new subdirectory called 'newSubDirectory' and puts the newFile within it.

You can combine to do some very weird (and generally pointless) directory traversal such as mv oldFile ././././../../dev/null if you really wanted, but there's very little point.

1

If you did not specify a full path they're in position relative to the path you worked on.

If you're in your users directory (/home/user) and run mv myfile newfile while being in that directory the file is renamed to newfile. If it exists it's overwritten. If you specified part of a path (mv myfile something/newfile) and the folder did not exist, you'd get an error. If you supplied -p the folder something would've been created.

If you do know the name you could use find or some other utility to find the file (on Debian you could use locate).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .