目次
1 Linuxコマンドとは
linux コマンドは、 Linuxシステム を管理するためのコマンドです。Linux システムの場合、中央処理装置、メモリ、ディスク ドライブ、キーボード、マウス、またはユーザーなどはすべてファイルであり、 Linux システムによって管理されるコマンドは、以前のシステムと同様に、通常の操作の中核です。 DOS コマンド。システムには、組み込み シェル コマンドと Linux コマンドの 2 種類の Linux コマンドがあります。
まず「console(コンソール)」という用語を導入します。これは、dos などの文字インターフェイスを使用して、通常私たちが目にするマンマシン インターフェイスです。コンソール コマンドとは、文字インターフェイスを介してシステム入力を操作するために使用できるコマンドを意味し、たとえば、dos コマンドはコンソール コマンドです。理解したいのは、Linux オペレーティング システムに基づく基本的なコンソール コマンドです。注意すべきことの 1 つは、dos コマンドとは異なり、Linux コマンド (ファイル名などを含む) は大文字と小文字が区別されることです。つまり、入力したコマンドの大文字と小文字が間違っていると、システムは期待どおりに応答しません。
2種類のコマンド
まず、最初に覚えるコマンドは type コマンドです。type コマンドは、コマンドのタイプを確認できます。コマンドのタイプは、「エイリアス」、「キーワード」、「関数」、「組み込み」、「ファイル」に分けられます。いくつかの例を見ることができます:
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type cd
cd is a shell builtin
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type which
which is hashed (/usr/bin/which)
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type apt
apt is /usr/bin/apt
単純なタイプのコマンドのみを取得する場合は、-t パラメーターを追加できます。例えば:
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type -t cd
builtin
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type -t which
file
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ type -t apt
file
では、コマンドのタイプを取得することの用途は何ですか。コマンドのタイプを取得したら、and help または man を使用してコマンドのヘルプ マニュアルを表示できます。組み込みコマンドの場合は help コマンドを使用してコマンドのヘルプ マニュアルを表示し、ファイル コマンドの場合は man コマンドを使用してコマンドのヘルプ マニュアルを表示します。例えば:
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ help cd
cd: cd [-L|[-P [-e]] [-@]] [dir]
Change the shell working directory.
Change the current directory to DIR. The default DIR is the value of the
HOME shell variable.
The variable CDPATH defines the search path for the directory containing
DIR. Alternative directory names in CDPATH are separated by a colon (:).
A null directory name is the same as the current directory. If DIR begins
with a slash (/), then CDPATH is not used.
If the directory is not found, and the shell option `cdable_vars' is set,
the word is assumed to be a variable name. If that variable has a value,
its value is used for DIR.
Options:
-L force symbolic links to be followed: resolve symbolic
links in DIR after processing instances of `..'
-P use the physical directory structure without following
symbolic links: resolve symbolic links in DIR before
processing instances of `..'
-e if the -P option is supplied, and the current working
directory cannot be determined successfully, exit with
a non-zero status
-@ on systems that support it, present a file with extended
attributes as a directory containing the file attributes
The default is to follow symbolic links, as if `-L' were specified.
`..' is processed by removing the immediately previous pathname component
back to a slash or the beginning of DIR.
Exit Status:
Returns 0 if the directory is changed, and if $PWD is set successfully when
-P is used; non-zero otherwise.
このようにして、Linux コマンドを学習する方法が得られます。たとえば、 which コマンドを知りたい場合、上記の type query から、 which コマンドは file コマンドなので、 man which を使用して、このコマンドの使用方法を問い合わせることができます。
WHICH(1) General Commands Manual WHICH(1)
NAME
which - locate a command
SYNOPSIS
which [-a] filename ...
DESCRIPTION
which returns the pathnames of the files (or links) which would be executed in the current environment, had its arguments been given as commands in a strictly POSIX-conformant shell. It
does this by searching the PATH for executable files matching the names of the arguments. It does not canonicalize path names.
OPTIONS
-a print all matching pathnames of each argument
EXIT STATUS
0 if all specified commands are found and executable
1 if one or more specified commands is nonexistent or not executable
2 if an invalid option is specified
上記のマニュアルから、どのコマンドがコマンドの位置を特定できるか、および -a パラメーターを使用して、一致するすべてのコマンドの位置を出力できることがわかります。
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ which ls
/usr/bin/ls
parallels@ubuntu-linux-20-04-desktop:~/C_test1$ which -a ls
/usr/bin/ls
/bin/ls
実際、type コマンドはコマンドの場所を提供することもでき、type コマンドは which コマンドよりも多くの情報を提供します。