Sunday, July 31, 2011

sls (combination of ssh and ls)

Here's a little bash script I just wrote and thought somebody might find useful. I'm always moving files around using scp and also needing to ssh around to ls them. So why not combine the ssh and the ls into sls -- just like scp, right?

Here are the usage and help text...

usage: sls [ls-option]... user@host[:file]...

sls is a magical combination of ssh and ls. Simply give the sls command some (or no) ls options and one or more remote locations and you'll get a listing for each. The remote spec is the same user@host:file specification you would use with the scp command, and the file part is optional.

And here is the script itself. If you have any fixes or improvements, please let me know.

p.s. Blogger, when I write a post in HTML, please let me edit it the same way... thank you. And to visitors from the future, if you find yourself needing to edit your HTML-written post, it's actually easy now that I think about it. Just ask your browser to show you the source, grab what you need, and paste that back into the post editor.

1 comment:

Anonymous said...

This is brilliant and I can't believe nobody has commented on it. It was exactly what I was looking for - are we the only two that want this functionality? Thanks much for sharing.

One upgrade that would be appreciated is to support SSH login aliases. By editing ~/.ssh/config on any Unix, including OS/X, you can turn:
scp user@host:file
into
scp alias:file

I think the complex SED line in the script is preventing SSH login aliases from working.

I know enough to install this brilliant script but maybe I should upgrade my skills to modify it to add the feature above.

Thanks again for sharing!