I ran
/$ sudo mv -f -i FileSystem/* After using the command all my files are missing. Where my files have gone to?
02 Answers
This command lacks a destination:
sudo mv -f -i FileSystem/* Due to expansion of the * mv will use the LAST one it finds for the directory to move it to (or file is there was only 2). Example:
touch 1 2 3 4 5 6 7 8
$ mv *
mv: target '8' is not a directoryIt errors out because 8 is not a directory. The last one in your command probably was a directory so it will have moved all the files into that directory. Or if the mv consists of 2 files it will have moved one over the other.
So do a
ls FileSystemand it should still have 1 item in there being a directory that has the result of your mv. Mind that due to the -f (force) and if it was 2 files you deleted one and will not be able to recover it. You would need to restore a backup.
Example of the last:
$ ls
1 2
$ mv *
$ ls
2This only happens when there are TWO files.
1 errors out
ls
1
$ mv *
mv: missing destination file operand after '1'
Try 'mv --help' for more information.3 and more error out too (as with the 8 files example above) UNLESS the last one is an existing directory:
$ touch 1 2 3 4 5 6
$ mkdir 7
$ mv *
$ ls
7
$ ls 7
1 2 3 4 5 6 The files in the globbed folder (FileSystem) will be treated by the shell as a list of arguments to the mv command, and so the last file/folder in the list will be read as the destination.
- If you had just two files,
mvwould replace the second with the first after prompting for permissions to overwrite. - If the last item in the list returned is a folder,
mvcommand will move everything else inside the folder in question.
It seems likely that the missing files are located in the last folder that the FileSystem/* would have produced at the time the command was run.
Consider the following test folder containing exactly two files, where running the command you listed will attempt to overwrite the first file with the second (I've added -v for illustrative purposes):
~$ ls testdir
test1.txt test2.txt
sudo mv -f -i -v testdir/*
mv: overwrite 'testdir/test2.txt'? y
renamed 'testdir/test1.txt' -> 'testdir/test2.txt'In another scenario, where a folder is the last in the list of files, it moves everything to test_folder (as it's the last returned item and is treated as the destination by mv command) like so:
$ ls testdir/
empty_folder1 test1.txt test2.txt test_folderAll of your files will be moved to the last item in the list (test_folder in this example)
$ sudo mv -f -i -v testdir/*
renamed 'testdir/empty_folder1' -> 'testdir/test_folder/empty_folder1'
renamed 'testdir/test1.txt' -> 'testdir/test_folder/test1.txt'
renamed 'testdir/test2.txt' -> 'testdir/test_folder/test2.txt' 1