Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is there a way to do a remote "ls" much like "scp" does a remote copy in a standard linux shell?

share|improve this question
I can see it'd be nice to do this, but why not just SSH in and do an ls? –  SpacemanSpiff Mar 2 '11 at 12:54
@SpacemanSpiff - So you can script it. That's how I got to this page. –  wobbily_col Aug 27 '14 at 13:02

4 Answers 4

up vote 22 down vote accepted

You could always do this:

ssh user@host ls -l /some/directory

That will SSH to the host, run ls, dump the output back to you and immediately disconnect.

share|improve this answer
... if you have real shell access. Some systems have a special shell which will only accept certain scp and rsync calls, maybe sftp as well, and that's it. –  glglgl Jun 6 '14 at 22:11
how would you alias this to, say, "rls" ? –  Walrus the Cat Oct 18 '14 at 16:24

Yes. SSH and do an ls:

ssh host ls /path

You could easily script this to be more flexible, or use the host:path syntax scp uses.

share|improve this answer

To list all files in a directory:

rsync host.name.com:directory/path/'*'

For something like find directory/path -ls

rsync -r host.name.com:directory/path
share|improve this answer

I find my most frequent use of this is to get the ls result, a simple list of files without all the permissions and dates and such, and keep it in a local file.

{ ssh me@host.com "cd /dir/of/interest; ls -1f *.txt;" } > /home/me/listoffiles.txt

You can run anything you want within the quotes. All output ends up in your local text file. Or if you want to run a big nasty script on the server and capture all of its output, even errors:

{ ssh me@host.com <script.remote.sh } > /home/me/output.log 2>/home/me/output.err
share|improve this answer
In the 2nd code line, the { } are not needed. –  glglgl Jun 6 '14 at 22:12

Your Answer


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.