Linux basic commands comments (2)

Linux basic commands comments (2)

ln link file

  • ln -s [source] [link name] soft connection
[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 [source] [connection name] hard links
[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 copy a file, a file to a file, multiple files to a directory

  • 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 archive copy, commonly used in backup
[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 recursive copy, you must use this option when copying directories
[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 and tac

  • cat stitching contents of the file and output to the standard output (screen)
[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 number of display lines
[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 reverse link file and print content to standard output
[root@localhost ~]# cat /etc/issue
\S
Kernel \r on an \m

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

Kernel \r on an \m
\S

more full-screen view text automatically exit the front (after the space turning) back after reading

[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: full-screen view after page text box, b front page, reading does not automatically quit, q quit

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

head 与tail

  • print head from the file header of the file content, the default 10 lines
[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 display lines

[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

  • From the tail end of the file to print the contents of a file, the default 10 lines
[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 display lines

[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

  • Displays [n] lines
[root@localhost ~]# cat anaconda-ks.cfg |head -11 | tail -1
firstboot --enable

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

du view files or directories take up disk space

  • du view files or directories take up disk space
[root@localhost ~]# du a
0   a/c
4   a

  • -s only view the catalog
[root@localhost ~]# du -s a
4   a

  • -h display the directory file size
[root@localhost ~]# du -sh a
4.0K    a

  • wc text statistics; -c: count the number of text bytes; w: count the number of words of text; -l: Number of lines of text l Statistics
[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 report file system disk space usage

  • df report file system disk space usage
[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: unit conversion, display size in a more friendly way
[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 modify the hostname

  • hostname view or modify temporary host name, reopen the terminal is valid, failure to restart
[root@hostnamectl ~]# hostname
hostnamectl
[root@hostnamectl ~]# hostname M
[root@hostnamectl ~]# hostname
M

  • hostnmectl modify the host name (will modify the configuration file), the reopening of the terminal effective, restart is still valid
[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 ~]# 

  • Check your tty terminal
[root@hostnamectl ~]# tty
/dev/pts/0

which view commands absolute path

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

clear clear screen

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

cal Calendar Print

[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] output of the calendar year n 1 to 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 command to view those dependent libraries

[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 time

[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

  • Formatting Output Time:
    +% the Y: Year
    +% m: month
    +% d: Day
    +% H: When
    +% M: fraction
    +% S: seconds
[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
  • Current file creation time
[root@hostnamectl ~]# touch $(date '+%Y%m%d')
[root@hostnamectl ~]# ls
20190910  a  abc  acb  acd  anaconda-ks.cfg  bbb 

help

  • help command built-in 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 external command
[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 manual
    []: Optional

<>: Required

...: there may be many times

|: A multiple-choice

{}: Packet

NAME: command name and a brief description of the function

SYNOPSIS: Usage Notes, including the options available

DESCRIPTION: detailed description of the command function, and may include the meaning of each option

OPTIONS: explain the significance of each option

FILES: This command related configuration files

BUGS: report a bug

EXAMPLES: Example command

SEE ALSO: additional reference

Scroll: space (turned back one screen), b key (flip ahead a screen)

Find:
/ KEYWORD: front to back to find KEYWORD
KEYWORD:? From the look KEYWORD forward
n: the next matching row
row before a match: N
q: quit

man

Find on a capital N

Lowercase n Find Next

   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)

Guess you like

Origin www.cnblogs.com/guilai/p/11527475.html