I have an alias defined in my .bashrc
alias l.='ls -d .* --color=auto'
It's very useful :) but it doesn't work via ssh
:
$ ssh localhost l.
bash: l.: command not found
Why is that?
I have an alias defined in my .bashrc
alias l.='ls -d .* --color=auto'
It's very useful :) but it doesn't work via ssh
:
$ ssh localhost l.
bash: l.: command not found
Why is that?
Try:
ssh localhost -t bash -ci l.
Note:
The alias should be in ~/.bashrc
on the remote server, not on your local machine.
The -i
option tells bash
to run an interactive shell. Aliases are enabled by default only in interactive shells.
The -t
options tells ssh
to allocate a pseudo-tty. Without this, bash
emits a warning message when started in interactive mode. This also enables ls
colors. Without it, you'd have to use --color=always
, see man ls
.
There is another way to enable aliases, without setting the interactive flag, namely shopt -s expand_aliases
. So you could try:
ssh localhost 'bash -c "shopt -s expand_aliases; l."'
However:
Your .bashrc
might only define aliases if the shell sourcing it is interactive. In this example, the shell would not be interactive at that time.
If you try to define aliases on the same line, see this.
ssh
. Yes, with localhost
that's not a problem.
– Matei David
Aug 09 '16 at 15:09
ssh ... <cmd>
exits when <cmd>
is done. If you want to keep the shell around after ls
, try ssh localhost -t 'bash -ci "l.; exec bash"'
.
– Matei David
Aug 09 '16 at 20:59
.bashrc
is only read if the shell is interactive. – user4556274 Aug 09 '16 at 15:05alias l.='ls -d .* --color'
then the colors appear. Just thought I would add that. At least I was experiencing that. – Terrance Aug 09 '16 at 15:44source .bashrc
) – Zanna Aug 09 '16 at 15:49alias l.='ls -dC .* --color'
where theC
shows columns. – Terrance Aug 09 '16 at 15:53