Say I have a folder with a series of symbolic links:

ussdv103:en195d; default$  pwd
ussdv103:en195d; default$  ls -ltr
exp -> /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/exp
dpdump -> /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/dpdump
backup -> /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/backup

Then I issue the following commmands to link it to a different STREAM directory:

unlink $ORACLE_BASE/admin/database1/backup
unlink $ORACLE_BASE/admin/database1/dpdump
unlink $ORACLE_BASE/admin/database1/exp
mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/backup
mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/dpdump
mkdir -p /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/exp
ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/backup $ORACLE_BASE/admin/database1/backup
ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/dpdump $ORACLE_BASE/admin/database1/dpdump
ln -s $ORACLE_BASE/acfsmounts/global/STREAM1a/database1/exp    $ORACLE_BASE/admin/database1/exp

Then I would use the following command to copy data from the old STREAM directory to the new STREAM directory:

cp -p -r /oradba/app/oracle/acfsmounts/global/STREAM##/database1/ /oradba/app/oracle/acfsmounts/global/STREAM1a/.

But I have to replace ## so that it reflects the location of the old STREAM directory, so the command will look like this:

cp -p -r /oradba/app/oracle/acfsmounts/global/STREAM2a/database1/ /oradba/app/oracle/acfsmounts/global/STREAM1a/.

How can I capture information about the old STREAM directory before unlinking it so that my copy command automatically replaces ## with the correct location of the old STREAM directory? Is there a Unix/Linux variable I can assign the old symbolic link to and then reference that in the copy command?


Store your old file destinations in a variable using the command readlink to read link information.

OLDBACKUP=`readlink $ORACLE_BASE/admin/database1/backup`
OLDDUMP=`readlink $ORACLE_BASE/admin/database1/backup`
OLDEXP=`readlink $ORACLE_BASE/admin/database1/exp`
unlink $ORACLE_BASE/admin/database1/backup
unlink $ORACLE_BASE/admin/database1/dpdump
unlink $ORACLE_BASE/admin/database1/exp
mkdir -p $NEWBACKUP
mkdir -p $NEWDUMP
mkdir -p $NEWEXP
ln -s $NEWBACKUP $ORACLE_BASE/admin/database1/backup
ln -s $NEWDUMP $ORACLE_BASE/admin/database1/dpdump
ln -s $NEWEXP    $ORACLE_BASE/admin/database1/exp

cp -p -r $OLDEXP $NEWEXP
  • Is there anyway to parse out everything after the STREAM directory? $: OLD_STREAM=readlink $ORACLE_BASE/admin/database1/backup $: echo $OLD_STREAM $: /oradba/app/oracle/acfsmounts/global/STREAM1a/database1/backup I would like it to echo: /oradba/app/oracle/acfsmounts/global/STREAM1a/
    – etho201
    May 23 '14 at 15:13
  • I'm trying to automate that... For ease of implementation I think I should get it to echo "/oradba/app/oracle/acfsmounts/global/STREAM1a/database1/" The regular expression .*\/database1\/ will achieve this but I need to figure out how to use substrings in Linux to use that regular expression.
    – etho201
    May 23 '14 at 15:40
  • OLD_STREM=$(echo $(dirname $(dirname $OLDBACKUP)))
    – Slyx
    May 23 '14 at 15:44

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.