how to clear the effect of system wide bashrc

At my company there are system-wide bashrc files like /etc/bashrc and so on.

Inside, they source more and more files. It's very confusing (I noticed my "ls" is aliased with a bunch of flags to ls that I don't want).

I want to for my ~/.bashrc clear the effects of all bashrcs.

Is there something like that in bash? Just to clear all aliases, functions, etc, defined in system-wide files.

1 Answer

The easiest way would be to add this line to your ~/.bashrc :

unalias -a

As far as I know, there is no equivalent for clearing all functions. You can, however, clear them one by one using

unset -f function_name

The following two bash options are also relevant:

 --rcfile file Execute commands from file instead of the system wide initialization file /etc/bash.bashrc and the standard personal initialization file ~/.bashrc if the shell is interactive (see INVOCATION below). --norc Do not read and execute the system wide initialization file /etc/bash.bashrc and the personal initialization file ~/.bashrc if the shell is interactive. This option is on by default if the shell is invoked as sh.

So, you could set bash to be an alias for bash --norc:

 alias bash='/bin/bash --norc'

That way, every time you manually launch bash a new shell will be started with no initialization files. You would then need to manually source your .bashrc.

I thought you could combine the --norc and --rcfile options to read your ~/.bashrc only but could not get it to work.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like