Can someone please help me with a possible case of accidental deletion on a linux box?

I ran the following command:

cp file1 /newdir1/folder1

What I intended to do was to copy file1 to the pre-existing /newdir1/folder1/ directory. Now when I try to go to /newdir1 and run ls command i see folder1 which as a file with contents from file1, instead of finding the original folder1. Folder1 had some files within as well. I didn't get a warning when i ran the copy command. Is it possible that folder1 is now deleted? Is there any way to check for it or Is there any way to recover it if it is deleted?

This is what I have checked so far: When i type alias cp i get alias cp='cp -i' To check linux version, I browsed to the /etc/ directory and checked redhat-release file and it says "CentOS release 6.4 (Final)"


  • Was the directory called folder1 or Folder1? Is it possible that that's the source of the confusion? – Keith Thompson Jan 5 '16 at 20:27
  • @KeithThompson I just found out that the folder was moved without notifying us. A big thank you! – PC2015 Jan 5 '16 at 21:20
  • It helps to always use trailing slashes, so you are explicitly aware you are transferring a file to a directory. In this case, you would have saved yourself a lot of time because you would get an error that says "not a directory" – cutrightjm Jan 6 '16 at 2:11
  • @ekaj lesson learnt! – PC2015 Jan 6 '16 at 15:09

If the folder1 item is actually the file1 file, then there was no preexisting folder1 directory. The default behavior of cp is that if the destination is a directory, the item(s) to be copied will be copied into the destination directory. Note that in Linux, folder1 and Folder1 are different, as it is case-sensitive.

  • The folder1 item now shows contents from file1. And folder1 directory has disappeared. This folder was present before since i have accessed it. Unfortunately i believe that it was deleted and replaced. It doesnt look like i have a way to find out using history or logs. – PC2015 Jan 5 '16 at 20:25
  • If it was present previously, it was removed prior to the cp command you listed being issued. – John Jan 5 '16 at 20:36
  • That may be a possibility but seems unlikely for someone to go in and delete it. is there any way to check logs or history? – PC2015 Jan 5 '16 at 20:38
  • You would need to look through the ~/.bash_history files for each user. And it's not a possibility, it is a definite. cp does not replace directories when they already exist - it never has and likely never will. – John Jan 5 '16 at 20:44
  • Thank You. It is a relief to know that, even as i still look for the missing directory. Appreciate your help! – PC2015 Jan 5 '16 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.