最も便利な端末コマンド( Linux , Mac , Unix )


この初心者チュートリアルでは、LinuxやMac OS XをはじめとするUnixライクな環境で実行できる最も一般的で便利なコマンドをレビューします.
pwd - 印刷作業ディレクトリpwd 現在のディレクトリを出力します.これは、“私はどこですか?”質問に短いと簡単に答えを提供します.を実行するのはとても便利ですpwd 端末セッションの開始時にコマンドを実行します.ここでは実行の例ですpwd rootとしてサーバーにログインした直後に.
root@scw-tender-lewin:~# pwd
/root
ls - リストファイルとディレクトリ
ディレクトリの内容を見るにはls ( list )コマンド.基本的な使い方は以下のようになります:
root@scw-tender-lewin:/# ls
bin   dev  home        initrd.img.old  lib64       media  opt   root  sbin  srv       sys  usr  vmlinuz
boot  etc  initrd.img  lib             lost+found  mnt    proc  run   snap  swapfile  tmp  var  vmlinuz.old
特定のディレクトリの内容をチェックアウトしたい場合、すなわち、var , あなたはその直後にそのパスを追加することによってそれを行うことができますls :
root@scw-tender-lewin:/# ls /var
backups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp
また、出力の形式を変更する便利なフラグもいくつかありますls コマンド.

ロングリストビュー
The -l フラグには、パーミッション、所有者、サイズ、日付などの追加情報が表示されます.
root@scw-tender-lewin:/# ls -l
total 4194396
drwxr-xr-x   2 root root       4096 May 15 06:46 bin
drwxr-xr-x   4 root root       4096 Sep  3 06:15 boot
drwxr-xr-x  16 root root       3680 May 20 06:35 dev
drwxrwxr-x  93 root root       4096 Sep  3 06:15 etc
drwxr-xr-x   3 root root       4096 Mar  6 09:14 home
lrwxrwxrwx   1 root root         34 Sep  3 06:15 initrd.img -> boot/initrd.img-4.15.0-115-generic
lrwxrwxrwx   1 root root         34 Sep  3 06:15 initrd.img.old -> boot/initrd.img-4.15.0-112-generic
drwxr-xr-x  23 root root       4096 Mar  6 09:16 lib
drwxr-xr-x   2 root root       4096 Jul  8 06:20 lib64
drwx------   2 root root      16384 Mar  5  2019 lost+found
drwxr-xr-x   2 root root       4096 Feb  4  2019 media
drwxr-xr-x   2 root root       4096 Feb  4  2019 mnt
drwxr-xr-x   3 root root       4096 Mar  6 09:17 opt
dr-xr-xr-x 189 root root          0 May  4 06:16 proc
drwx------   8 root root       4096 Mar 19 08:13 root
drwxr-xr-x  28 root root       1120 Sep  3 07:21 run
drwxr-xr-x   2 root root      12288 Jul  8 06:20 sbin
drwxr-xr-x   2 root root       4096 Mar  6 09:14 snap
drwxr-xr-x   2 root root       4096 Feb  4  2019 srv
-rw-------   1 root root 4294967296 Mar  6 10:10 swapfile
dr-xr-xr-x  13 root root          0 May  4 06:16 sys
drwxrwxrwt  10 root root       4096 Sep  3 07:22 tmp
drwxrwxr-x  10 root root       4096 Mar  5  2019 usr
drwxr-xr-x  13 root root       4096 Mar  5  2019 var
lrwxrwxrwx   1 root root         31 Sep  3 06:15 vmlinuz -> boot/vmlinuz-4.15.0-115-generic
lrwxrwxrwx   1 root root         31 Sep  3 06:15 vmlinuz.old -> boot/vmlinuz-4.15.0-112-generic
ところで、1つのファイルについての特定の情報をチェックしたい場合は、ディレクトリと同じように名前を追加できます.ここでどのように長いリストビューをチェックすることができますswapfile :
root@scw-tender-lewin:/# ls -l swapfile
-rw------- 1 root root 4294967296 Mar  6 10:10 swapfile

