search and replace symlinks


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users search and replace symlinks
# 1  
Old 10-17-2005
Data search and replace symlinks

Hello All,

Assuming i have a thousand symlinks under directory /mydir (and its sub-dir) such as:

mysymlink1 -> ../../../myfoo/mysymlink1
mysymlink2 -> ../../../myfoo/mysymlink2

How can I search the string "myfoo" and replaced with "yourfoo" such that after the operation is complete the /mydir will look like this:

mysymlink1 -> ../../../yourfoo/mysymlink1
mysymlink2 -> ../../../yourfoo/mysymlink2

======
Thanks!
# 2  
Old 10-19-2005
This is a little on the dangerous side to say the least. Run this script...it will produce a second script. Examine that second script carefully before you run it.
Code:
#! /usr/bin/ksh

function dodir
{
        typeset fname data savedir
        ls | while read fname ; do
                if [[ -L $fname ]] ; then
                        data=$(ls -l $fname)
                        data=${data##* }
                        data=$(echo "$data" | sed 's=myfoo=yourfoo=')
                        echo rm $1/$fname
                        echo ln -s $data $1/$fname
                elif [[ -d $fname ]] ; then
                        savedir=$(pwd)
                        cd $fname
                        dodir $savedir/$fname
                        cd $savedir
                fi
        done
        return
}

dodir $(pwd)
exit 0

# 3  
Old 10-19-2005
I'll try it out.

Thank you!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rsync move with symlinks

Hi, I use rsync to move from source to target, but there are cases that I need to exclude: Suppose in my file system, I have a soft link ~/data -> /media/volgrp/data. Under data folder, there is a file hello.txt. After moving command "rsync --remove-source-files -aH --force ~/data/... (3 Replies)
Discussion started by: huangyingw
3 Replies

2. Shell Programming and Scripting

Nested search in a file and replace the inner search

Hi Team, I am new to unix, please help me in this. I have a file named properties. The content of the file is : ##Mobile props east.url=https://qa.east.corp.com/prop/end west.url=https://qa.west.corp.com/prop/end south.url=https://qa.south.corp.com/prop/end... (2 Replies)
Discussion started by: tolearn
2 Replies

3. Shell Programming and Scripting

Find + Symlinks = me confused

So i have read the man pages a few time. Searched google but I am not quite sure i understand all the lingo. What i want to do is list all files on / except i dont want any symlinks (because if I am searching / I will find the "true" file...correct?) So there is the -P, -H, and '-type l'... (2 Replies)
Discussion started by: nitrobass24
2 Replies

4. Shell Programming and Scripting

Look for, backup and delete symlinks

Hi, My first post here: Was looking if someone can help enhancing my code. I am limited to sh or ash shell (android / busybox) I made a script to look for busybox symlinks, backup them and delete them I have these questions about the below code: - busybox tar do not has the options... (2 Replies)
Discussion started by: Phil3759
2 Replies

5. Slackware

Context dependent symlinks

Ive got multiple PCs, sharing an NFS mounted home dir. For certain apps I would like to keep the config files host specific. Easy solution is to create symlinks to local folders for configs. Ideally I would still want the .config files to reside in the user home folder. Is it possible to... (2 Replies)
Discussion started by: agentrnge
2 Replies

6. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

7. Shell Programming and Scripting

awk - replace number of string length from search and replace for a serialized array

Hello, I really would appreciate some help with a bash script for some string manipulation on an SQL dump: I'd like to be able to rename "sites/WHATEVER/files" to "sites/SOMETHINGELSE/files" within the sql dump. This is quite easy with sed: sed -e... (1 Reply)
Discussion started by: otrotipo
1 Replies

8. UNIX for Dummies Questions & Answers

Symlinks

Given a filename, is it possible to know haow many symbolic links are pointing to it? How can I tell? (1 Reply)
Discussion started by: ct1977
1 Replies

9. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

10. Shell Programming and Scripting

Nested Symlinks?

Please don't laugh or call me a fool... I'm trying to set up a script that will go through my Music File directory and generate a set of symbolic links in a directory called "What's New". Within that directory there will be a "30 Days", "3 Months", "6 Months" and "A Year" directories. Within... (0 Replies)
Discussion started by: deckard
0 Replies
Login or Register to Ask a Question