LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 10-30-2008, 06:07 PM   #1
xoxox
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Rep: Reputation: 0
.bashrc help


Hi,

Im having quite of a bit of trouble with this one.

so far i have done:

find / -name .bashrc

to display all the .bashrc files on the system

-How can i tell which one ( if not all ) of these files modify the PS1 varaible?

Im guessing that the output is displaying the full path name. Although most paths have permission denied.

-What command can i use to display the file protection?

-When i redirect the output to an emacs file i only the /home entries


Again, all .bashrc files on the system and need the file protection and to redirect all of the output to a file.

Hints are appreciated.
 
Old 10-30-2008, 06:19 PM   #2
abolishtheun
Member
 
Registered: Mar 2008
Posts: 183

Rep: Reputation: 31
you can use grep for, say, "PS1=" to check if the PS1 variable is changed. and you must have permission to any file you read... so run the command as root or something.
 
Old 10-30-2008, 06:41 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Expanding on the above, the only place a .bashrc file should exist is in the /home dirs. Its a user specific/customisable file, along with .bash_profile.
To show perms use
ls -l
 
Old 10-30-2008, 07:13 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by xoxox View Post
Hi,

Im having quite of a bit of trouble with this one.

so far i have done:

find / -name .bashrc

to display all the .bashrc files on the system

-How can i tell which one ( if not all ) of these files modify the PS1 varaible?
I'll respond with a quote from `man bash` (see that man page -search for "INVOCATION"- for more info).

Quote:
When bash is invoked as an interactive login shell, or as a non-interactive
shell with the --login option, it first reads and executes commands from the
file /etc/profile, if that file exists. After reading that file, it looks
for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads
and executes commands from the first one that exists and is readable. The
--noprofile option may be used when the shell is started to inhibit this
behavior.

When a login shell exits, bash reads and executes commands from the file
~/.bash_logout, if it exists.

When an interactive shell that is not a login shell is started, bash reads
and executes commands from ~/.bashrc, if that file exists. This may be
inhibited by using the --norc option. The --rcfile file option will force
bash to read and execute commands from file instead of ~/.bashrc.
Quote:
Im guessing that the output is displaying the full path name. Although most paths have permission denied.
Yep.

Quote:
-What command can i use to display the file protection?
If you mean, to see the permissions of the file, use ls -l which will display all the info. The permissions are the first thing on each row.

Quote:
-When i redirect the output to an emacs file i only the /home entries
Dunno what do you mean by "emacs file". Maybe it's a plain text file that you open in emacs(?), but in any case, all the output except maybe the errors should be redirected into the file. To output everything you can add ">myfile 2>&1" instead of just ">myfile".
 
Old 10-30-2008, 07:43 PM   #5
xoxox
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
I need to add the protection to the " find / -name .bashrc " output

ls -lha .bashrc gives me the protection of the .bashrc file but not every .bashrc file on the system.

is there some way to link these commands together?


And the redirection worked nicely.
 
Old 10-30-2008, 07:51 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
I answered a similar question here today:

http://www.linuxquestions.org/questi...ight=stat+find

However, why do you want to do so? Did you read the fragment of the man page I gave you? You will find .bashrc only on the home directory of your users, and nowhere else. And only the one for the current active user is relevant for you. I don't know what do you expect to find.
 
Old 10-30-2008, 08:00 PM   #7
xoxox
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
lol neither do i.

but i want to get this right.

How do i know that any of these files modify the PS1 varaible?


i understand the ls -l all the files in my home directory

but insted of my /home the .bashrc files insted
 
Old 10-30-2008, 08:09 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
There is only one hidden .bashrc file in each user's home dir.
To see it, use
ls -a

if you want perms as well

ls -la

You can check for PS1 being set using grep

grep PS1 .bashrc
 
Old 10-30-2008, 08:29 PM   #9
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by xoxox View Post
lol neither do i.
Hehehe, well, right. Then it's time to learn, no one is born knowing everything.

Everything you need to know is in that bit of info I pasted from the bash man page. However, since I have some spare time right now I will explain it a bit better for you.

You can consider /etc/profile like kind of a global bash configuration file. You shouldn't ever need to change it, unless you know what you are doing (and in that case, you wouldn't be asking here).

So, that leaves one less option. For the rest...

If you login on text mode, in a pure text console outside X, then bash will be in login mode (easy to understand). In login mode, bash reads one and only one amongst these files: ~/.bash_profile, ~/.bash_login, and ~/.profile. Bash looks for them in that same order, and only the first one found is used, even if it's an empty file (as long as you have read permissions over them).

If you didn't log in text mode, then you will be accessing bash using an xterm or a similar terminal emulator (konsole, gnome-terminal, urxvt or whatever). Then bash is in non-login mode. In this case, the relevant file is ~/.bashrc.

So, there you are: that's the info you need. If you want to change the value of PS1, just put it in the right file, and it will work. If these files do not exist, just create them using a regular text editor and make sure you name them correctly, starting with a dot.
 
Old 10-30-2008, 08:34 PM   #10
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Since you're using the find command, consider using the -exec grep -H PS1 {} option to implement Chris' suggestion. (You will, of course, need to prepend the find with a sudo or su -c, or just run in a root shell.)
 
Old 10-30-2008, 09:39 PM   #11
xoxox
LQ Newbie
 
Registered: Oct 2008
Posts: 4

Original Poster
Rep: Reputation: 0
i found a simlar command:

find . -type f | xargs grep .bashrc


But im not sure if these files modify the PS1 varaible. LOL

And the files are mostly bash_history
 
Old 10-30-2008, 10:04 PM   #12
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: Slackware®
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Hi,

I'm not sure as to your reasoning but if you would read the 'man bash' then things may clear up.

Code:
excerpt 'man bash';

 When bash is invoked as an interactive login shell, or as a  non-inter-
       active  shell with the --login option, it first reads and executes com-
       mands from the file /etc/profile, if that file exists.   After  reading
       that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
       in that order, and reads and executes commands from the first one  that
       exists  and  is  readable.  The --noprofile option may be used when the
       shell is started to inhibit this behavior.

       When a login shell exits, bash reads and  executes  commands  from  the
       file ~/.bash_logout, if it exists.

       When  an  interactive  shell that is not a login shell is started, bash
       reads and executes commands from ~/.bashrc, if that file exists.   This
       may  be inhibited by using the --norc option.  The --rcfile file option
       will force bash to read and  execute  commands  from  file  instead  of
       ~/.bashrc.
Below is an example of a '.bashrc' that I use on my systems. Very useful for the user. I really don't see the need to modify the 'PS1=' within '.bashrc' system wide. What is your reasoning?

Code:
#.bashrc
#08-30-06 12:17 gws copied loki:/home/gws
# Add bin to path
export PATH="$PATH:$HOME/bin"

# Dynamic resizing
shopt -s checkwinsize

# Custom prompt
#
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

#08-29-06 11:40 gws

#if [ `id -un` = root ]; then
#  PS1='\[\033[1;31m\]\h:\w\$\[\033[0m\] '
# else
#  PS1='\[\033[1;32m\]\h:\w\$\[\033[0m\] '
#fi
#
# Add color
eval `dircolors -b`

# User defined aliases
alias cls='clear'
alias clls='clear; ls'
alias ll='ls -l'
alias lsa='ls -A'
alias lsg='ls | grep'
alias na='nano'
alias web='links -g -download-dir ~/ www.google.com'

#08-29-06 11:45 gws
#To clean this up and cover your tracks once you log off

#Depending on your version of BASH, you might have to use
# the other form of this command
  trap "rm -f ~$LOGNAME/.bash_history" 0

#The older KSH-style form
#  trap 0 rm -f ~$LOGNAME/.bash_history
Notice the '.bash_profile';

Code:
# .bash_profile
#08-30-06 12:18 copied loki:/home/gws

# Source .bashrc
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
.bashrc help please... have a look. abovenbeyond Linux - Server 3 03-07-2008 04:20 PM
Setting path: /etc/profile, /etc/bashrc or ~/.bashrc Swakoo Linux - General 1 08-07-2007 10:59 PM
bashrc ovince Programming 1 04-24-2007 02:27 AM
bashrc nobu Slackware 6 03-21-2003 10:53 AM
.bashrc prasad Linux - General 1 04-14-2001 09:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration