Linux基礎命令注釋(2)


Linux基礎命令注釋(2)

ln 鏈接文件

  • ln -s [源文件] [鏈接名稱] 軟連接
[root@localhost ~]# ln -s anaconda-ks.cfg acd
[root@localhost ~]# ls -l
總用量 20
drwxr-xr-x. 3 root root   37 9月   8 11:02 a
-rw-r--r--. 1 root root   21 9月   8 09:31 abc
lrwxrwxrwx. 1 root root   15 9月  10 09:46 acd -> anaconda-ks.cfg
-rw-------. 1 root root 1451 9月   6 22:57 anaconda-ks.cfg


  • ln [源文件][連接名] 硬鏈接
[root@localhost ~]# ln anaconda-ks.cfg vbn
[root@localhost ~]# ll
總用量 24
drwxr-xr-x. 3 root root   37 9月   8 11:02 a
-rw-r--r--. 1 root root   21 9月   8 09:31 abc
lrwxrwxrwx. 1 root root   15 9月  10 09:46 acd -> anaconda-ks.cfg
-rw-------. 2 root root 1451 9月   6 22:57 anaconda-ks.cfg
-rw-r--r--. 1 root root    0 9月   7 15:56 bbb
drwxr-xr-x. 3 root root   15 9月   7 16:33 c
-rw-r--r--. 1 root root  327 9月   7 16:42 cc
-rw-r--r--. 1 root root  126 9月   7 15:53 qwq
-rw-------. 2 root root 1451 9月   6 22:57 vbn

copy 復制文件,一個文件到一個文件,多個文件到目錄

  • cp
[root@localhost ~]# ls
a  abc  acd  anaconda-ks.cfg  bbb  c  cc  qwq  vbn  wqw
[root@localhost ~]# cp abc cc
cp:是否覆蓋"cc"? y

  • -a 歸檔復制,常用於備份
[root@localhost ~]# ls
a  abc   acd  anaconda-ks.cfg  bbb  c  cc  qwq  vbn  wqw
[root@localhost ~]# cp -a abc acb
[root@localhost ~]# ls
a  abc  acb  acd  anaconda-ks.cfg  bbb  c  cc  qwq  vbn  wqw

  • -r遞歸復制,拷貝目錄時必須使用此選項
[root@localhost ~]# ls 
a  abc  acb  acd  anaconda-ks.cfg  bbb  c  cc  qwq  vbn  wqw
[root@localhost ~]# ls c
[root@localhost ~]# 
[root@localhost ~]# cp -r a c


cat 與 tac

  • cat 拼接文件內容並輸出至標准輸出(屏幕)
[root@localhost ~]# cat qwq
rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.

[root@localhost ~]# cat qwq wqw
rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.
rootpw --iscrypted $6$15KaJSMJ1CnXnZP6$i.4EoTpZwTUTcZhK0oYRIjgyP9UTYbXsq//IV4xIiaB.2RfwtJP7SzhiAN4KcrAZP1ABjRIPx9pdl7vXdHoJk.
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty

  • -n顯示行數
[root@localhost ~]# cat -n anaconda-ks.cfg 
     1	#version=DEVEL
     2	# System authorization information
     3	auth --enableshadow --passalgo=sha512
     4	repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
     5	repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
     6	# Use CDROM installation media
     7	cdrom
     8	# Use graphical install
     9	graphical
    10	# Run the Setup Agent on first boot
    11	firstboot --enable
    12	ignoredisk --only-use=sda
    13	# Keyboard layouts
    14	keyboard --vckeymap=cn --xlayouts='cn'
    15	# System language
    16	lang zh_CN.UTF-8
    .....


  • tac 鏈接文件並倒序打印內容至標准輸出
[root@localhost ~]# cat /etc/issue
\S
Kernel \r on an \m

[root@localhost ~]# tac /etc/issue

Kernel \r on an \m
\S

more 全屏查看文本內容從前往后看完后自動退出(空格后翻)

[root@localhost ~]# more anaconda-ks.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvaila
bility
repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientS
torage
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
...

less: 全屏查看文本內容空格后翻頁,b 前翻頁,看完不會自動退出,q 退出

[root@localhost ~]# less anaconda-ks.cfg 

head 與tail

  • head 從文件首部打印文件內容,默認10行
[root@localhost ~]# head anaconda-ks.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot

-[n]顯示n行

[root@localhost ~]# head -15 anaconda-ks.cfg 
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language

[root@localhost ~]# cat anaconda-ks.cfg |head -15
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language

  • tail 從文件尾部打印文件內容,默認10行
[root@localhost ~]# tail anaconda-ks.cfg 

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end


-[n]顯示n行

[root@localhost ~]# tail -15 anaconda-ks.cfg 
@core
chrony
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end


[root@localhost ~]# cat anaconda-ks.cfg |tail -15
@core
chrony
kexec-tools

%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end


  • 只顯示[n]行
[root@localhost ~]# cat anaconda-ks.cfg |head -11 | tail -1
firstboot --enable