隠しファイルとフォルダ
隠しファイルやフォルダを表示するには-a へのフラグls コマンド
root@scw-tender-lewin:/# ls -a
.   bin   dev  home        initrd.img.old  lib64       media  opt   root  sbin  srv       sys  usr  vmlinuz
..  boot  etc  initrd.img  lib             lost+found  mnt    proc  run   snap  swapfile  tmp  var  vmlinuz.old

このようにして、少なくとも2つ以上の追加レコードを取得します.. and .. . 単一のドットはカレントディレクトリを表し、ダブルドットは現在の1つのレベルのディレクトリにアクセスするために使用されます.

出力をソートするls コマンド
The -S フラグは、結果を昇順にサイズでソートするために使用されます.
root@scw-tender-lewin:/# ls -S
swapfile    sbin  boot  home  lib64  mnt  root  srv  usr  dev  initrd.img      vmlinuz      proc
lost+found  bin   etc   lib   media  opt  snap  tmp  var  run  initrd.img.old  vmlinuz.old  sys

フラグの組み合わせ
かなり頻繁に複雑な動作を実現したい.たとえば、両方の長いリストビューを取得する必要があります-l , 人間と読めるサイズの出力-h で結果をソートする-S フラグ.
これを達成するには、1つにすべてのフラグを組み合わせることができます.フラグの順序はここでは重要ではありません-lhS-hSl , 以下のようなシーケンスを使用できます.
root@scw-tender-lewin:/# ls -lhS
total 4.1G
-rw-------   1 root root 4.0G Mar  6 10:10 swapfile
drwx------   2 root root  16K Mar  5  2019 lost+found
drwxr-xr-x   2 root root  12K Jul  8 06:20 sbin
drwxr-xr-x  23 root root 4.0K Sep  3 06:15 .
drwxr-xr-x  23 root root 4.0K Sep  3 06:15 ..
drwxr-xr-x   2 root root 4.0K May 15 06:46 bin
drwxr-xr-x   4 root root 4.0K Sep  3 06:15 boot
drwxrwxr-x  93 root root 4.0K Sep  3 06:15 etc
drwxr-xr-x   3 root root 4.0K Mar  6 09:14 home
drwxr-xr-x  23 root root 4.0K Mar  6 09:16 lib
drwxr-xr-x   2 root root 4.0K Jul  8 06:20 lib64
drwxr-xr-x   2 root root 4.0K Feb  4  2019 media
drwxr-xr-x   2 root root 4.0K Feb  4  2019 mnt
drwxr-xr-x   3 root root 4.0K Mar  6 09:17 opt
drwx------   8 root root 4.0K Mar 19 08:13 root
drwxr-xr-x   2 root root 4.0K Mar  6 09:14 snap
drwxr-xr-x   2 root root 4.0K Feb  4  2019 srv
drwxrwxrwt  10 root root 4.0K Sep  3 07:22 tmp
drwxrwxr-x  10 root root 4.0K Mar  5  2019 usr
drwxr-xr-x  13 root root 4.0K Mar  5  2019 var
drwxr-xr-x  16 root root 3.6K May 20 06:35 dev
drwxr-xr-x  28 root root 1.1K Sep  3 07:21 run
lrwxrwxrwx   1 root root   34 Sep  3 06:15 initrd.img -> boot/initrd.img-4.15.0-115-generic
lrwxrwxrwx   1 root root   34 Sep  3 06:15 initrd.img.old -> boot/initrd.img-4.15.0-112-generic
lrwxrwxrwx   1 root root   31 Sep  3 06:15 vmlinuz -> boot/vmlinuz-4.15.0-115-generic
lrwxrwxrwx   1 root root   31 Sep  3 06:15 vmlinuz.old -> boot/vmlinuz-4.15.0-112-generic
dr-xr-xr-x 191 root root    0 May  4 06:16 proc
dr-xr-xr-x  13 root root    0 Sep  3 08:25 sys
cd - ディレクトリを変更
ですから、ディレクトリ内の内容についてすべてを学んだ後、どこか他の場所に行きたいと思います.The cd コマンドは一つの引数としてディレクトリ名を取り、そこに移動します.The cd コマンドはエラーがあれば出力を出力するので、すぐにls 見回すコマンド
root@scw-tender-lewin:/# cd var
root@scw-tender-lewin:/var# ls -a
.  ..  backups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp

