0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

sftp上でlsした結果をlessするにはsftpのバッチモードを使えばいい

Posted at

課題

sftpで使えるコマンドは限りがあるのでlsした結果をlessしにくい。

解決サンプル

echo "ls -lt" | sftp  -b - user@host | less

解説

sftpにはバッチモード-bがある。普通はこの引数にコマンドをつらつら書いたファイルを指定するが、それも面倒なので標準入力から渡す。

コマンドラインツールはファイル名に- を指定すると標準入力(出力ファイル名に指定するときには標準出力)になるものが多い。

つまり上記のコマンドは

  • ls -lt というsftpコマンドをsftpのバッチモードの入力にパイプで渡す
  • sftp 上でlsした結果は標準出力に出される
  • パイプで lessコマンドに渡す

用途

会社間のファイルのやり取りはS3やsftpでやり取りされることが増えた。やりとりするディレクトリをポーリングするだけでいい。手動での操作であっても何かしらのディレクトリを見るときにはワンライナーにしておくことで、ヒストリから辿れて便利。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?