哦最常見的問題之一是如何使用包管理器(例如 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 用戶的主要障礙是 location 命令。但是在這個簡單頁面的幫助下,您可以找到命令路徑,甚至可以使用手冊頁獲得幫助。 假設您在 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 用戶和開發人員會發現這些命令很有用。快樂編碼。