alias command that works in ssh too

I have some commands that I always use and they are rather hard to remember such as lsof -i -P -n | grep LISTEN. I would like to create an alias for them that also applies when logged in via ssh on another server. Is this possible?


Solution 1:

This is not possible. You need to define your aliases on the other server.

Solution 2:

Rather than defining your alias on the remote host, define a local alias for doing commands remotely. So instead of doing $ ssh bar@foo and then execute your lsof -P -i -n | grep LISTEN you do this on your local machine:

$ alias foolsof='ssh bar@foo "lsof -i -P -n" | grep LISTEN'
$ foolsof

Note that pipe and redirect can be tricky, the grep in the above command is executed on your local machine.