I accidentally copied the full contents of a directory into a destination directory instead of moving the full directory. This resulted in a cluttered destination directory instead of the origin directory being added to the directory.
To fix this, I did the following:
ls -rt /path/to/cluttered/destination/directory/ > /opt/dircheck/filestomove
The above command creates the filestomove file that will be a list of all contents of the destination directory, reverse sorted by time, meaning oldest to newest.
Then I created a sub-directory of the now cluttered destination directory to move the stuff into.
Then I repeated the directory listing, except listing to screen and showing more details.
ls -lrht /path/to/cluttered/destination/directory/
This line lists the directory, sorted by date ascending (reverse sort by time) and shows more information, including the date/time stamp of each file in the now cluttered destination directory. I refer to this, starting at the top to show what directories and files I want to keep where they were. There will be a gap in the date/time stamp of the files where all the new files start that shouldn't be there.
Then I edited the filestomove file created in the first step above (that is sorted by date) and deleted the few from the list that were there previously that I want to stay from the original directory.
vim /opt/dircheck/filestomove Delete from the top, all files you don't want to move.
Then I used the command listed previously in this post to move the files in my list to the new directory I made.
sudo xargs -a /opt/dircheck/filestomove mv -t /path/to/cluttered/destination/directory/newsubdirectory
This moved all the files in a split second. (Note: you may not need the sudo at the beginning, this is a matter of file permissions).
Now my original destination directory is nice and clean and contains a new directory with all the files and directories that were cluttering it.