[root@localhost ~]# head -11 anaconda-ks.cfg | tail -1
firstboot --enable

du 查看文件或目錄占用的磁盤空間大小

  • du 查看文件或目錄占用的磁盤空間大小
[root@localhost ~]# du a
0	a/c
4	a

  • -s只查看本目錄
[root@localhost ~]# du -s a
4	a

  • -h 顯示目錄文件大小
[root@localhost ~]# du -sh a
4.0K	a

  • wc文本統計; -c:統計文本字節數; w:統計文本單詞數; -l:統計文本行數l
[root@localhost ~]# wc abc
 3  3 21 abc
[root@localhost ~]# wc -c abc
21 abc
[root@localhost ~]# wc -w abc
3 abc
[root@localhost ~]# wc -l abc
3 abc

df 報告文件系統磁盤空間使用情

  • df 報告文件系統磁盤空間使用情況
[root@localhost ~]# df
文件系統                 1K-塊   已用     可用 已用% 掛載點
/dev/mapper/rhel-root 40137576 971488 39166088    3% /
devtmpfs                922456      0   922456    0% /dev
tmpfs                   933524      0   933524    0% /dev/shm
tmpfs                   933524   8844   924680    1% /run
tmpfs                   933524      0   933524    0% /sys/fs/cgroup
/dev/sda1              1038336 145824   892512   15% /boot
/dev/mapper/rhel-home 19593216  32956 19560260    1% /home
tmpfs                   186708      0   186708    0% /run/user/0

  • -h : 單位轉換,以更友好的方式顯示大小
[root@localhost ~]# df -h
文件系統               容量  已用  可用 已用% 掛載點
/dev/mapper/rhel-root   39G  949M   38G    3% /
devtmpfs               901M     0  901M    0% /dev
tmpfs                  912M     0  912M    0% /dev/shm
tmpfs                  912M  8.7M  904M    1% /run
tmpfs                  912M     0  912M    0% /sys/fs/cgroup
/dev/sda1             1014M  143M  872M   15% /boot
/dev/mapper/rhel-home   19G   33M   19G    1% /home
tmpfs                  183M     0  183M    0% /run/user/0

hostname 修改主機名

  • hostname 查看或臨時修改主機名,重開終端有效,重啟失效
[root@hostnamectl ~]# hostname
hostnamectl
[root@hostnamectl ~]# hostname M
[root@hostnamectl ~]# hostname
M

  • hostnmectl 修改主機名(會修改配置文件 ),重開終端有效,重啟依然有效
[root@M ~]# hostnamectl set-hostname hostnamectl
[root@M ~]# hostname
hostnamectl
[root@M ~]# shutdown -r now
Last login: Tue Sep 10 13:00:46 2019 from 192.168.213.1
[root@hostnamectl ~]# 


who

[root@hostnamectl ~]# who       //顯示當前登錄用戶
root     pts/0        2019-09-10 13:02 (192.168.213.1)
[root@hostnamectl ~]# w     //顯示當前在線用戶並顯示其正在運行的命令
 13:06:14 up 3 min,  1 user,  load average: 0.01, 0.01, 0.01
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.213.1    13:02    6.00s  0.07s  0.06s w
[root@hostnamectl ~]# whoami            //顯示當前登錄用戶
root
[root@hostnamectl ~]# who am i          //顯示當前登錄用戶
root     pts/0        2019-09-10 13:02 (192.168.213.1)
[root@hostnamectl ~]# 

  • tty 查看你的終端
[root@hostnamectl ~]# tty
/dev/pts/0

which 查看命令的絕對路徑

[root@hostnamectl ~]# which ls
alias ls='ls --color=auto'
	/usr/bin/ls

clear 清屏

  • clear 或者 Ctrl+l
[root@hostnamectl ~]# clear
[root@hostnamectl ~]# 

cal 打印日歷

[root@hostnamectl ~]# cal
      九月 2019     
日 一 二 三 四 五 六
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

  • [n]輸出n年的日歷1~9999
[root@hostnamectl ~]# cal 2012
                               2012                               

        一月                   二月                   三月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
 1  2  3  4  5  6  7             1  2  3  4                1  2  3
 8  9 10 11 12 13 14    5  6  7  8  9 10 11    4  5  6  7  8  9 10
15 16 17 18 19 20 21   12 13 14 15 16 17 18   11 12 13 14 15 16 17
22 23 24 25 26 27 28   19 20 21 22 23 24 25   18 19 20 21 22 23 24
29 30 31               26 27 28 29            25 26 27 28 29 30 31

        四月                   五月                   六月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
 1  2  3  4  5  6  7          1  2  3  4  5                   1  2
 8  9 10 11 12 13 14    6  7  8  9 10 11 12    3  4  5  6  7  8  9
15 16 17 18 19 20 21   13 14 15 16 17 18 19   10 11 12 13 14 15 16
22 23 24 25 26 27 28   20 21 22 23 24 25 26   17 18 19 20 21 22 23
29 30                  27 28 29 30 31         24 25 26 27 28 29 30

        七月                   八月                   九月        
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
 1  2  3  4  5  6  7             1  2  3  4                      1
 8  9 10 11 12 13 14    5  6  7  8  9 10 11    2  3  4  5  6  7  8
15 16 17 18 19 20 21   12 13 14 15 16 17 18    9 10 11 12 13 14 15
22 23 24 25 26 27 28   19 20 21 22 23 24 25   16 17 18 19 20 21 22
29 30 31               26 27 28 29 30 31      23 24 25 26 27 28 29
                                              30
        十月                  十一月                 十二月       
日 一 二 三 四 五 六   日 一 二 三 四 五 六   日 一 二 三 四 五 六
    1  2  3  4  5  6                1  2  3                      1
 7  8  9 10 11 12 13    4  5  6  7  8  9 10    2  3  4  5  6  7  8
14 15 16 17 18 19 20   11 12 13 14 15 16 17    9 10 11 12 13 14 15
21 22 23 24 25 26 27   18 19 20 21 22 23 24   16 17 18 19 20 21 22
28 29 30 31            25 26 27 28 29 30      23 24 25 26 27 28 29
                                              30 31


ldd 查看命令依賴那些庫

[root@hostnamectl ~]# ldd /usr/bin/ls
	linux-vdso.so.1 =>  (0x00007ffe917ec000)
	libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f3a56334000)
	libcap.so.2 => /lib64/libcap.so.2 (0x00007f3a5612f000)
	libacl.so.1 => /lib64/libacl.so.1 (0x00007f3a55f25000)
	libc.so.6 => /lib64/libc.so.6 (0x00007f3a55b62000)
	libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f3a55900000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007f3a556fb000)
	/lib64/ld-linux-x86-64.so.2 (0x00005561b7879000)
	libattr.so.1 => /lib64/libattr.so.1 (0x00007f3a554f6000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f3a552da000)


date 時間

[root@hostnamectl ~]# date
2019年 09月 10日 星期二 13:21:59 CST

[root@hostnamectl ~]# date -s '2019-09-10 13:21:30'
2019年 09月 10日 星期二 13:21:30 CST

  • 格式化輸出時間:
    +%Y:年
    +%m:月
    +%d:日
    +%H:時
    +%M:分
    +%S:秒
[root@hostnamectl ~]# date +%y
19
[root@hostnamectl ~]# date +%m
09
[root@hostnamectl ~]# date +%d
10
[root@hostnamectl ~]# date +%H
13
[root@hostnamectl ~]# date +%M
56
[root@hostnamectl ~]# date +%MS
  • 創建當前時間文件
[root@hostnamectl ~]# touch $(date '+%Y%m%d')
[root@hostnamectl ~]# ls
20190910  a  abc  acb  acd  anaconda-ks.cfg  bbb 

幫助

  • help command 內置命令
[root@hostnamectl ~]# 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.

  • CMMAND --help 外部命令
[root@hostnamectl ~]# ls --help
用法:ls [選項]... [文件]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all			不隱藏任何以. 開始的項目
  -A, --almost-all		列出除. 及.. 以外的任何項目
      --author			與-l 同時使用時列出每個文件的作者
  -b, --escape			以八進制溢出序列表示不可打印的字符
      --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                               '--block-size=M' prints sizes in units of
                               1,048,576 bytes; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of fil
  • man手冊
    []:可選

<>:必選

…:可出現多次

|:多選一

{}:分組

NAME:命令名稱及功能簡要說明

SYNOPSIS:用法說明,包括可用的選項

DESCRIPTION:命令功能的詳盡說明,可能包括每一個選項的意義

OPTIONS:說明每一個選項的意義

FILES:此命令相關的配置文件

BUGS:報告bug

EXAMPLES:命令示例

SEE ALSO:另外參照

翻屏:空格(向后翻一屏),b鍵(向前翻一屏)

查找:
/KEYWORD:從前往后查找KEYWORD
?KEYWORD:從后往前查找KEYWORD
n:下一個匹配的行
N:前一個匹配的行
q:退出

man

大寫N查找上一個

小寫n查找下一個

   Mandatory arguments to long options are mandatory for short options  too.

       -a, --all
              do not ignore entries starting with .

       -A, --almost-all
              do not list implied . and ..

       --author
              with -l, print the author of each file

       -b, --escape
              print C-style escapes for nongraphic characters

       --block-size=SIZE
              scale sizes by SIZE before printing them; e.g.,  '--block-size=M'  prints
              sizes in units of 1,048,576 bytes; see SIZE format below

       -B, --ignore-backups
              do not list implied entries ending with ~

       -c     with  -lt:  sort  by,  and show, ctime (time of last modification of file
              status information); with -l: show ctime and  sort  by  name;  otherwise:
              sort by ctime, newest first

       -C     list entries by columns
 Manual page ls(1) line 15 (press h for help or q to quit)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM