LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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


Closed Thread
  Search this Thread
Old 07-04-2006, 05:22 PM   #1
frz
LQ Newbie
 
Registered: Jul 2006
Location: Canada
Distribution: Mandriva!
Posts: 13

Rep: Reputation: 0
Wink .bashrc TUTORIAL for help newbie


Hi. its now doin' 1 week that I'm usin' linux (Mandriva). It's my first nix OS and i decided to edit my .bashrc. I Think i'm the first to paste a .bashrc example script . This can maybe cool to add a place on the forum just for .bashrc scripting!!! So here is my personal .bashrc

NORMAL USERs (/home/frz/.bashrc)

Quote:
# .bashrc

# User specific aliases and functions

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# Prompt konsol shell
PS1="[\u@\H \W] "


#### Perso ####
#############

# Défini les couleurs
BLACK='\e[0;30m'
BLUEF='\e[0;34m'
BLUEP='\e[1;34m'
GREENF='\e[0;32m'
GREENP='\e[1;32m'
CYANF='\e[0;36m'
CYANP='\e[1;36m'
REDF='\e[0;31m'
REDP='\e[1;31m'
PURPLEF='\e[0;35m'
PURPLEP='\e[1;35m'
BROWNF='\e[0;33m'
BROWNP='\e[1;33m'
GRAYF='\e[0;37m'
GRAYP='\e[1;37m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
NC='\e[0m' # No Color


# Message de bienvenue
clear
# Message de bienvenue
if [ "$USER" = "mathieu" ]; then
echo -e "${REDP}Welcome master. You are logged on $HOSTNAME.${NC}"
uname -a
echo ""
else
echo -e "${REDP}Welcome $USER. You are logged on $HOSTNAME.${NC}"
uname -a
echo ""
fi

# Aliases (variables)
alias home='cd /home'
alias frz='cd ~'
alias desktop='cd /home/frz/Desktop'
alias frzd='cd /home/frz/Desktop/frz'
alias lsa='ls -Al' # List all files (+hidden files)


# Functions
function cmds() # savoir mes commandes
{
echo -e "\n${REDP}Liste des commandes:"
echo -e "${GREENP} -Alias-"
echo -e "${BLUEP}aliasp: ${NC}Liste les commandes alias persos."
echo -e "\n${GREENP} -Functions-"
echo -e "${BLUEP}clog: ${NC}Clear les logs."
echo -e "${BLUEP}info: ${NC}Informations sur la session ouverte et l'ordinateur."
echo ""
}

function aliasp() #savoir mes alias
{
echo -e "\n${REDP}Liste des aliases persos:"
echo -e "${BLUEP}home: ${NC}Dossier home (~)."
echo -e "${BLUEP}frz: ${NC}Dossier frz."
echo -e "${BLUEP}desktop: ${NC}Dossier Desktop."
echo -e "${BLUEP}frzd: ${NC}Dossier frz sur le desktop."
echo -e "${BLUEP}lsa: ${NC}Liste tout les fichiers + fichiers cachés."
echo ""
}
function colors()
{
echo -e "\n${REDP}Code de couleurs:"
echo -e "${BLUEF}BLUEF ${NC}<--> ${BLUEP}BLUEP"
echo -e "${GREENF}GREENF ${NC}<--> ${GREENP}GREENP"
echo -e "${CYANF}CYANF ${NC}<--> ${CYANP}CYANP"
echo -e "${REDF}REDF ${NC}<--> ${REDP}REDP"
echo -e "${PURPLEF}PURPLEF ${NC}<--> ${PURPLEP}PURPLEP"
echo -e "${BROWNF}BROWNF ${NC}<--> ${BROWNP}BROWNP"
echo -e "${GRAYF}GRAYF ${NC}<--> ${GRAYP}GRAYP"
echo -e "${YELLOW}YELLOW"
echo -e "${WHITE}WHITE"
echo -e "${NC}NC (NO COLOR)"
echo ""
}

function info() # avoir les infos dla session ouverte et pc
{
echo -e "\nYou are logged on ${BLUEP}$HOSTNAME"
echo -e "\n${REDP}Additionnal information:$NC " ; uname -a
echo -e "\n${REDP}Users logged on:$NC " ; w -h
echo -e "\n${REDP}Current date :$NC " ; date
echo -e "\n${REDP}Machine stats :$NC " ; uptime
echo -e "\n${REDP}Memory stats :$NC " ; free
my_ip 2>&- ;
echo -e "\n${REDP}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
echo -e "\n${REDP}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}
echo ""
}


function clog() # Clear les logs
{
if [ "$UID" = "0" ]; then # 0 = level r00t
cd /var/log
cat /dev/null > messages
cat /dev/null > wtmp
echo -e "${REDP}Logs cleaned up.${NC}"
echo ""
else
echo -e "${REDP}That cmd request a r00t access.${NC}"
echo ""
fi
}
r00t bash (/root/bashrc)

Quote:
# .bashrc

PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin
ENV=$HOME/.bashrc
USERNAME="root"
export USERNAME ENV PATH

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# Prompt konsol shell
PS1="[\u@\H \W] "


#### Perso ####
#############

# Défini les couleurs
BLACK='\e[0;30m'
BLUEF='\e[0;34m'
BLUEP='\e[1;34m'
GREENF='\e[0;32m'
GREENP='\e[1;32m'
CYANF='\e[0;36m'
CYANP='\e[1;36m'
REDF='\e[0;31m'
REDP='\e[1;31m'
PURPLEF='\e[0;35m'
PURPLEP='\e[1;35m'
BROWNF='\e[0;33m'
BROWNP='\e[1;33m'
GRAYF='\e[0;37m'
GRAYP='\e[1;37m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
NC='\e[0m' # No Color


# Message de bienvenue
if [ "$UID" = "0" ]; then
echo -e "${REDP}Your are not logged as r00t on $HOSTNAME.${NC}"
uname -a
echo ""
else
echo -e "${REDP}Welcome $USER. You are logged on $HOSTNAME.${NC}"
uname -a
echo ""
fi

# Aliases (variables)
alias home='cd /home'
alias frz='cd ~'
alias desktop='cd /home/frz/Desktop'
alias frzd='cd /home/frz/Desktop/frz'
alias lsa='ls -Al' # List all files (+hidden files)


# Functions
function cmds() # savoir mes commandes
{
echo -e "\n${REDP}Liste des commandes:"
echo -e "${GREENP} -Alias-"
echo -e "${BLUEP}aliasp: ${NC}Liste les commandes alias persos."
echo -e "\n${GREENP} -Functions-"
echo -e "${BLUEP}clog: ${NC}Clear les logs."
echo -e "${BLUEP}info: ${NC}Informations sur la session ouverte et l'ordinateur."
echo ""
}

function aliasp() #savoir mes alias
{
echo -e "\n${REDP}Liste des aliases persos:"
echo -e "${BLUEP}home: ${NC}Dossier home (~)."
echo -e "${BLUEP}frz: ${NC}Dossier frz."
echo -e "${BLUEP}desktop: ${NC}Dossier Desktop."
echo -e "${BLUEP}frzd: ${NC}Dossier frz sur le desktop."
echo -e "${BLUEP}lsa: ${NC}Liste tout les fichiers + fichiers cachés."
echo ""
}
function colors()
{
echo -e "\n${REDP}Code de couleurs:"
echo -e "${BLUEF}BLUEF ${NC}<--> ${BLUEP}BLUEP"
echo -e "${GREENF}GREENF ${NC}<--> ${GREENP}GREENP"
echo -e "${CYANF}CYANF ${NC}<--> ${CYANP}CYANP"
echo -e "${REDF}REDF ${NC}<--> ${REDP}REDP"
echo -e "${PURPLEF}PURPLEF ${NC}<--> ${PURPLEP}PURPLEP"
echo -e "${BROWNF}BROWNF ${NC}<--> ${BROWNP}BROWNP"
echo -e "${GRAYF}GRAYF ${NC}<--> ${GRAYP}GRAYP"
echo -e "${YELLOW}YELLOW"
echo -e "${WHITE}WHITE"
echo -e "${NC}NC (NO COLOR)"
echo ""
}

function info() # avoir les infos dla session ouverte et pc
{
echo -e "\nYou are logged on ${BLUEP}$HOSTNAME"
echo -e "\n${REDP}Additionnal information:$NC " ; uname -a
echo -e "\n${REDP}Users logged on:$NC " ; w -h
echo -e "\n${REDP}Current date :$NC " ; date
echo -e "\n${REDP}Machine stats :$NC " ; uptime
echo -e "\n${REDP}Memory stats :$NC " ; free
my_ip 2>&- ;
echo -e "\n${REDP}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
echo -e "\n${REDP}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}
echo ""
}

function clog() # Clear les logs
{
if [ "$UID" = "0" ]; then # 0 = level r00t
cd /var/log
cat /dev/null > messages
cat /dev/null > wtmp
echo -e "${REDP}Logs cleaned up.${NC}"
echo ""
else
echo -e "${REDP}That cmd request a r00t access.${NC}"
echo ""
fi
}
You can also make just one bashrc with more if, elif, then, else in the /etc/ U must change the welcome message! Example:

Quote:
# /etc/bashrc

# System wide functions and aliases
# Environment stuff goes in /etc/profile

# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
umask 002
else
umask 022
fi

# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
;;
*)
;;
esac
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "

if [ -z "$loginsh" ]; then # We're not a login shell
# Not all scripts in profile.d are compatible with other shells
# TODO: make the scripts compatible or check the running shell by
# themselves.
if [ -n "${BASH_VERSION}${KSH_VERSION}${ZSH_VERSION}" ]; then
for i in /etc/profile.d/*.sh; do
if [ -x $i ]; then
. $i
fi
done
fi
fi
fi

unset loginsh


##################
### bashrc perso ###
##################
# Défini les couleurs
BLACK='\e[0;30m'
BLUEF='\e[0;34m'
BLUEP='\e[1;34m'
GREENF='\e[0;32m'
GREENP='\e[1;32m'
CYANF='\e[0;36m'
CYANP='\e[1;36m'
REDF='\e[0;31m'
REDP='\e[1;31m'
PURPLEF='\e[0;35m'
PURPLEP='\e[1;35m'
BROWNF='\e[0;33m'
BROWNP='\e[1;33m'
GRAYF='\e[0;37m'
GRAYP='\e[1;37m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
NC='\e[0m' # No Color

# Message de bienvenue
if [ "$UID" = "0" ]; then
echo -e "${REDP}You are not logged as r00t on $HOSTNAME.${NC}"
echo ""
elif [ "$USER" = "mathieu" ]; then
echo -e "${REDP}Welcome master. You are logged on $HOSTNAME.${NC}"
uname -a
echo ""
else
echo -e "${REDP}Welcome $USER. You are logged on $HOSTNAME.${NC}"
uname -a
echo ""
fi

# Aliases (variables)
alias home='cd /home'
alias frz='cd ~'
alias desktop='cd /home/frz/Desktop'
alias frzd='cd /home/frz/Desktop/frz'
alias lsa='ls -Al' # List all files (+hidden files)


# Functions
function cmds() # savoir mes commandes
{
echo -e "\n${REDP}Liste des commandes:"
echo -e "${GREENP} -Alias-"
echo -e "${BLUEP}aliasp: ${NC}Liste les commandes alias persos."
echo -e "\n${GREENP} -Functions-"
echo -e "${BLUEP}clog: ${NC}Clear les logs."
echo -e "${BLUEP}info: ${NC}Informations sur la session ouverte et l'ordinateur."
echo ""
}

function aliasp() #savoir mes alias
{
echo -e "\n${REDP}Liste des aliases persos:"
echo -e "${BLUEP}home: ${NC}Dossier home (~)."
echo -e "${BLUEP}frz: ${NC}Dossier frz."
echo -e "${BLUEP}desktop: ${NC}Dossier Desktop."
echo -e "${BLUEP}frzd: ${NC}Dossier frz sur le desktop."
echo -e "${BLUEP}lsa: ${NC}Liste tout les fichiers + fichiers cachés."
echo ""
}
function colors()
{
echo -e "\n${REDP}Code de couleurs:"
echo -e "${BLUEF}BLUEF ${NC}<--> ${BLUEP}BLUEP"
echo -e "${GREENF}GREENF ${NC}<--> ${GREENP}GREENP"
echo -e "${CYANF}CYANF ${NC}<--> ${CYANP}CYANP"
echo -e "${REDF}REDF ${NC}<--> ${REDP}REDP"
echo -e "${PURPLEF}PURPLEF ${NC}<--> ${PURPLEP}PURPLEP"
echo -e "${BROWNF}BROWNF ${NC}<--> ${BROWNP}BROWNP"
echo -e "${GRAYF}GRAYF ${NC}<--> ${GRAYP}GRAYP"
echo -e "${YELLOW}YELLOW"
echo -e "${WHITE}WHITE"
echo -e "${NC}NC (NO COLOR)"
echo ""
}

function info() # avoir les infos dla session ouverte et pc
{
echo -e "\nYou are logged on ${BLUEP}$HOSTNAME"
echo -e "\n${REDP}Additionnal information:$NC " ; uname -a
echo -e "\n${REDP}Users logged on:$NC " ; w -h
echo -e "\n${REDP}Current date :$NC " ; date
echo -e "\n${REDP}Machine stats :$NC " ; uptime
echo -e "\n${REDP}Memory stats :$NC " ; free
my_ip 2>&- ;
echo -e "\n${REDP}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
echo -e "\n${REDP}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}
echo ""
}


function clog() # Clear les logs
{
if [ "$UID" = "0" ]; then # 0 = level r00t
cd /var/log
cat /dev/null > messages
cat /dev/null > wtmp
echo -e "${REDP}Logs cleaned up.${NC}"
echo ""
else
echo -e "${REDP}That cmd request a r00t access.${NC}"
echo ""
fi
}
 
Old 07-05-2006, 01:13 AM   #2
DaneM
Member
 
Registered: Oct 2003
Location: Chico, CA, USA
Distribution: Linux Mint
Posts: 881

Rep: Reputation: 130Reputation: 130
Great scripts!

Perhaps these should go under Tutorials?

--Dane
 
Old 07-05-2006, 02:10 AM   #3
frz
LQ Newbie
 
Registered: Jul 2006
Location: Canada
Distribution: Mandriva!
Posts: 13

Original Poster
Rep: Reputation: 0
Wink Lol

Quote:
Originally Posted by DaneM
Great scripts!

Perhaps these should go under Tutorials?

--Dane
Of course.. n00bs can learn A LOT with that on bashrc files dude.
 
Old 07-05-2006, 04:31 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Of course.. n00bs can learn A LOT with that on bashrc files dude.
Yeah. Like this:

Code:
function clog() # Clear les logs
{
if [ "$UID" = "0" ]; then # 0 = level r00t
cd /var/log
cat /dev/null > messages
cat /dev/null > wtmp
- Who "invented" this function or what distribution ships this as "standard"?
- Why do you think would zeroeing out logs and records be "better" than using standard logrotate utility?
 
Old 07-05-2006, 11:52 AM   #5
frz
LQ Newbie
 
Registered: Jul 2006
Location: Canada
Distribution: Mandriva!
Posts: 13

Original Poster
Rep: Reputation: 0
Thumbs down

Quote:
Originally Posted by unSpawn
Of course.. n00bs can learn A LOT with that on bashrc files dude.
Yeah. Like this:

Code:
function clog() # Clear les logs
{
if [ "$UID" = "0" ]; then # 0 = level r00t
cd /var/log
cat /dev/null > messages
cat /dev/null > wtmp
- Who "invented" this function or what distribution ships this as "standard"?
- Why do you think would zeroeing out logs and records be "better" than using standard logrotate utility?
What are you saying?, i posted that to look better with others merits, and you're telling people that publicly?

Last edited by Tinkster; 07-06-2006 at 01:43 AM.
 
Old 07-05-2006, 12:27 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
What are you saying?, i posted that to look better with others merits, and you're telling people that publicly?
What kind of answer is that?

Last edited by Tinkster; 07-06-2006 at 01:47 AM.
 
Old 07-05-2006, 12:57 PM   #7
frz
LQ Newbie
 
Registered: Jul 2006
Location: Canada
Distribution: Mandriva!
Posts: 13

Original Poster
Rep: Reputation: 0
Thumbs down

I seriously apologise an promise not to show disrespect to mods again!

Last edited by Tinkster; 07-06-2006 at 01:44 AM.
 
Old 07-05-2006, 01:19 PM   #8
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Sorry unspawn ...
Oh, now I see, it's from an ABS example...
BTW, you where talking to, who?

Last edited by Tinkster; 07-06-2006 at 01:46 AM.
 
Old 07-05-2006, 02:35 PM   #9
frz
LQ Newbie
 
Registered: Jul 2006
Location: Canada
Distribution: Mandriva!
Posts: 13

Original Poster
Rep: Reputation: 0
Thumbs down

I really really apologise for my foul temper which is only surplused by
my bad manners.

Last edited by Tinkster; 07-06-2006 at 01:45 AM.
 
Old 07-05-2006, 03:01 PM   #10
DaneM
Member
 
Registered: Oct 2003
Location: Chico, CA, USA
Distribution: Linux Mint
Posts: 881

Rep: Reputation: 130Reputation: 130
Geez! It was just a question...
 
Old 07-05-2006, 03:23 PM   #11
ethics
Senior Member
 
Registered: Apr 2005
Location: London
Distribution: Arch - Latest
Posts: 1,522

Rep: Reputation: 45
Quote:
Originally Posted by frz
we REALLY don't want to see this
How do people like you get through birth, much less early childhood?

Last edited by Tinkster; 07-06-2006 at 01:45 AM.
 
Old 07-06-2006, 02:53 AM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
And now that this thread is settled and the nastyness gone ... closed.
 
  


Closed Thread

Tags
bash, bashrc, script, scripting, tutorial



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
newbie question : how to edit bashrc pingu99 Linux - Software 5 10-26-2010 07:22 PM
I wanna learn Solaris-Newbie....give me a tutorial indian Solaris / OpenSolaris 2 04-25-2007 11:24 PM
Tutorial or guide book for newbie ewinandar Linux - Newbie 7 11-09-2004 12:33 AM
How about a weekly tutorial? or just a tutorial Alinuxnoob LQ Suggestions & Feedback 2 04-09-2002 08:30 PM

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

All times are GMT -5. The time now is 09:34 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