0

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?

1
  • What's an m/c ?
    – moopet
    Sep 5, 2012 at 19:11

3 Answers 3

1

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.

2
  • 3
    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, 2012 at 2:33
  • In general good practice, but unrelated to the problem. Sep 6, 2012 at 2:39
0

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.

-1

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.

2
  • Why the downvote ?????
    – Kyrol
    Jul 3, 2016 at 18:31
  • Probably cause your answer has nothing to do with the original question...
    – Dakusan
    Sep 30, 2017 at 12:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .