rblampain
asked on
symbolic links for directories
I am writing scripts for an application that needs a table translation for paths, I'd like to use symbolic links if its possible, here is the problem:
A small group of users may use paths as follows:
/home/thoseusers/thislongd irectoryna me/thatdir name/anoth er_directo ry/etc
For manageability, all those directories have a 2 character name (aa, ab, ac etc) and either a translation table is necessary or symbolic links but I am not too sure if I can use symbolic links. In the example above the directory names should translate like this:
/home/ ---> /home/
~/thoseusers/ ---> ~/thoseusers/
~/thislongdirectoryname/ ---> ~/aa/ (or any other 2 character combination)
~/thatdirname/ ---> ~/aa/ (or any other 2 character combination)
~/another_directory/ ---> ~/aa/ (or any other 2 character combination)
Question: Is it suitable to use symbolic links in this case or is there a better way?
Thank you for your help.
A small group of users may use paths as follows:
/home/thoseusers/thislongd
For manageability, all those directories have a 2 character name (aa, ab, ac etc) and either a translation table is necessary or symbolic links but I am not too sure if I can use symbolic links. In the example above the directory names should translate like this:
/home/ ---> /home/
~/thoseusers/ ---> ~/thoseusers/
~/thislongdirectoryname/ ---> ~/aa/ (or any other 2 character combination)
~/thatdirname/ ---> ~/aa/ (or any other 2 character combination)
~/another_directory/ ---> ~/aa/ (or any other 2 character combination)
Question: Is it suitable to use symbolic links in this case or is there a better way?
Thank you for your help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
added some changes
count1=0
count2=0
count3=0
for i in `ls /home`
do
cd /home/$i
for j in `ls`
do
ln -s $j a$count1
count1=`expr $count1 + 1`
cd $j
for k in `ls`
do
ln -s $k b$count2
count2=`expr $count2 + 1`
cd $k
for l in `ls`
do
ln -s $k c$count3
count3=`expr $count3 + 1`
done
cd ..
done
cd ..
done
cd ..
done
count1=0
count2=0
count3=0
for i in `ls /home`
do
cd /home/$i
for j in `ls`
do
ln -s $j a$count1
count1=`expr $count1 + 1`
cd $j
for k in `ls`
do
ln -s $k b$count2
count2=`expr $count2 + 1`
cd $k
for l in `ls`
do
ln -s $k c$count3
count3=`expr $count3 + 1`
done
cd ..
done
cd ..
done
cd ..
done
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you all. stefan73's solution seems to be what I needed, I'll try it within the next few days and come back ASAP.
ASKER
Thanks to ahoffmann for the good examples.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -- -------------------------- ---------- ---------- -
To joju:
Your script would be very handy if there was a lot of directory names to be "translated' but each has only to be translated when a user creates it (according to the user's needs).
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -- -------------------------- ---------- ---------- -
To stefan73:
I still have to get a good understanding of "export", I think it simply makes whatever is "exported" available. Please correct me if I'm wrong.
If I understand your example correctly, it is basically what I need except it is the other way round. In my case, all the users will know is the names that they have given to a number of directories and files, this will be the "names_that_are_too_long" and these names will refer to real directories whose real names will be a 2 character string, for example the user may enter /home/thoseusers/long_dire ctory/my_t op_directo ry/my_midd le_directo ry/last_di rectory/my _very_best _fite.txt
and this should bring the following file:
/home/thoseusers/a1/bf/F5/ 6t/zZ.txt
I tried to adapt your example to suit my needs but I don't know enough and didn't succeed. Here is what I've done:
(my home directory is /home/rene/)
I created /home/essai/aa/ as "su"
exited "su"
export aa=/home/essai/some_long_p ath_name
/home/essai/$ cd $some_long_path_name
/home/rene/$
(the command cd $some_long_path_name returned me to /home/rene/)
Can you show me the appropriate code?
--------------------------
To joju:
Your script would be very handy if there was a lot of directory names to be "translated' but each has only to be translated when a user creates it (according to the user's needs).
--------------------------
To stefan73:
I still have to get a good understanding of "export", I think it simply makes whatever is "exported" available. Please correct me if I'm wrong.
If I understand your example correctly, it is basically what I need except it is the other way round. In my case, all the users will know is the names that they have given to a number of directories and files, this will be the "names_that_are_too_long" and these names will refer to real directories whose real names will be a 2 character string, for example the user may enter /home/thoseusers/long_dire
and this should bring the following file:
/home/thoseusers/a1/bf/F5/
I tried to adapt your example to suit my needs but I don't know enough and didn't succeed. Here is what I've done:
(my home directory is /home/rene/)
I created /home/essai/aa/ as "su"
exited "su"
export aa=/home/essai/some_long_p
/home/essai/$ cd $some_long_path_name
/home/rene/$
(the command cd $some_long_path_name returned me to /home/rene/)
Can you show me the appropriate code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
To ahoffmann:
Nobody said your solution doesn't work, I'm pretty sure it does work and works well. I know you know your stuff.
The intention is to allow the users to access directories and files according to the names a user has given to the directories and files and give the directories and files a second name, as short as possible, to suit a logging program. If this logging program had to accept user made names, the log files would simply be enormous since each record logged need to show the full path.
At this stage, I know we can use symbolic links (ln -s), the drawback could be the number of them to administer for thousands of files in thousands of directories and this is why I want to familiarize myself a bit with stefan73's solution which could be easier to administer.
I'm a long way ahead as this will only be used in some time yet and we're not sure about the specs yet. My gut feeling is that the 2 solutions will have advantages and disadvantages, perhaps we'll have to use both. It's likely I'll have to split the points.
So please be patient for a few days, I'm learning more than I'm judging solutions.
Nobody said your solution doesn't work, I'm pretty sure it does work and works well. I know you know your stuff.
The intention is to allow the users to access directories and files according to the names a user has given to the directories and files and give the directories and files a second name, as short as possible, to suit a logging program. If this logging program had to accept user made names, the log files would simply be enormous since each record logged need to show the full path.
At this stage, I know we can use symbolic links (ln -s), the drawback could be the number of them to administer for thousands of files in thousands of directories and this is why I want to familiarize myself a bit with stefan73's solution which could be easier to administer.
I'm a long way ahead as this will only be used in some time yet and we're not sure about the specs yet. My gut feeling is that the 2 solutions will have advantages and disadvantages, perhaps we'll have to use both. It's likely I'll have to split the points.
So please be patient for a few days, I'm learning more than I'm judging solutions.
> .. the names a user has given to the directories and files ..
so the long names are in the user's responsibility?
> ..and give the directories and files a second name, as short as possible,
and the system automatically uses such short names when dirs and files are created or accessed?
At first glance this sounds a bit strange.
If it's the user's responsibility only, then aliases or symbolic links should do the trick.
But if the systems uses the short names only, then you need some kind of wrapper for all the user's commands and actions which uses a table mapping short to long names for each user.
Is this what you want? Or do I miss something?
so the long names are in the user's responsibility?
> ..and give the directories and files a second name, as short as possible,
and the system automatically uses such short names when dirs and files are created or accessed?
At first glance this sounds a bit strange.
If it's the user's responsibility only, then aliases or symbolic links should do the trick.
But if the systems uses the short names only, then you need some kind of wrapper for all the user's commands and actions which uses a table mapping short to long names for each user.
Is this what you want? Or do I miss something?
ASKER
To ahoffmann:
Your interpretation is correct. It is strange - because we found no suitable existing logging system and have to create our own.
Despite what may appear, the users involved have very restricted access to "their" files, so far only through programs which obviously perform pre-allowed operations. Outside of those programs the files and directories are permanently RO and the owner is not the user. The long names mentioned are only kept to make it easy for those users to work with "their" material.
We're a Not-For-Profit and I've found almost everything we do is unusual or sometimes the opposite of what one would expect.
Hope this is helpful.
Your interpretation is correct. It is strange - because we found no suitable existing logging system and have to create our own.
Despite what may appear, the users involved have very restricted access to "their" files, so far only through programs which obviously perform pre-allowed operations. Outside of those programs the files and directories are permanently RO and the owner is not the user. The long names mentioned are only kept to make it easy for those users to work with "their" material.
We're a Not-For-Profit and I've found almost everything we do is unusual or sometimes the opposite of what one would expect.
Hope this is helpful.
> .. only through programs ..
you have to implement a table per user which maps the short to long names into these programs
you have to implement a table per user which maps the short to long names into these programs
ASKER
To ahoffmann: outside of the programs, the files are still world readable through the long names and the tables wouldn't solve that problem. My last comment lacks clarity on this aspect.
I understand, as I mentioned before, our problems are always out of the conventional and put the experts off balance in one way or another. I think you people have given enough clues as to how to tackle the problem and I think each has proposed something that we can make use of so I hope you will find the splitting of the points fair to all. I've done this on the basis of your involvment.
I understand, as I mentioned before, our problems are always out of the conventional and put the experts off balance in one way or another. I think you people have given enough clues as to how to tackle the problem and I think each has proposed something that we can make use of so I hope you will find the splitting of the points fair to all. I've done this on the basis of your involvment.
ln -s thislongdirectoryname aa
ln -s thislongdirectoryname/that
ln -s thislongdirectoryname/that