I have accidentally deleted(in a way) or I can say dislocated reference to my /home/user/Desktop directory , Is there any way to undo what I have done.

The following Describes what I have done

$ cp xyz.java /home/user/Desktop
$ cp xyz1.java /home/user/Desktop

After these commands I am getting blank Desktop With wallpaper and when I try to open my Desktop Directory by

cd /home/user/Desktop

command it gives following not a directory error

bash: cd: /home/user/Desktop: Not a directory

PS: Before copying the file to correct Desktop Directory I mis-spelled Desktop as Deskop and system Created a file name Deskop in my /home/user folder when I opened it, the file contained data of xyz.java in it.

could anyone guide me through this and also please tell me what happened to my Desktop files and If, they are now orphaned in my memory How do i restore them.I have one more question in my mind after this Disaster:

How do I undo the commands and their execution results with command-line?

  • 2
    cp never deletes an existing directory. Either this wasn't the only thing you did, or something else happened that makes that directory inaccessible. – David Foerster Feb 8 '15 at 19:19
  • @Rinzwind- Yes I actually used "user" which is my username – Chinmaya B Feb 8 '15 at 19:33
  • what should I do?? I don't want empty Desktop.. Is there any way to recover from this? – Chinmaya B Feb 8 '15 at 19:45
  • @Creator doubt it. But there is a tool called "testdisk" (have a search on AU for it) that can restore deleted files. That might be your best best. – Rinzwind Feb 8 '15 at 19:50
  • have a look here for restoring: askubuntu.com/questions/3883/how-to-recover-deleted-files – Rinzwind Feb 8 '15 at 19:52

I doubt these commands did anything:

rinzwind@schijfwereld:~$ mkdir test
rinzwind@schijfwereld:~$ touch test1
rinzwind@schijfwereld:~$ cp test1 test
rinzwind@schijfwereld:~$ ls -l test*
-rw-rw-r-- 1 rinzwind rinzwind    0 feb  8 20:20 test1

total 0
-rw-rw-r-- 1 rinzwind rinzwind 0 feb  8 20:20 test1
rinzwind@schijfwereld:~$ cd test
rinzwind@schijfwereld:~/test$ ls

Directory test is still there and has test1 in it.

Before you continue do a

ls -l ~

and examine the results. There should be a

drwxrwxr-x 2 rinzwind rinzwind 4096 feb  8 20:20 Desktop

The "d" makes it a directory. If that is the case all is well.

If not and it shows a "-" (aka. it has become a file) ... do (as rthe user you want this desktop created ($USER will be expand to that user name)):

cd ~
rm /home/$USER/Desktop
mkdir Desktop

(do not add -r to the rm) as the user that is suppose to own this directory. Otherwise add in

chown $USER:$USER Desktop

Warning: if you do this with a directory the "rm" will fail with an error stating you are trying to delete a directory. This will have you restore to an EMPTY desktop. If you had files in there they are gone.

From comments

-rw-r--r--  1 root       root        Desktop

Put "sudo" in front of the "rm" above. So ...

cd ~
sudo rm /home/$USER/Desktop
mkdir Desktop
  • chmod: invalid mode: ‘root:root’ Try 'chmod --help' for more information. – Chinmaya B Feb 8 '15 at 20:37
  • Do not do this are root please. – Rinzwind Feb 8 '15 at 20:48
  • I did it and got a new Desktop Folder all my stuff is lost and what is major reason not to work (unnecessarily) as root? – Chinmaya B Feb 8 '15 at 20:49

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.