Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
But ~ means "the home directory of the user", and if your distribution has made /root the home directory for the superuser, you're correct. After all you could, if you wanted to, set /var/log (just an example) to be the home directory of user foo, and then when you were logged in as foo and went to your home directory /var/log, your command prompt would show it as ~.
EDIT: the message in the above example was simply that /home/user is by no means the only place where a user can have it's homedirectory. It's up to the system admin to decide where the home directory resides.
To answer your question, as far as I know, bash does not have an escape sequence for what you're looking for. However, you could tailor it. The following is a quick and easy sample, but since it will give you the entire working directory, you might want to work on it to shorten up the return.
PS1="[\u@\h $directory]\$ "
When logged in as root and within root's home directory, this will output
(I notice you use >> rather than # to signify root. If you still want to use this, just replace the \$ with >>.)
EDIT: The above isn't correct. See my next response for the explanation...
Quick solution, instead of doing su -, do just an su. This will leave you in current working directory. By doing an su -, it reads the (in this case) roots env, and goes to roots homedir. In that case "~" = /root. If you do a su - user2, than you'll be in /home/user2. An easy redirect would be su - root, then cd ~user. You;ll now be in the /home/user directory.
And with all of the above said: you REALLY need to just change your
idea of what ~ stands for. It's "the effective users home directory"
which can be ANYWHERE in the file-system. All you need to know is that
it's "your home". Work-arounds may be all-right, but never rely on them
because there will come a time when you're at a machine you haven't set-up.
I made a mistake with my previous reply. What I had done will not work, as pwd is only getting evaluated once. This means that after you start the session, the displayed working directory will not change, regardless of where you move to in the filesystem. I tried putting the command directly into the PS1 variable, but that didn't work either. So I'm not entirely sure if you could accomplish that task manually.
However, I'm fairly certain that \W will work (it displays root for me). Are you certain that after making the change, you re-sourced your .bashrc? You can do this with either the . command or source while in your home directory:
That being said, I agree with the advice on changing your concept of ~.