› Forums › Basic skills › Programming › Shell scripting (in bash) › Symbolic links
- This topic has 0 replies, 1 voice, and was last updated 8 years, 9 months ago by Simon.
-
AuthorPosts
-
-
March 13, 2016 at 16:37 #2802
Sometimes it is convenient to have a file or directory in a certain place (e.g., because a script requires it to be there), but to point at a copy of that file or directory that exists elsewhere. This is sometimes a useful way to save space.
Let’s imagine we are building our own unit selection voice and we have several versions of the voice, each in its own directory, like this
Documents$ ls -l total 0 drwxr-xr-x 2 simonk staff 68 13 Mar 16:16 ss drwxr-xr-x 2 simonk staff 68 13 Mar 16:16 ss_domain drwxr-xr-x 2 simonk staff 68 13 Mar 16:17 ss_small drwxr-xr-x 2 simonk staff 68 13 Mar 16:16 ss_version_2
and that we want all of them to share some data. In the original voice that we made, in
ss
, there is the actual data in a directory calledwav
Documents$ cd ss ss$ ls -l total 0 drwxr-xr-x 2 simonk staff 68 13 Mar 16:18 wav ss$ ls wav arctic_a0001.wav arctic_a0006.wav arctic_a0002.wav arctic_a0007.wav arctic_a0003.wav arctic_a0008.wav arctic_a0004.wav arctic_a0009.wav arctic_a0005.wav arctic_a0010.wav
and we want it to look like there is also a wav directory with the same contents in each of the other voices, but without actually making a copy.
The way to do this is with a symbolic link. Let’s go into one of the other voices, which is currently empty
ss$ cd ../ss_version_2/ ss_version_2$ ls -l ss_version_2$
now we make the symbolic link
ss_version_2$ ln -s ../ss/wav .
the link looks special when we examine it
ss_version_2$ ls -l total 8 lrwxr-xr-x 1 simonk staff 9 13 Mar 16:20 wav -> ../ss/wav
and in the Finder (or the equivalent on whatever operating system you are using) it will have a little arrow added to the icon
but it behaves just like it is a directory as far as any programs or scripts are concerned
for example we can
cd
in to it (on the command line or in the Finder) and take a look at the contentsss_version_2$ cd wav horizon:wav$ pwd /Users/simonk/Documents/ss_version_2/wav wav$ ls arctic_a0001.wav arctic_a0006.wav arctic_a0002.wav arctic_a0007.wav arctic_a0003.wav arctic_a0008.wav arctic_a0004.wav arctic_a0009.wav arctic_a0005.wav arctic_a0010.wav
but any changes we make will also change the directory that we made the symbolic link to – they are the same thing.
-
-
AuthorPosts
- You must be logged in to reply to this topic.