how to remove the target of the symbol link in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to remove the target of the symbol link in a shell script
# 1  
Old 10-11-2011
how to remove the target of the symbol link in a shell script

I have a target directory, there are some files and directories in "target_dir".

I have a symbol link: my_link -> <target_dir>

The target directory name is NOT known to the script (because it is varying), while the link name is always fixed.

In a shell script, how to remove both the symbol link and the target directory (including the target directory itself and its content) ?

Thanks.
# 2  
Old 10-11-2011
Code:
cd mylink && rm -rf *
unlink /<mylink_absolute_path>/mylink
tgt=$PWD
cd .. && rmdir $tgt

?
Maybe there are some better solutions, i haven't tried it so far.
Test it before implementing it in a script.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dollar symbol in Shell Script Variable

Hi, I am working on PGP encryption. I am getting public keys from some file. One of the key has dollar sign in it "$" Example: "abc$123" echo 'passphrase='$passphrase --> Giving correct value abc$123 But if I use $passphrase in PGP command getting Invalid passphrase error. If I... (10 Replies)
Discussion started by: Sreehari
10 Replies

2. Shell Programming and Scripting

Moving the target of a symbolic link

Hello all, On a Solaris box, I am trying to move the target of a symbolic link. Let's say the symbolic link looks like the following: /dir1/dir2/link -> /some/dir/target I would like to know of a simple way to move the target of the symbolic link and not the link itself. I'd like to move... (4 Replies)
Discussion started by: ejianu
4 Replies

3. UNIX for Dummies Questions & Answers

Shell Script for displaying the line till the target word

" Script for display sentences with special character" Hi, Could any one share a command how to display a line until my target word. For ex: My file has the content as: select * from db_wrk where col1 < col2 insert into table_name values('1','2','tst','wrk','dev','prod') My target... (10 Replies)
Discussion started by: Kalaiselvi66
10 Replies

4. Shell Programming and Scripting

$ symbol in sql query in shell script

Hi Team, Can you please help me to resolve this issue. Am unable to use this $ symbol in sql query in the shell script. For Example: # !/bin/sh export USER_NAME=XXX export PASSWORD=YYY export ORACLE_SID=xamdb echo $ORACLE_SID echo " Session Details ..." ... (1 Reply)
Discussion started by: indira_s
1 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Symbolic link not allowed or link target not accessible

Hi everybody, I read about treads realted to this issue but they did not resovle issue given below. Please help me resolve issue given below I have html file under /srv/www/htdocs/actual_folder ls actual_folder/ test.html and following link works... (0 Replies)
Discussion started by: newbielgn
0 Replies

6. Shell Programming and Scripting

How to bin/find w/ -follow without searching both link and target

I am interested in searching links to files not found within a directory, so I use the -follow option. However, the dir may contain links to files that are also found within the dir. That means if I bin/find a bunch of files then search their contents using grep, I get redundant information. An... (1 Reply)
Discussion started by: stevensw
1 Replies

7. Shell Programming and Scripting

Shell script to transfer the files from source to target server.

I need to write a shell script to transfer the files every hour from source - target server. The cron job should be running every hour and shouldn't copy already copied files to the remote server ? I was able to write intial script but not able to get the logic for (in the next run it should... (12 Replies)
Discussion started by: radhirk
12 Replies

8. UNIX for Dummies Questions & Answers

change target of a symbolic link

Hi, Is it possible to change the target of a symbolic link? What I currently have is: /home/Data1 /home/Data2 /home/Stores In the Stores directory, I did: ln -s /home/Data1 /home/Stores/abc $ pwd /home/Stores $ ls -latr lrwxrwxrwx 1 dandy dandy 46 Feb 12 16:38 abc ->... (5 Replies)
Discussion started by: dandyrandy
5 Replies

9. UNIX for Dummies Questions & Answers

ZIP a soft / symbolic link target

Hey, How can one ZIP the target of a soft/symbolic link in unix (if dodag@ is a symbolic link for the path car/reno/*.*, how can I zip car/reno/*.*, with using only dodag as my reference)? Thxnk you. (1 Reply)
Discussion started by: galz
1 Replies

10. Shell Programming and Scripting

Registered Symbol in Korn Shell script

When I am trying to write this symbol in shell script ( ® ) I am getting a . ( dot ) instead , does anybody know how to fix it. Thanks. (1 Reply)
Discussion started by: jacki
1 Replies
Login or Register to Ask a Question