親フォルダへの移動
上記の1つのフォルダを移動するには.. ディレクトリ名として.以上の2つ以上のレベルを移動するにはcd ../.. など.
存在しないディレクトリに移動しようとすると、次のメッセージが表示されます.
root@scw-tender-lewin:/var# cd local42
-bash: cd: local42: No such file or directory
root@scw-tender-lewin:/var# cd ..
root@scw-tender-lewin:/# ls
bin   dev  home        initrd.img.old  lib64       media  opt   root  sbin  srv       sys  usr  vmlinuz
boot  etc  initrd.img  lib             lost+found  mnt    proc  run   snap  swapfile  tmp  var  vmlinuz.old

帰宅
を使用する場合~ ディレクトリ名としてシンボルを使用すると、ホームフォルダに移動されます.それはあなたが現在のところでは重要ではない便利なショートカットであり、いくつかの時点でホームディレクトリへの正確なパスを知っているかもしれません.
root@scw-tender-lewin:/# cd ~
root@scw-tender-lewin:~# pwd
/root
touch - ファイルを作る
The touch コマンドを使用すると、空のファイルを作成できます.では、次のような計画です.
  • ホームディレクトリに移動しますcd ~
  • それが空であることを確認してくださいls
  • 新しいファイルを作成するtouch そしてファイル名を
  • を実行するls 再び新しく作成されたファイルが存在することを確認するコマンド
  • root@scw-tender-lewin:/var/log# cd ~
    root@scw-tender-lewin:~# ls
    root@scw-tender-lewin:~# touch hello.txt
    root@scw-tender-lewin:~# ls
    hello.txt
    
    mkdir - ディレクトリを作る
    Linuxでディレクトリを作成するにはmkdir コマンド.それはほとんど同じように動作しますtouch を返します.
    root@scw-tender-lewin:~# mkdir internal
    root@scw-tender-lewin:~# ls
    hello.txt  internal
    
    man - マニュアルを表示
    そして最後に、超大国!The man コマンドを使用すると、任意のコマンドでも、短いマニュアルを与える.何かをしたいのですが、重要なフラグやコマンド構文を忘れてしまった場合はman コマンド名に従ってインスタントマニュアルを取得します.以下に例を示します:
    root@scw-tender-lewin:~# man ls
    NAME
         ls -- list directory contents
    
    SYNOPSIS
         ls [-ABCFGHLOPRSTUW@abcdefghiklmnopqrstuwx1%] [file ...]
    
    DESCRIPTION
         For each operand that names a file of a type other than directory, ls displays its name as well as any requested, associated information.
         For each operand that names a file of type directory, ls displays the names of files contained within that directory, as well as any
         requested, associated information.
    
         If no operands are given, the contents of the current directory are displayed.  If more than one operand is given, non-directory operands
         are displayed first; directory and non-directory operands are sorted separately and in lexicographical order.
    
         The following options are available:
    ...
    

    結論
    この記事では、使用する最も簡単なLinuxとMacOS、および/nixシステムコマンドのように、我々は最も簡単に見直しましたls , pwd , cd , touch , mkdir , and man .
    あなたがちょうどあなたの旅をソフトウェア開発世界に始めているならば、あなたはすべての巨大な端末またはコマンドラインのルックスに脅かされるかもしれません.
    しかし、あなたが見るように、それは非常に簡単で簡単な場合は、適切な場所で起動します.