24

I have give alias names in .bashrc file like below. But the alias names are not working. why?

alias c='clear'
alias l='ls -lt'
alias h='history'
alias d='ls -lt |grep "^d"'

export ORACLE_HOME=/ora11gr2/app/oracle/product/11.2.0/db2
export ORACLE_LIB=/ora11gr2/app/oracle/product/11.2.0/db2/lib
export PATH=$ORACLE_HOME/bin:/usr/vac/bin:/usr/vacpp/bin:.    
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:.
Giacomo1968
  • 58,727
Venkatesh
  • 341

10 Answers10

42

Did you source your .bashrc file after you changed it? Try:

. ~/.bashrc

Then your shell should see the changes. Alternatively, you can terminate and restart your shell.

p.s.

When you run from a script, load this first ref

shopt -s expand_aliases
Nam G VU
  • 12,548
Fran
  • 5,511
5

Just in case any macOS users come looking for this answer, I tried this on my MacBook and even restarting the Terminal would not load the new alias definitions.

The only way I could get it to work was to source ~/.bashrc every time.

Then I tried moving my alias definitions to ~/.bash_profile and this is what did the trick.

Giacomo1968
  • 58,727
Mig82
  • 191
3

This may happen because your PATH has not been set correctly to use all alias referenced binaries' absoulte path. i.e ls exists under /bin/ls.

Can you give a try using

export PATH=$PATH:$ORACLE_HOME/bin:/usr/vac/bin:/usr/vacpp/bin:.

or somthing like

export PATH=$ORACLE_HOME/bin:/usr/vac/bin:/usr/vacpp/bin:/bin:/sbin/:/usr/sbin

If not, then use which to find the path directory for individual alias ref binaries (which history).

Worthwelle
  • 4,816
3

Maybe you are trying to define your aliases in your .bashrc that are already global.

Usually your aliases in .bashrc are defined before the /etc/bashrc call. Try to define them after.

Here an example of your .bashrc:

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

# User specific aliases and functions
alias c='clear'
alias l='ls -lt'
alias h='history'
alias d='ls -lt |grep "^d"'

export ORACLE_HOME=/ora11gr2/app/oracle/product/11.2.0/db2
export ORACLE_LIB=/ora11gr2/app/oracle/product/11.2.0/db2/lib
export PATH=$ORACLE_HOME/bin:/usr/vac/bin:/usr/vacpp/bin:.    
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:.
1

Change the user's shell from /bin/sh to /bin/bash. This is all that needs to be done to make the .bashrc aliases and such work.

Worthwelle
  • 4,816
1

I had a bunch of stuff in my ~/.zshrc and it was unclear which was overwriting ls as ls -G. Putting alias ls='exa' at the very bottom helped.

1

Questions to ask yourself are:

  • Is the ~/.bashrc already executed in your shell. It only runs when the shell is started. If you open a new shell (execute bash) it should be. With alias you should see all your aliases printed.
  • Second thing to ask: are the programs in your aliases available. At least h (alias history) should definitely work, because it is builtin.
0

I'm embarrassed to type this but the reason aliases weren't working for me is because I had a space in between:

alias c = 'clear'

With alias c='clear' it works.

kohane15
  • 109
  • 3
0

Note: Deal with ~/.bashrc or ~/.zshrc according to the shell you use.


  1. Make sure first what shell do use the command below will let you know:

    $ echo "$SHELL"
    
  2. Why do you have to know? Because editing the ~/.bashrc while you use Zsh and even re-sourcing or logging out will give no benefit since you configure a file for shell ur not currently using and that was the case with me.

Commands: If you use Zsh ~> nano /.zshrc. If you use Bash ~> nano /.bashrc and so on.

Giacomo1968
  • 58,727
0

I was trying to load my .bash_aliases file with the command alias ls='exa --icons', but it was conflicting with the aliases from bash_it. The solution is simply to delete the line of conflicting aliases. You can list all of them with a simple command alias.