哦我遇到的最常見問題之一是如何使用 apt / dnf 命令等包管理器找到我剛剛在 Linux 上安裝的 Linux 命令路徑。 有許多來自 Windows 世界的新開發人員。許多人是 Linux 新手。 有些使用 WSL 的 Linux,而有些則直接通過 ssh 處理雲服務器。 下面我們來看看一些常用的命令來列出或查找Linux命令的路徑。
什麼是 Linux 命令?
在 Windows 上,默認用戶界面是 GUI。但是,服務器端 Linux 默認有一個文本界面。因此,經常使用諸如 Bash、shell、控制台、命令提示符、終端和許多其他名稱之類的術語。兩者均指文本界面。例如,在 MS Windows 上[スタート]單擊按鈕以啟動應用程序。
同樣,在終端中輸入一條名為 Linux 命令的指令。例如,您可以按 Ctrl–Alt–T 啟動 Linux 終端。然後您可以輸入一個簡單的命令,例如日期,以查看今天的日期和時間。必須包含所有日期命令 小寫字母 按下前 進來 這樣做的關鍵:
不同類型的 Linux 命令
您可以在終端中輸入不同類型的 Linux 命令。
如何查找 Linux 命令類型
必須使用 輸入命令 顯示 Linux 命令的路徑。它還確定命令是內置 shell、別名、函數還是外部命令。語法是
type command type -t command type -a command
例如,讓我們看一下 pwd 命令類型。
type pwd type date type hello type ping # Display a single word which is one of 'alias', 'keyword', 'function', 'builtin', # 'file or '' , if command is an alias, shell reserved word, shell function, shell builtin, # disk file, or not found, respectively type -t ping type -t if type -t vi type -t nano # The '-a' option shows all locations containing an executable named ping type -a ping
$PATH 變量是什麼?
PATH 變量包含一組目錄,其中可執行程序(ping、date、vi、docker 等)存儲在 Linux 或類 Unix 系統上。檢查當前路徑 回顯命令//printf 命令:
echo "$PATH" # OR # # More human readable format # echo "${PATH//:/$'n'}"
這就是我所看到的:
/home/vivek/google-cloud-sdk/bin /home/vivek/.local/bin /home/vivek/bin /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /usr/games /usr/local/games /snap/bin
要查看/bin/目錄下存儲的所有可執行文件,運行ls命令如下:
ls /bin/ ls -l /bin/
如何顯示有關命令的信息
利用 命令命令 Linux命令的路徑是:
command -v date command -v pwd command -v ping command -v docker
如何查找 Linux 命令
您還可以使用 which 命令輕鬆獲取 Linux 命令的路徑。例如:which gcc
which nano
要打印所有可能的匹配路徑,請傳遞 -a 如下:which -a ls
獲取 Linux 命令或手冊頁的路徑
使用 whereis 命令在二進製文件、源代碼和手冊頁中搜索磁盤上的指定程序或命令。語法如下:
whereis command whereis gcc whereis docker whereis lxc whereis vim
您只想查看二進製文件嗎?嘗試:whereis -b ls
只搜索手冊和信息頁面怎麼樣?簡單的:whereis -m date
whereis -m gcc
搜索和搜索命令
您還可以按名稱查找文件。例如,要搜索“日期”類型的文件:
locate -b 'date' ## OR ## find / -name "date" -ls # sudo for all files sudo find / -name "date" -ls
定位命令的輸出:
/snap/core/11316/bin/date /snap/core/11420/bin/date /snap/core18/2066/bin/date /snap/core18/2074/bin/date /snap/core20/1026/usr/bin/date /snap/core20/1081/usr/bin/date /usr/bin/date /usr/lib/byobu/date
獲取有關 Linux 命令的幫助
您可以使用 whatis 命令。 幫助命令 什麼時候 手動命令 或信息命令。
什麼是訂單?
每個 Linux 命令都附帶一個手冊頁(解釋用法和語法的頁面)。它還包含一個簡短的描述。例如,whatis 命令搜索手冊頁名稱。將顯示具有匹配名稱的手冊頁的簡短描述。whatis ls
whatis clear
whatis date
whatis gcc
要使用的所有外部命令 手動命令 或者,使用以下 info 命令在屏幕上顯示詳細手冊。man date
man ls
man gcc
man bash
info ls
info bash
man which
所有 Bash 關鍵字和內置函數
幫助命令
:
help if
help exit
help logout
help type
help command
全部的
新 Linux 用戶的主要障礙是搜索命令。但是在這個簡單頁面的幫助下,您可以找到命令路徑或使用手冊頁來獲得幫助。 假設你的 Ubuntu 服務器上安裝了 Docker。然後您可以找到路徑並獲得以下幫助:
whatis docker whereis docker type -a docker which docker find / -iname "docker" locate -b 'docker' man docker
對於 Debian 或 Ubuntu Linux 服務器,請嘗試以下兩個命令。 使用 dpkg 命令列出 Docker 包安裝在服務器上的所有文件。dpkg -L docker-ce
dpkg -L docker-ce | more
/. /etc /etc/default /etc/default/docker /etc/init /etc/init/docker.conf /etc/init.d /etc/init.d/docker /lib /lib/systemd /lib/systemd/system /lib/systemd/system/docker.service /lib/systemd/system/docker.socket /usr /usr/bin /usr/bin/docker-init /usr/bin/docker-proxy /usr/bin/dockerd /usr/share /usr/share/doc /usr/share/doc/docker-ce /usr/share/doc/docker-ce/README.md /usr/share/doc/docker-ce/changelog.Debian.gz
使用 apt 命令顯示 Docker 包信息。apt show docker-ce
Package: docker-ce Version: 5:19.03.13~3-0~ubuntu-bionic Priority: optional Section: admin Maintainer: Docker <[email protected]> Installed-Size: 107 MB Depends: docker-ce-cli, containerd.io (>= 1.2.2-3), iptables, libseccomp2 (>= 2.3.0), libc6 (>= 2.8), libdevmapper1.02.1 (>= 2:1.02.97), libsystemd0 Recommends: aufs-tools, ca-certificates, cgroupfs-mount | cgroup-lite, git, pigz, xz-utils, libltdl7, apparmor Conflicts: docker (<< 1.5~), docker-engine, docker-engine-cs, docker.io, lxc-docker, lxc-docker-virtual-package Replaces: docker-engine Homepage: https://www.docker.com Download-Size: 22.5 MB APT-Manual-Installed: yes APT-Sources: https://download.docker.com/linux/ubuntu bionic/edge amd64 Packages Description: Docker: the open-source application container engine Docker is a product for you to build, ship and run any application as a lightweight container . Docker containers are both hardware-agnostic and platform-agnostic. This means they can run anywhere, from your laptop to the largest cloud compute instance and everything in between - and they don't require you to use a particular language, framework or packaging system. That makes them great building blocks for deploying and scaling web apps, databases, and backend services without depending on a particular stack or provider. N: There are 29 additional records. Please use the '-a' switch to see them.
我們希望新的 Linux 用戶和開發人員會發現這些命令很有用。快樂編碼。