LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   question about ~directories (https://www.linuxquestions.org/questions/linux-newbie-8/question-about-%7Edirectories-489566/)

kalak 10-04-2006 11:56 PM

question about ~directories
 
How do I make a directory on my system accessable from anywhere by the ~mydirectory convention?

I'm sure its easy but I had trouble finding an answer.

thanks

rkelsen 10-05-2006 12:09 AM

you mean symlinks?

ln -s

kalak 10-05-2006 12:27 AM

yes but how do I make the link accesable from anywhere?

for example my home directory can be accessed no matter what my current direcotory is by typing

cd ~

my mysql directory can be accessed from any directory by typing

cd ~mysql

I would like a universally accessable link like that but make it something like

cd ~mydir


-Kalak

chrism01 10-05-2006 02:48 AM

cd is a bash built-in cmd, where '~' means 'home dir of specified user', default 'current user' if none specified.
To emulate that I think you'll have to write a short script and ensure it's always in a dir in your $PATH env variable.
If you get it working, post it here, as i'm sure others would like to see it.

jlliagre 10-05-2006 03:35 AM

You can achieve what you want without the "~" shell feature.

Just use the CDPATH variable, which allows cd to search for different places when a relative directory is passed.

mickyg 10-05-2006 07:27 AM

Or you could set up alias'??

Type alias at the prompt to see which you already have set-up.

kalak 10-05-2006 02:14 PM

the CDPATH solution is the closest so far, but not quite right. My CDPATH is empty yet I can still cd to ~mysql or ~vpopmail from anywhere.

anybody know the answer?

-Kalak

jlliagre 10-05-2006 02:52 PM

Quote:

Originally Posted by kalak
My CDPATH is empty yet I can still cd to ~mysql or ~vpopmail from anywhere.

Sure, that's a shell feature.

Quote:

anybody know the answer?
I'm confused, the answer to what question ?

kalak 10-06-2006 02:44 PM

Quote:

Originally Posted by jlliagre
Sure, that's a shell feature.


I'm confused, the answer to what question ?

If it's a shell feature, how do I add my own directory to it?

eg. before I installed vpopmail I could not say
> cd ~vpopmail
and get to vpopmail. So I know that it is possible to add a new "link" (I quote it because i'm not sure what call it).

how do I get a link to mydar so that it can be accessed from anywhere by
> cd ~mydir
without adding it to a system variable. ~mysql, ~vpopmail, ~games, etc. are not anywhere in the system variables.

-Kalak

jlliagre 10-06-2006 04:01 PM

Quote:

Originally Posted by kalak
If it's a shell feature, how do I add my own directory to it?

You can't, it's a shell builtin feature.
~someone means someone's homedir
Quote:


eg. before I installed vpopmail I could not say
> cd ~vpopmail
and get to vpopmail. So I know that it is possible to add a new "link" (I quote it because i'm not sure what call it).
If you want that, you still can create a user account whose name is vpopmail and whose home directory is the directory where you want to go with "cd ~vpopmail"
Quote:

how do I get a link to mydar so that it can be accessed from anywhere by
> cd ~mydir
without adding it to a system variable. ~mysql, ~vpopmail, ~games, etc. are not anywhere in the system variables.
These have nothing to do with system variables, variables start with $ not ~.

kalak 10-07-2006 02:20 AM

Quote:

Originally Posted by jlliagre
You can't, it's a shell builtin feature.
~someone means someone's homedir
If you want that, you still can create a user account whose name is vpopmail and whose home directory is the directory where you want to go with "cd ~vpopmail"

These have nothing to do with system variables, variables start with $ not ~.

Ok, so basically the solution is to create a user that can't use a shell and has a home directory of whatever dir. I want to access?

I knew cd ~username works but I never thought about that. Thanks!

-Kalak

jlliagre 10-07-2006 02:49 AM

Yes, it's a hack but that's the only way to achieve what you want.

mickyg 10-09-2006 03:52 AM

Again, why not use alias'???

At the terminal type
Code:

alias 'cd ~whatever'='cd /folder/whereever'

jlliagre 10-09-2006 10:39 AM

Quote:

Originally Posted by mickyg
Again, why not use alias'???

Probably because that doesn't work:
Code:

$ bash --version
GNU bash, version 3.00.16(1)-release (i386-pc-solaris2.11)
Copyright (C) 2004 Free Software Foundation, Inc.
$ bash
$ alias 'cd ~whatever'='cd /folder/whereever'
bash: alias: `cd ~whatever': invalid alias name



All times are GMT -5. The time now is 01:06 PM.