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!
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.
Dear All,
I am new to Linux and I am using Linux mint 18.2 Sonya. While trying to save an environment variable, I overwrote my .bash_profile file instead adding to it. I would appreciate it if anyone can help me
recover the default content of this file. If you are still using the default .bash_profile file, please, kindly share.
Thanks.
If you are still using the default .bash_profile file, please, kindly share.
There is no real default .bash_profile, although mint may have added one. Look into /etc/skel to see if there's one there (those are the default files "useradd" add to each user's home directory, after creating it).
A minimal one that works for me is
For things that get added when a new user is created. A good place to start to revert to "defaults". Or to update your defaults should they have changed with an upgrade after your user was created. Otherwise fresh installs on linux take less than an hour in a lot of cases. Another source of something to copy.
I just upgraded an old 17.3 installation to 18, then to 18.2. Its ordinary user had and has no .bash_profile, and no apparent need for one, same as for superuser, and /etc/skel/. For most users, .bash_profile is an optional file, not missed if not present.
It may vary somewhat for different distros, but on my Centos 7
Code:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH
In case it helps, here is the /etc/profile from my Slackware 14.2 install:
Code:
$ cat /etc/profile
# /etc/profile: This file contains system-wide defaults used by
# all Bourne (and related) shells.
# Set the values for some environment variables:
export MINICOM="-c on"
export MANPATH=/usr/local/man:/usr/man
export HOSTNAME="`cat /etc/HOSTNAME`"
export LESSOPEN="|lesspipe.sh %s"
export LESS="-M"
# If the user doesn't have a .inputrc, use the one in /etc.
if [ ! -r "$HOME/.inputrc" ]; then
export INPUTRC=/etc/inputrc
fi
# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"
# For root users, ensure that /usr/local/sbin, /usr/sbin, and /sbin are in
# the $PATH. Some means of connection don't add these by default (sshd comes
# to mind).
if [ "`id -u`" = "0" ]; then
echo $PATH | grep /usr/local/sbin 1> /dev/null 2> /dev/null
if [ ! $? = 0 ]; then
PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH
fi
fi
# I had problems with the backspace key using 'eval tset' instead of 'TERM=',
# but you might want to try it anyway instead of the section below it. I
# think with the right /etc/termcap it would work.
# eval `tset -sQ "$TERM"`
# Set TERM to linux for unknown type or unset variable:
if [ "$TERM" = "" -o "$TERM" = "unknown" ]; then
TERM=linux
fi
# Set ksh93 visual editing mode:
if [ "$SHELL" = "/bin/ksh" ]; then
VISUAL=emacs
# VISUAL=gmacs
# VISUAL=vi
fi
# Set a default shell prompt:
#PS1='`hostname`:`pwd`# '
if [ "$SHELL" = "/bin/pdksh" ]; then
PS1='! $ '
elif [ "$SHELL" = "/bin/ksh" ]; then
PS1='! ${PWD/#$HOME/~}$ '
elif [ "$SHELL" = "/bin/zsh" ]; then
PS1='%n@%m:%~%# '
elif [ "$SHELL" = "/bin/ash" ]; then
PS1='$ '
else
PS1='\u@\h:\w\$ '
fi
PS2='> '
export PATH DISPLAY LESS TERM PS1 PS2
# Default umask. A umask of 022 prevents new files from being created group
# and world writable.
umask 022
# Notify user of incoming mail. This can be overridden in the user's
# local startup file (~/.bash.login or whatever, depending on the shell)
if [ -x /usr/bin/biff ]; then
biff y 2> /dev/null
fi
# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
if [ -x $profile_script ]; then
. $profile_script
fi
done
unset profile_script
I also have a small customize ~/.bashrc to customized my BASH prompt:
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,803
Rep:
Quote:
Originally Posted by weewee
I overwrote my .bash_profile file instead adding to it. I would appreciate it if anyone can help me
recover the default content of this file. If you are still using the default .bash_profile file, please, kindly share.
Thanks.
You could try adding a new user on your system. Copy that new account's .bash_profile (if one is created for that account).
I assume that you must have forgotten one of the ">"s and "replaced" rather than "appended" when you thought you were issuing "cat >> .bash_profile". (Most people have done this by accident when they were in a hurry and didn't see that missing character before hitting 'Return'.) Personally, I would never try to append something to my .bash_profile (or .profile or .bashrc) using that command. Use a text editor to make additions/changes to these files. Make a backup copy of them before editing (or use an editor like Emacs that does this for you). Use RCS, Subversion, or Git to keep a history of your important files.
Is it necessary to mention the importance of regular backups?
If your home directory is on a btrfs filesystem, you might be able to find a "pre-corruption" version of the file in a filesystem snapshot.
Nice, maybe we should have a "Show us your .bash_profile" thread.
As far as OP is concerned: weewee hasn't even logged in in 10 days.
Apologies for my poor follow-up. I have been following the responses without logging in.
There is no need for any "show us your .bash_profile" thread - for now at least.
When I overwrote my .bash_profile file, my terminal lost its color effects. Everything went plain.
I just copied the content of ".profile" file and transferred it to my ".bash_profile" file. Everything seems fine for now. I guess I didn't even much on my former .bash_profile file. I haven't had any issues so far.
Thanks, everyone.
In case it helps, here is the /etc/profile from my Slackware 14.2 install:
Code:
$ cat /etc/profile
# /etc/profile: This file contains system-wide defaults used by
# all Bourne (and related) shells.
# Set the values for some environment variables:
export MINICOM="-c on"
export MANPATH=/usr/local/man:/usr/man
export HOSTNAME="`cat /etc/HOSTNAME`"
export LESSOPEN="|lesspipe.sh %s"
export LESS="-M"
# If the user doesn't have a .inputrc, use the one in /etc.
if [ ! -r "$HOME/.inputrc" ]; then
export INPUTRC=/etc/inputrc
fi
# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/games"
# For root users, ensure that /usr/local/sbin, /usr/sbin, and /sbin are in
# the $PATH. Some means of connection don't add these by default (sshd comes
# to mind).
if [ "`id -u`" = "0" ]; then
echo $PATH | grep /usr/local/sbin 1> /dev/null 2> /dev/null
if [ ! $? = 0 ]; then
PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH
fi
fi
# I had problems with the backspace key using 'eval tset' instead of 'TERM=',
# but you might want to try it anyway instead of the section below it. I
# think with the right /etc/termcap it would work.
# eval `tset -sQ "$TERM"`
# Set TERM to linux for unknown type or unset variable:
if [ "$TERM" = "" -o "$TERM" = "unknown" ]; then
TERM=linux
fi
# Set ksh93 visual editing mode:
if [ "$SHELL" = "/bin/ksh" ]; then
VISUAL=emacs
# VISUAL=gmacs
# VISUAL=vi
fi
# Set a default shell prompt:
#PS1='`hostname`:`pwd`# '
if [ "$SHELL" = "/bin/pdksh" ]; then
PS1='! $ '
elif [ "$SHELL" = "/bin/ksh" ]; then
PS1='! ${PWD/#$HOME/~}$ '
elif [ "$SHELL" = "/bin/zsh" ]; then
PS1='%n@%m:%~%# '
elif [ "$SHELL" = "/bin/ash" ]; then
PS1='$ '
else
PS1='\u@\h:\w\$ '
fi
PS2='> '
export PATH DISPLAY LESS TERM PS1 PS2
# Default umask. A umask of 022 prevents new files from being created group
# and world writable.
umask 022
# Notify user of incoming mail. This can be overridden in the user's
# local startup file (~/.bash.login or whatever, depending on the shell)
if [ -x /usr/bin/biff ]; then
biff y 2> /dev/null
fi
# Append any additional sh scripts found in /etc/profile.d/:
for profile_script in /etc/profile.d/*.sh ; do
if [ -x $profile_script ]; then
. $profile_script
fi
done
unset profile_script
I also have a small customize ~/.bashrc to customized my BASH prompt:
Code:
$ cat .bashrc
PS1="\u@\H \W/ \$ "
Thanks for this. It's exactly what I wanted to see.
I just upgraded an old 17.3 installation to 18, then to 18.2. Its ordinary user had and has no .bash_profile, and no apparent need for one, same as for superuser, and /etc/skel/. For most users, .bash_profile is an optional file, not missed if not present.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.