Skip to main content

よく使うコマンド

よく使うコマンドで、操作に慣れておくべきもの

コマンド用途
ps -efプロセスの一覧
killプロセスの終了
df -hディスク空き容量の確認
du -shディレクトリのサイズ確認
ls -lファイルの一覧 (直下)
find * -type fファイルの一覧 (ディレクトリ以下)
xargsファイル一覧に対して操作をする
chmod権限の変更
crontabcron 設定 (Windowsでいうタスクスケジューラ)
grepファイル内の文字列検索

知らないものがあったら調べて慣れて置くと良い

組み合わせ例

bash
find XX -type f | xargs chmod u+x  # XX ディレクトリ以下のファイル全部に実行権限をつける

リダイレクトと標準出力

リダイレクトとパイプpd

bash
./command1  > a.txt      # 上書き
./command1 >> a.txt # 追記
./command1 2>&1 > a.txt # 標準エラーと合わせる

./command1 | ./command2 # 標準出力を次のコマンドに渡す

標準出力と標準エラー出力

bash
./command 1> a.txt # 標準出力をファイルに出す
./command 2> a.txt # 標準エラー出力をファイルに出す

実験

bash
ls -l /etc/ > a.txt  # 画面には何も出ないが
cat a.txt # ファイルにはコマンド結果(標準出力)出る

ls -l /no/such/file > a.txt # 画面にはエラーが出るが
cat a.txt # ファイルには何も出ない

ls -l /etc/ /no/such/file 2> a.txt # 画面には標準出力
cat a.txt # ファイルにはエラー

ls -l /etc/ /no/such/file 2>&1 > a.txt # 画面には何も出ず
cat a.txt # ファイルにはエラーと標準出力