SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
There may be a restriction on user number in /etc/profile.d/colorls.[your shell here]. (Which is where the alias is defined). It's worth having a look. I'm not sure why this is done.
Where is the file .bashrc or .profile for root user?
There is no such files in /etc or /home/user
which ls for normal user: /usr/bin/ls
which ls for root user: /bin/ls
They would be in root's home directory. If you type "cd" as root it will take you to root's home directory (usually /root). Typically you wouldn't want root's home in /home because that is often a separate mount and you want to be able to access root even if other things aren't working in singlle user mode.
The files are simply text files. If you aren't familiar with them then you probably want to look for and go through a bash tutorial (there many on the internet) before you try anything. You do NOT want to make your root account unusable.
They would be in root's home directory. If you type "cd" as root it will take you to root's home directory (usually /root). Typically you wouldn't want root's home in /home because that is often a separate mount and you want to be able to access root even if other things aren't working in singlle user mode.
The files are simply text files. If you aren't familiar with them then you probably want to look for and go through a bash tutorial (there many on the internet) before you try anything. You do NOT want to make your root account unusable.
No file named .bashrc or .profile in /root.
There is a file named "profile" in /etc.
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810
Rep:
Quote:
That works,but is there any other way to run as root with a login shell?
Well just logging in as root runs the login shell but the su utility is not meant to run a login shell unless the "-" argument is supplied. You could just set an alias in your /etc/profile so it was set for all users. Set it like this :
Code:
alias su="su -"
and su will run a login shell when it's ran. This may not always be what you want though so beware. It's the aliases that the login shell gives - this one being relevant :
Code:
ls='/bin/ls $LS_OPTIONS'
These are only set when /etc/profile is called by a login shell which in turn runs /etc/profile.d/coreutils-dircolors.sh which sets the aliases for dir colours.
Personally I just use "su -" when i want root's environment to be pure (as a login shell) but if you really want to shorten this the first supplied alias will do in which case running "su -" will have the opposite effect than normal running the interactive shell.
No file named .bashrc or .profile in /root.
There is a file named "profile" in /etc.
Well as I said they're simple text files - you can create then with vi, emacs or other editors.
/etc/profile and /etc/bashrc affect all users whereas .profile and .bashrc in a user's home directory only affect that user. That is to say /etc/profile and /etc/bashrc do global settings (assuming you're using bash) whereas .profile and .bashrc are specific only to the single user.
When you type "su <user>" you're saying - switch user without invoking his environment. When you type "su - <user>" you are saying switch user and invoke his environment. There are various things that might be set for a specific user that might not be set for other users - for example the PATH variable used by root is often different than that for users simply because the commands root can use are broader than those end users can use.
Sorry about the resurrection. However, you sure this is not how it works? I figured, since I suddenly had problems that 'ls' did not give any colors in my user shell. The shell itself looked pretty mush like BASH though, and when I looked up the $SHELL variable it return BASH, so I was very well on the right shell. After one additional launch (by simply typing 'bash') I suddenly had colors in 'ls'. After 'exit', I -- once again -- had no colors. I could not find the logic here. I had the default .bashrc file in my home directory. Then I recalled that I had lately written a simple ~/.bash_profile with a couple of lines. I simply tried removing this file, and then re-logged. Now, colors were showing correctly. How do you explain this? Should I perhaps make a new thread for this issue? Like I said, I got it figured, and by simply adding my log on lines to the end of .bashrc (instead of .bash_profile), I have it solved. I'm just trying to find out what's popping under the hood here.
What you describe is exactly the opposite of the default behaviour that you will see in Slackware. Slackware sets the colour ls alias from a file in /etc/profile.d which means it won't be available to any non-login shells that you launch from the command line. I don't know which distro you're using or how its profiles are written, so I can't guess why you're seeing what you are, but I can tell you how it is supposed to work:
Depending on whether it is started as a login shell or not, bash will either run /etc/profile (~/.bash_profile, ~/.profile, etc.) or ~/.bashrc. The existence of .~/.bash_profile has no bearing on whether .bashrc will run or not. All that matters is whether the shell is a login shell or not, and bash will run one or the other depending on that alone.
What I like to do is have a ~/.bash_profile that does this:
Code:
case $- in
*i* ) # Interactive shell
if [ -f ~/.bashrc ]; then
source ~/.bashrc
fi
;;
esac
... which will ensure that any aliases, functions or variables I define in my .bashrc also take effect in login shells (which would normally only run the profile files and ignore .bashrc)
If you want to go to the horse's mouth, have a read of the "INVOCATION" section of the bash man-page.
P.S.
$SHELL isn't a reliable way of determining what the current shell is.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.