[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

symbolic links for directories

Posted on 2005-05-03
12
Medium Priority
?
375 Views
Last Modified: 2010-04-22
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.
0
Comment
Question by:rblampain
  • 5
  • 4
  • 2
  • +1
12 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13925011
cd /home/thoseusers
ln -s thislongdirectoryname aa
ln -s thislongdirectoryname/thatdirname ab
ln -s thislongdirectoryname/thatdirname/another_directory ac
0
 
LVL 3

Assisted Solution

by:joju
joju earned 300 total points
ID: 13936118
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
 
LVL 3

Expert Comment

by:joju
ID: 13936137
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Assisted Solution

by:stefan73
stefan73 earned 300 total points
ID: 13937357
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
 

Author Comment

by:rblampain
ID: 13943169
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
 

Author Comment

by:rblampain
ID: 13949708
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
 
LVL 51

Accepted Solution

by:
ahoffmann earned 900 total points
ID: 13950028
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
 

Author Comment

by:rblampain
ID: 13950513
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13950880
> .. 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
 

Author Comment

by:rblampain
ID: 13953614
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13954377
> .. only through programs ..
you have to implement a table per user which maps the short to long names into these programs
0
 

Author Comment

by:rblampain
ID: 13957279
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question