A
A
Alexander2020-05-05 01:09:31
PHP
Alexander, 2020-05-05 01:09:31

How to change symbolic links to files?

Now we have to move from one domain to another, but on the same server. And every file on the site is displayed through symbolic links. I will copy the files to the new domain. Symbolic links can also, but... Naturally, they will point to the old domain. That's where the two questions come from.
1 - is it possible to massively change the names of all symbolic links not completely, but only in their site.ru names to site1.ru?
2 - Is it possible to change the domain name site.ru to site1.ru in the path to the file of each link without creating new symbolic links, or just select all 130K records from the database of files and create links from scratch?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
brar, 2020-05-05
@brar

grep -rl старое_имя_домена /путь/к/каталогу_сайта/
Lists all files containing the old domain name. If there are not enough of them, you can manually change them to a new domain name.

find /путь/к/каталогу_сайта/ -type f -exec sed -i 's/https\:\/\/старое_имя_домена.ru/https\:\/\/новое_имя_домена.ru/g' {} +

Replace all occurrences of old_domain_name with new_domain_name.
However, it is worth noting that the indication of absolute links of the site address inside the code is bad manners. You need to use relative links - or rather, just a slash. (a properly configured webserver will accept it as the correct path).
PS Do not forget the preliminary backup.

H
hint000, 2020-05-05
@hint000

I riveted this option (maybe someday it will come in handy). The first line does not contain dangerous commands, and after it you can visually check the contents of the text file.

find /каталог/где/симлинки -type l \( -exec readlink {} \; -exec echo {} \; \) |xargs -L2|sed 's/site.ru/site1.ru/g' > aaaa.txt
cat aaaa.txt|awk '{print $2}'|xargs rm
cat aaaa.txt|xargs -L1 ln -s

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question