0

On my CentOS , i was on the following directory:-

/home/coolcatg 

and that directory contain a website folder named "public_html".

I simply copied that folder to /home directory :-

[root@server coolcatg]# cp -R public_html /home/coolcatgbk

Now when i want to use the copied directory, i noticed it converted somehow to file instead of folder

lrwxrwxrwx   1 root       root           40 Apr 29 19:15 coolcatgbk -> ./domains/cdomainname.com/public_html

How can i recover it?

2
  • You'll need to add a / at the end of public_html to have it be treated as a directory
    – Vinayak
    Apr 29, 2020 at 20:05
  • That is a link and I don't know how you made it using cp -R.. Notice the "l" at the front of the permissions and the "->" between coolcatbk and the path?.. Also.. seeing that you don't know what you are doing completely yet (we've all been there).. you WILL hurt yourself as root. Apr 29, 2020 at 20:07

1 Answer 1

1

it looks like what you copied was a symbolic link, aka symlink, which is similar to a "Shortcut" on windows. This symlink pointed to a relative path though, meaning it points to another file relative to where the symlink is currently located. Since you moved the symlink, it is now pointing to a non-existent location.

You can tell this by looking at the ls -l output; to the far left is an "l", meaning "link", instead of a "-" for regular files or a "d" for directories, and after the filename is a "->", and to the right of that is the path it points to. You can also tell it is a "relative" path because the first character of the path is not a /. The ./ refers to the current directory. You can also have symlink paths like "linkname -> folder1/" which would point to folder1 in the current directory. An absolute path would be like "linkname -> /path/to/folder1/" which specifies the entire path leading up to the location.

To fix this, you can first run rm /home/coolcatgbk. If it is actually a directory, "rm" without the "-r" argument will not delete anything. On CentOS, unless you changed something, it will also prompt you like "rm: remove symbolic link '/home/coolcatgbk"? You can can then run

ln -s /old/path/cdomainname.com/public_html/ /home/coolcatgbk

You will have to replace "/old/path" in that command with the location you were at when you ran [root@server coolcatg]# cp -R public_html /home/coolcatgbk above.

Also, as Señor CMasMas mentioned in a comment, moving directories around without being familiar with very basics like this is pretty risky, even as a non-root user. I hope this is non-critical stuff, and you have backups.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .