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/thislongdirectoryname/thatdirname/another_directory/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.
rblampainAsked:
Who is Participating?
 
ahoffmannCommented:
this sounds like you want to access files in a hashed diretory tree, if so, why do you want to access the short names?

Could you please explain how the mapping should work:
  long_directory/my_top_directory/my_middle_directory/last_directory/my_very_best_fite.txt --> a1/bf/F5/6t/zZ.txt

I still don't see why my suggestion does not work.
stefan73' suggestion should work too, but you need to take care about the shell you use, for example:

# sh syntax:
zZ=/home/thoseusers/long_directory/my_top_directory/my_middle_directory/last_directory/my_very_best_fite.txt
export zZ
ls -l $zZ

# csh syntax:
setenv zZ /home/thoseusers/long_directory/my_top_directory/my_middle_directory/last_directory/my_very_best_fite.txt
ls -l $zZ
0
 
ahoffmannCommented:
cd /home/thoseusers
ln -s thislongdirectoryname aa
ln -s thislongdirectoryname/thatdirname ab
ln -s thislongdirectoryname/thatdirname/another_directory ac
0
 
jojuCommented:
do you need some thing like this ?


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
        done
    done
done
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jojuCommented:
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
0
 
stefan73Commented:
Hi rblampain,
> Is it suitable to use symbolic links in this case or is there a better way?
Symbolic links are OK, but your directory structure is probably easier to maintain if you use environment variables for this.

Example: Have a "prototype" account (e.g, /home/master), where you have the setup script. In each user's .login/.profile, you call this setup script, which might look like this:

export app_a_data=$HOME/some_long_path_name
mkdir -p $app_a_data
export app_b_data=$HOME/some_other_path_name
mkdir -p $app_b_data
[...]

...and the users can simply do
cd $app_a_data

The advantage is that you need to maintain only a single file, not lots of links in the users' home directories.

Cheers!

Stefan
0
 
rblampainAuthor Commented:
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.
0
 
rblampainAuthor Commented:
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_directory/my_top_directory/my_middle_directory/last_directory/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_path_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?
0
 
rblampainAuthor Commented:
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.
0
 
ahoffmannCommented:
> .. 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?
0
 
rblampainAuthor Commented:
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.
0
 
ahoffmannCommented:
> .. only through programs ..
you have to implement a table per user which maps the short to long names into these programs
0
 
rblampainAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.