• Post Reply Bookmark Topic Watch Topic
  • New Topic

Usage of "ln -sf"  RSS feed

 
swathi bairu
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a file Accounts-TEST.xml in /www/inf/xxxx/config. My java code is referring to this file as Accounts.xml. I am running my java class from a shell script, and this shell script is being run by another test shell script. I used "ln -sf" command to create Accounts.xml file with Accounts-TEST.xml file contents transferred to it and removing Accounts-TEST.xml. After running the script, Accounts.xml file gets deleted by transferring all its contents back to Accounts-TEST.xml file. But this is not working. It is deleting both the files when I run this script. Please suggest.
testScript.sh
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things -- I think you have a misunderstanding of what the link command does, and it looks like you are using it incorrectly.

The link command does not transfer/copy contents from one file to another, it creates a named link to an existing file.

The syntax is: link  existing-file  linked-name

For your example it would look something like this:
   # ls -l /www/inf/xxxx/config/
   -rw-r--r-- 1 root root 0 Jan 12 08:49 Accounts-TEST.xml

   # ln -sf /www/inf/xxxx/config/Accounts-TEST.xml /www/inf/xxxx/config/Accounts.xml

   # ls -l /www/inf/xxxx/config/
   -rw-r--r-- 1 root root 0 Jan 12 08:49 Accounts-TEST.xml
   lrwxrwxrwx 1 root root 38 Jan 12 08:49 Accounts.xml -> /www/inf/xxxx/config/Accounts-TEST.xml

   # rm -f /www/inf/xxxx/config/Accounts.xml

   # ls -l /www/inf/xxxx/config/
   -rw-r--r-- 1 root root 0 Jan 12 08:49 Accounts-TEST.xml
 
swathi bairu
Ranch Hand
Posts: 85
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That was a clear cut explanation about the link command, and got the solution for my problem. Thank you @Ron McLeod
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!