LoginSignup
5
7

More than 5 years have passed since last update.

Bashとコマンドの基本的なこと

Last updated at Posted at 2013-10-09

zsh使えるようになりたい。

リダイレクト

標準出力と標準エラー出力を一緒にファイルに書き出す

順番注意。
以下は 「2の出力先を1と同じものにする」 という意味。

  • 作成
echo "aaa" >result.txt 2>&1
  • 追記
echo "aaa" >>result.txt 2>&1

Tips

cutコマンド

$ ls -Fl
total 0
drwxr-xr-x  3 noguchiwataru  staff  102 10 10 00:39 cookbooks/
drwxr-xr-x  3 noguchiwataru  staff  102 10 10 00:39 data_bags/
drwxr-xr-x  3 noguchiwataru  staff  102 10 10 00:39 nodes/
drwxr-xr-x  3 noguchiwataru  staff  102 10 10 00:39 roles/
drwxr-xr-x  4 noguchiwataru  staff  136 10 10 23:47 site-cookbooks/

次の例はどうなるか。

$ ls -Fl | cut -f14 -d " "
  • 区切りをホワイトスペース として2つ連続する空白は1つのフィールドとして扱われる。-d でデリミタとして指定する。
  • -f オプションで読み出すフィールド番号を指定する。インデックスは1番から始まります。ここでは12番目のフィールドを読み出し。

結果、以下のように表示される。


cookbooks/
data_bags/
nodes/
roles/
site-cookbooks/

クリップボード操作

xclipコマンドが便利。

インストール

  • Ubuntu
sudo apt-get -y install xclip
使い方

-sel clip としないとうまくクリップボードにコピーされないようなので注意。

ls -la / | xclip -sel clip

参考サイト

xclip

5
7
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
5
7