Output ls contents of a server directory using bash
I'm getting really excited spending more and more time using the command line.
Today I had an issue, I wanted to write a script that would ssh into a server and save the
ls from a certain path.
If you're not familiar with bash,
ls -al will list everything in a vertical list like this:
$ ls -al
I thought about how I'd do this with my limited knowledge of bash and did some googling but didn't get anywhere.
I sent out a tweet and copied in a few people.
Please help bash friends, copy `ls -al` from a server to local txt file https://t.co/R1w0Pe1m8P +@sindresorhus @mathias @csswizardry— Simon Owen (@s10wen) July 22, 2014
Within 10 minutes, a few awesome people had replied all with solutions.
@s10wen @sindresorhus @mathias @csswizardry output to file with >> then scp the file from the server?— Ash Davies (@erraticwelshie) July 22, 2014
@s10wen @sindresorhus @mathias https://t.co/mxwDGZPDXL ?— Harry Roberts (@csswizardry) July 22, 2014
@s10wen If all you need is `ls -al` output, run `ssh host 'ls -al /some/path' > foo.txt` on your local machine. +@sindresorhus @csswizardry— Mathias Bynens (@mathias) July 22, 2014
This is a shout out to everyone that is so freaking awesome (sorry Harry, I know I'm not American, but how I love the word :wink:) and willing to take time out of their day to help.
With the information above I was able to put a little script together:
Now I have a directory locally called
server that has a file in called
server.sh, I can
cd to it and run
bash server.sh and I end up with the
ls -al contents of the servers.
Browse by category:
- case study4
- chrome dev tools4
- clojure overtone2
- dev tips1
- raspberry pi1
- responsive web design1
- web development2