Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have many bash aliases on a remote location.
But when I try to run those from my local linux box,
I get the 'command not found' error. e.g.

$ ssh root@remote 'status'  
bash: status: command not found

On the remote location, status is defined as

$ alias status='ls /tmp/status'  

How can I declare an alias on the remote location,
such that I can invoke it from any location?

share|improve this question
    
What's an m/c ? –  moopet Sep 5 '12 at 19:11

3 Answers 3

See the answer to a similar question on Server Fault. Basically, bash doesn't expand aliases in non-interactive shells unless explicitly configured to do so (shopt -s expand_aliases). Plus, you have to make sure that .bashrc is evaluated even in non-interactive shells.

share|improve this answer
2  
I would recommend putting the aliases in a separate file, which you can source from .bashrc and source explicitly when logging into the remote host. –  chepner Sep 6 '12 at 2:33
    
In general good practice, but unrelated to the problem. –  Ansgar Wiechers Sep 6 '12 at 2:39

You can run

ssh root@remote_mc 'bash -ic status'

To run another copy of the shell in interactive mode (which means it'll load the aliases from your bash configuration files)

Starting a second shell isn't that fantastic a solution, but it works.

share|improve this answer

In my opinion, if you want to create many aliases, best solution is:

  • Create a hidden file (I called it .bash_aliases) in your /home/"user_name"
  • In this file you have to put all the aliases that you want to use in terminal. I.e mine is:

alias ll='ls -l'

alias la='ls -A'

alias mydu='du -s * .[^.]* | sort -n'

alias apti='sudo apt-get install'

alias aptr='sudo apt-get remove'

alias aptu='sudo apt-get update'

alias aptg='sudo apt-get upgrade'

alias down='sudo ifconfig wlan0 down'

alias up='sudo ifconfig wlan0 up'

alias managed='sudo iwconfig wlan0 mode managed'

alias monitor='sudo iwconfig wlan0 mode monitor'

alias usb='sudo mount /dev/sdc1 /mnt'

  • In your /home/"user_name"/.bashrc file, put the following lines:
# More alias definitions in ~/.bash_aliases

if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi

I put this line in the end of the file, but just for clarity.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.