1

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)"

Thanks

5
  • Was the directory called folder1 or Folder1? Is it possible that that's the source of the confusion? Commented Jan 5, 2016 at 20:27
  • @KeithThompson I just found out that the folder was moved without notifying us. A big thank you! Commented Jan 5, 2016 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" Commented Jan 6, 2016 at 2:11
  • @ekaj lesson learnt! Commented Jan 6, 2016 at 15:09
  • I have a similar situation. I took the output of an HG command and used the ">" symbol to direct it's output to a file but accidentally targeted directory name instead. There is now a file with the directory's name there containing the output of the HG command. Odd thing though, it was the root directory of a website and Apache is still serving up the site normally. I'm afraid if I restart Apache or the system I'll loose the link to the site directory. Help! Commented Dec 19, 2019 at 2:02

1 Answer 1

2

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.

8
  • 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. Commented Jan 5, 2016 at 20:25
  • If it was present previously, it was removed prior to the cp command you listed being issued. Commented Jan 5, 2016 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? Commented Jan 5, 2016 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. Commented Jan 5, 2016 at 20:44
  • Thank You. It is a relief to know that, even as i still look for the missing directory. Appreciate your help! Commented Jan 5, 2016 at 20:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.