ls [選項] [路徑或文件]
ls 選項及說明linux
-a 顯示指定目錄下的全部文件以及子目錄,包含隱藏文件 -d 只顯示目錄列表,不顯示文件 -l 除文件名稱外,同時將文件或者子目錄的權限,使用者和文件大小等詳細信息列出 -s 在每一個文件名後輸出該文件的大小 -k 以k字節的形式表示文件的大小 -u 以文件上次被訪問的時間排序 -t 以時間排序 -o 顯示除組外的詳細信息 -x 按列輸出,橫向排序 -r 對目錄反向排序 -q 用「?」代替不可輸出的字符 -m 橫向輸出文件名,並以「,」做爲分隔符 -S 以文件大小排序 -R 列出全部子目錄下的文件 -pF 在每一個文件名後附上一個字符以說明該文件的類型。「*」表示可執行的普通文件,「/」表示目錄,「@」表示符號連接,「|」表示FIFO,「=」表示套接字(socket) -C 按列輸出,縱向排序 -Q 把輸出的文件名用雙引號括起來
[root@cinder01 ~]# ls -l /home/ total 142448 drwxr-xr-x 2 root root 39 Feb 23 2017 files -rw-r--r-- 1 root root 1486 Feb 23 2017 iperf.sh drwxr-xr-x 8 root root 4096 Feb 17 2017 jdk drwx------ 6 jenkins jenkins 145 Sep 12 17:01 jenkins -rw-r--r-- 1 root root 67025973 Aug 26 2016 op-adapter.war -rw-r--r-- 1 root root 78829122 Aug 26 2016 op-user.war drwx------ 2 user001 user001 79 Aug 10 16:18 user001
顯示/home/jenkins 下的全部文件以及子目錄的詳細信息,並顯示文件類型標記shell
[root@cinder01 jenkins]# ls -alF total 20 drwx------ 6 jenkins jenkins 145 Sep 12 17:01 ./ drwxr-xr-x. 8 root root 4096 Sep 21 10:33 ../ -rw------- 1 jenkins jenkins 187 Jul 20 20:04 .bash_history -rw-r--r-- 1 jenkins jenkins 18 Dec 7 2016 .bash_logout -rw-r--r-- 1 jenkins jenkins 193 Dec 7 2016 .bash_profile -rw-r--r-- 1 jenkins jenkins 231 Dec 7 2016 .bashrc drwxr-xr-x 3 jenkins jenkins 19 Sep 12 17:01 .groovy/ drwxr-xr-x 2 jenkins jenkins 39 Sep 12 16:52 .oracle_jre_usage/ drwx------ 2 jenkins jenkins 58 Jul 20 17:49 .ssh/ drwxr-xr-x 2 root root 58 Aug 2 10:34 xies03_new/
pwd
[root@cinder01 jenkins]# pwd /home/jenkins
cd [目錄名]
cd 命令的選項及其說明:緩存
cd [目錄] 切換到指定目錄下 cd 或者 cd ~ 返回用戶的默認工做目錄下 cd ~[用戶名] 返回指定用戶的工做目錄下 cd .. 或者 cd../ 返回到上級工做目錄下 cd / 返回到根目錄下
[root@cinder01 ~]# cd /usr/bin/ [root@cinder01 bin]# pwd /usr/bin
返回到上級目錄安全
[root@cinder01 bin]# cd .. [root@cinder01 usr]# pwd /usr
date [選項] 顯示時間格式(以+開頭,後面接時間格式)
date 命令的選項及其說明bash
-s --set: 設置系統時間 -d --date: 顯示描述的日期
時間顯示格式:oracle
%H 顯示小時,表示格式範圍00~23 %I 顯示小時,表示格式範圍00~12 %k 顯示小時,表示格式範圍0~23 %M 顯示分鐘,顯示格式範圍00~59 %S 顯示秒鐘,顯示格式範圍00~59 %p 顯示是AM(上午)仍是PM(下午) %r 顯示時間,格式爲 hh:mm:ss AM或者PM %T 顯示時間,格式爲 hh:mm:ss %x 顯示年份和日期,格式爲 mm/dd/yyyy %X 顯示時間格式,至關於%H:%M:%S的組合 %a 顯示星期幾 %b 顯示月份,月份的簡稱 %B 顯示月份,月份的全稱 %m 顯示月份,表示格式爲01~12 %Z 顯示時區 %d 顯示一個月的第幾天 %D 顯示年份和月份,格式mm/dd/yy %Y 顯示年份,顯示完整的年份 %y 顯示年份,顯示年份的最後兩個數字 %c 顯示日期和時間格式,至關於「%a%d%b%Y%r%Z」的組合
[root@cinder01 ~]# date Tue Sep 26 15:48:43 CST 2017
用制定的格式顯示時間和日期less
[root@cinder01 ~]# date "+%Y-%m-%d" 2017-09-26
修改系統時間ssh
[root@cinder01 ~]# date -s 20160930 Fri Sep 30 00:00:00 CST 2016
passwd [用戶名]
[root@cinder01 ~]# passwd user001 Changing password for user user001. New password: Retype new password: passwd: all authentication tokens updated successfully. [root@cinder01 ~]#
根據提示,連續輸入兩次密碼便可。socket
root 用戶修改密碼操作系統
[root@cinder01 ~]# passwd root 或: [root@cinder01 ~]# passwd
su [選項] [用戶名]
su 命令的選項及其說明
-加載相應用戶下的環境變量 -l 使當前的shell成爲改變身份後用戶默認的shell -c 改變身份運行一個指令後就結束 -m 改變用戶身份,但不改變環境變量
[user001@cinder01 ~]$ su - Password:
輸入root密碼後便可進入root的bash shell環境下
clear
man [命令全稱]
[root@cinder01 ~]# man ls LS(1) User Commands LS(1) NAME ls - list directory contents SYNOPSIS ls [OPTION]... [FILE]... DESCRIPTION
who [選項] [file]
who 命令的通常輸出格式以下:
名稱 [狀態] 終端時間 [活動] [進程標識] (主機名) 名稱:用戶的登陸名 狀態:代表終端是否對用戶都是可寫的 時間:用戶登陸系統的時間 活動:某個用戶在本身的終端上最後一次活動發生以來到如今的時間 進程標識:用戶登陸shell的進程id 主機名:登錄到linux系統上的客戶端機器標識
who 命令的選項及說明:
-a 列出全部信息,至關於全部選項 -b 列出系統最近啓動的日期 -l 列車全部可登陸的終端信息 -m 僅列出關於當前zhong -q 列出在本地系統上的用戶和用戶數的清單 -r 顯示當前系統的運行級別 -s 僅顯示名稱、終端和時間字段信息(who的默認輸出) -u 顯示當前每一個用戶的用戶名,登陸終端、終端活動和進程標識 -T或-w 顯示tty終端的狀態,「+」表示對任何人可寫,「-」表示僅對root用戶或全部者可寫,「?」表示遇到終端故障
[root@cinder01 ~]# who -r run-level 3 2017-04-26 00:13
顯示系統最近啓動日期,以及當前每一個用戶的登錄詳情,終端狀態
[root@cinder01 ~]# who -buT system boot 2017-04-26 00:12 root + pts/0 2017-08-26 04:16 . 19192 (192.168.180.38)
w [選項] [用戶]
w 命令的選項及其說明
-h 不顯示輸出信息的標題 -l 用長格式輸出 -s 用短格式輸出,不顯示登陸時間、JCPU 和 PCPU -V 顯示版本信息
[用戶] 表示當指定用戶後,只顯示該用戶的信息
[root@cinder01 ~]# w 04:25:03 up 153 days, 20:03, 1 user, load average: 0.08, 0.04, 0.05 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root pts/0 192.168.180.38 04:16 7.00s 1.13s 0.95s w [root@cinder01 ~]#
解釋:
uname [選項]
uname 命令的選項及其說明
-a 顯示操做系統所有信息 -m 顯示系統CPU類型(32位或64位) -n 顯示操做系統的主機名 -s 顯示操做系統類型 -r 顯示操做系統內核版本
[root@cinder01 ~]# uname -a Linux cinder01 3.10.0-514.2.2.el7.x86_64 #1 SMP Tue Dec 6 23:06:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux [root@cinder01 ~]# uname -m x86_64 [root@cinder01 ~]# uname -n cinder01 [root@cinder01 ~]# uname -s Linux [root@cinder01 ~]# uname -r 3.10.0-514.2.2.el7.x86_64
uptime
uptime 輸出當前系統時間,系統開機到如今運行時間、目前有多少用戶在線和系統平均負載
[root@cinder01 ~]# uptime 04:46:21 up 153 days, 20:24, 1 user, load average: 0.00, 0.01, 0.05 [root@cinder01 ~]#
last [選項][-n(顯示行數)]
last命令選項及其說明
-a 把登入系統的主機名或IP地址顯示在最後一行 -R 不顯示登入系統的主機名或IP地址 -x 顯示系統關機,從新開機以及執行等級的改變信息 -n 設置列出名單的顯示列數 -d 將顯示的IP地址轉換成主機名稱
[root@cinder01 ~]# last -n 5 root pts/0 192.168.180.38 Sat Aug 26 04:16 still logged in root pts/0 192.168.180.38 Tue Sep 26 15:03 - 02:46 (-31+-12:-17 root pts/2 192.168.180.38 Tue Sep 26 10:26 - 13:27 (03:01) root pts/0 192.168.180.38 Tue Sep 26 09:48 - 12:00 (02:11) root pts/0 192.168.180.38 Thu Sep 21 17:40 - 19:51 (02:11) wtmp begins Tue Dec 20 16:13:46 2016 [root@cinder01 ~]#
dmesg [選項]
dmesg 命令的選項及其說明
-c 顯示開機信息後,清除ring buffer信息 -s 設置緩衝區大小,默認設置爲8192 -n 設置記錄信息的層級
[root@cinder01 ~]# dmesg | less [ 0.000000] Initializing cgroup subsys cpuset [ 0.000000] Initializing cgroup subsys cpu [ 0.000000] Initializing cgroup subsys cpuacct ......
free [選項] [-s (間隔秒數)]
free 命令的選項及其說明
-b 以字節爲單位顯示內存使用狀況 -m 以MB爲單位顯示內存使用狀況 -K 以KB爲單位顯示內存使用狀況 -t 顯示內存總和列 -s 根據指定的間隔秒數持續顯示內存使用狀況 -o 不顯示系統緩衝區列
[root@cinder01 ~]# free -b total used free shared buff/cache available Mem: 3975155712 3379781632 207343616 50302976 388030464 277786624 Swap: 4294963200 15134720 4279828480 [root@cinder01 ~]# [root@cinder01 ~]# free -m total used free shared buff/cache available Mem: 3791 3223 197 47 370 264 Swap: 4095 14 4081 [root@cinder01 ~]# [root@cinder01 ~]# free total used free shared buff/cache available Mem: 3881988 3300568 202484 49124 378936 271276 Swap: 4194300 14780 4179520 [root@cinder01 ~]#
ps [選項]
ps 經常使用選項介紹
-a 顯示全部用戶的進程,包含每一個程序的完整路徑 -x 顯示全部系統程序,包括沒有終端的程序 -u 顯示全部者的名稱和起始時間 -f 詳細顯示程序執行的路徑羣 -c 只顯示進程的名稱,不顯示進程完整路徑 -e 將除內核進程之外全部進程的信息寫到標準輸出
[root@cinder01 ~]# ps PID TTY TIME CMD 19192 pts/0 00:00:00 bash 19261 pts/0 00:00:00 ps [root@cinder01 ~]#
解釋:
查看系統全部進程
[root@cinder01 ~]# ps -ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 Mar25 ? 00:05:06 /usr/lib/systemd/systemd --switched-root --system --deserialize 21 root 2 0 0 Mar25 ? 00:00:05 [kthreadd] root 3 2 0 Mar25 ? 00:00:04 [ksoftirqd/0] root 7 2 0 Mar25 ? 00:00:36 [migration/0] root 8 2 0 Mar25 ? 00:00:00 [rcu_bh] root 9 2 0 Mar25 ? 00:31:24 [rcu_sched] root 10 2 0 Mar25 ? 00:01:15 [watchdog/0] root 11 2 0 Mar25 ? 00:01:40 [watchdog/1] ......
[注]:ps 最經常使用的命令組合 ps -ef | ps -aux
top 命令提供對系統處理器狀態的實時監控,顯示系統的各個進程資源佔用情況
top [選項]
top 命令的經常使用選項說明
-d 指定每兩次屏幕信息刷新之間的時間間隔 -i 不顯示閒置或者僵死的進程信息 -c 顯示進程的整個命令路徑,而不僅顯示命令名稱 -s 使top命令在安全模式下運行 -b 分屏顯示輸出信息,結合「-n」選項能夠將屏幕信息輸出到文檔 -n top輸出信息更新的次數,完成後退出top命令
[root@cinder01 ~]# top top - 05:27:50 up 153 days, 21:06, 1 user, load average: 0.00, 0.01, 0.05 Tasks: 123 total, 1 running, 122 sleeping, 0 stopped, 0 zombie %Cpu(s): 0.1 us, 0.0 sy, 0.0 ni, 99.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 3881988 total, 201788 free, 3300988 used, 379212 buff/cache KiB Swap: 4194300 total, 4179520 free, 14780 used. 270844 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 666 root 20 0 24324 1540 1280 S 0.3 0.0 1:31.81 systemd-logind 1 root 20 0 190676 3260 2088 S 0.0 0.1 5:06.45 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:05.54 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:04.42 ksoftirqd/0 7 root rt 0 0 0 0 S 0.0 0.0 0:36.34 migration/0 8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh 9 root 20 0 0 0 0 S 0.0 0.0 31:24.74 rcu_sched 10 root rt 0 0 0 0 S 0.0 0.0 1:15.65 watchdog/0 ... ... [root@cinder01 ~]#
解釋:
參考自:< <循環漸進linux第2版> >