Linux命令2

Linux命令:

1、uptime:输入系统运行信息


    [root@demo6 ~]# uptime
 20:44:17 up 47 min,  2 users,  load average: 0.00, 0.01, 0.03


20:44:17:系统时间
up:状态
47 min: 运行了多久
2 users:用户数量
0.00:五分钟平均负载
0.01:十分钟平均负载
0.03:十五分钟平均负载

2、top:实时显示系统负载,以及每个进程的资源占用情况

[root@demo6 ~]# top
top - 20:49:16 up 52 min,  2 users,  load average: 0.00, 0.01, 0.03
Tasks:  76 total,   1 running,  75 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  0.3%sy,  0.0%ni, 99.3%id,  0.0%wa,  0.0%hi,  0.3%si,  0.0%st
Mem:   1004136k total,   191232k used,   812904k free,    26892k buffers
Swap:  2097148k total,        0k used,  2097148k free,    42088k cached

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
     1 root      20   0 19232 1492 1224 S  0.0  0.1   0:01.82 init
     2 root      20   0     0    0    0 S  0.0  0.0   0:00.02 kthreadd
     3 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 migration/0
     4 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
     5 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 stopper/0
     6 root      RT   0     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
     7 root      20   0     0    0    0 S  0.0  0.0   0:03.15 events/0
     8 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events/0
     9 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_long/0
    10 root      20   0     0    0    0 S  0.0  0.0   0:00.00 events_power_ef
    11 root      20   0     0    0    0 S  0.0  0.0   0:00.00 cgroup
    12 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khelper
    13 root      20   0     0    0    0 S  0.0  0.0   0:00.00 netns
    14 root      20   0     0    0    0 S  0.0  0.0   0:00.00 async/mgr
    15 root      20   0     0    0    0 S  0.0  0.0   0:00.00 pm
    16 root      20   0     0    0    0 S  0.0  0.0   0:00.02 sync_supers
    17 root      20   0     0    0    0 S  0.0  0.0   0:00.01 bdi-default
    18 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kintegrityd/0
    19 root      20   0     0    0    0 S  0.0  0.0   0:00.51 kblockd/0
    20 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpid
    21 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_notify
    22 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kacpi_hotplug
    23 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ata_aux
    24 root      20   0     0    0    0 S  0.0  0.0   0:00.01 ata_sff/0
    25 root      20   0     0    0    0 S  0.0  0.0   0:00.00 ksuspend_usbd
    26 root      20   0     0    0    0 S  0.0  0.0   0:00.05 khubd
    27 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kseriod
    28 root      20   0     0    0    0 S  0.0  0.0   0:00.00 md/0
    29 root      20   0     0    0    0 S  0.0  0.0   0:00.00 md_misc/0
    30 root      20   0     0    0    0 S  0.0  0.0   0:00.00 linkwatch
    33 root      20   0     0    0    0 S  0.0  0.0   0:00.00 khungtaskd
    34 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kswapd0
    35 root      25   5     0    0    0 S  0.0  0.0   0:00.00 ksmd
    36 root      39  19     0    0    0 S  0.0  0.0   0:00.00 khugepaged
    37 root      20   0     0    0    0 S  0.0  0.0   0:00.00 aio/0
    38 root      20   0     0    0    0 S  0.0  0.0   0:00.00 crypto/0
    45 root      20   0     0    0    0 S  0.0  0.0   0:00.00 kthrotld/0

ps:显示进程瞬间的运行动态

3、ps -ef:查看进程。


    [root@demo6 ~]# ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 19:56 ?        00:00:01 /sbin/init
root          2      0  0 19:56 ?        00:00:00 [kthreadd]
root          3      2  0 19:56 ?        00:00:00 [migration/0]
root          4      2  0 19:56 ?        00:00:00 [ksoftirqd/0]
root          5      2  0 19:56 ?        00:00:00 [stopper/0]
root          6      2  0 19:56 ?        00:00:00 [watchdog/0]
root          7      2  0 19:56 ?        00:00:03 [events/0]
root          8      2  0 19:56 ?        00:00:00 [events/0]
root          9      2  0 19:56 ?        00:00:00 [events_long/0]
root         10      2  0 19:56 ?        00:00:00 [events_power_ef]
root         11      2  0 19:56 ?        00:00:00 [cgroup]
root         12      2  0 19:56 ?        00:00:00 [khelper]
root         13      2  0 19:56 ?        00:00:00 [netns]
root         14      2  0 19:56 ?        00:00:00 [async/mgr]
root         15      2  0 19:56 ?        00:00:00 [pm]
root         16      2  0 19:56 ?        00:00:00 [sync_supers]
root         17      2  0 19:56 ?        00:00:00 [bdi-default]
root         18      2  0 19:56 ?        00:00:00 [kintegrityd/0]
root         19      2  0 19:56 ?        00:00:00 [kblockd/0]
root         20      2  0 19:56 ?        00:00:00 [kacpid]
root         21      2  0 19:56 ?        00:00:00 [kacpi_notify]
root         22      2  0 19:56 ?        00:00:00 [kacpi_hotplug]
root         23      2  0 19:56 ?        00:00:00 [ata_aux]
root         24      2  0 19:56 ?        00:00:00 [ata_sff/0]
root         25      2  0 19:56 ?        00:00:00 [ksuspend_usbd]
root         26      2  0 19:56 ?        00:00:00 [khubd]
root         27      2  0 19:56 ?        00:00:00 [kseriod]
root         28      2  0 19:56 ?        00:00:00 [md/0]
root         29      2  0 19:56 ?        00:00:00 [md_misc/0]
root         30      2  0 19:56 ?        00:00:00 [linkwatch]
root         33      2  0 19:56 ?        00:00:00 [khungtaskd]
root         34      2  0 19:56 ?        00:00:00 [kswapd0]
root         35      2  0 19:56 ?        00:00:00 [ksmd]
root         36      2  0 19:56 ?        00:00:00 [khugepaged]
root         37      2  0 19:56 ?        00:00:00 [aio/0]
root         38      2  0 19:56 ?        00:00:00 [crypto/0]
root         45      2  0 19:56 ?        00:00:00 [kthrotld/0]
root         46      2  0 19:56 ?        00:00:00 [pciehpd]
root         48      2  0 19:56 ?        00:00:00 [kpsmoused]
root         49      2  0 19:56 ?        00:00:00 [usbhid_resumer]
root         50      2  0 19:56 ?        00:00:00 [deferwq]
root         80      2  0 19:56 ?        00:00:00 [kdmremove]
root         81      2  0 19:56 ?        00:00:00 [kstriped]
root        112      2  0 19:56 ?        00:00:00 [ttm_swap]
root        248      2  0 19:56 ?        00:00:00 [scsi_eh_0]
root        251      2  0 19:56 ?        00:00:00 [scsi_eh_1]
root        263      2  0 19:56 ?        00:00:00 [mpt_poll_0]
root        264      2  0 19:56 ?        00:00:00 [mpt/0]
root        265      2  0 19:56 ?        00:00:00 [scsi_eh_2]
root        409      2  0 19:56 ?        00:00:01 [jbd2/sda2-8]
root        410      2  0 19:56 ?        00:00:00 [ext4-dio-unwrit]
root        494      1  0 19:56 ?        00:00:00 /sbin/udevd -d
root        628      2  0 19:56 ?        00:00:00 [vmmemctl]
root        766      2  0 19:56 ?        00:00:00 [bluetooth]
root        810      2  0 19:56 ?        00:00:00 [jbd2/sda1-8]
root        811      2  0 19:56 ?        00:00:00 [ext4-dio-unwrit]
root        859      2  0 19:56 ?        00:00:00 [kauditd]
root       1123      1  0 19:56 ?        00:00:00 auditd
root       1145      1  0 19:56 ?        00:00:00 /sbin/rsyslogd -i /var/run/sys
root       1228      1  0 19:56 ?        00:00:00 /usr/sbin/sshd
root       1253      1  0 19:56 ?        00:00:01 crond
root       1267      1  0 19:56 ?        00:00:00 login -- root
root       1269      1  0 19:56 tty2     00:00:00 /sbin/mingetty /dev/tty2
root       1271      1  0 19:56 tty3     00:00:00 /sbin/mingetty /dev/tty3
root       1273      1  0 19:56 tty4     00:00:00 /sbin/mingetty /dev/tty4
root       1275    494  0 19:56 ?        00:00:00 /sbin/udevd -d
root       1276    494  0 19:56 ?        00:00:00 /sbin/udevd -d
root       1278      1  0 19:56 tty5     00:00:00 /sbin/mingetty /dev/tty5
root       1280      1  0 19:56 tty6     00:00:00 /sbin/mingetty /dev/tty6
root       1284   1267  0 19:57 tty1     00:00:00 -bash
root       1422   1228  0 20:28 ?        00:00:00 sshd: root@pts/0
root       1426   1228  0 20:28 ?        00:00:00 sshd: root@notty
root       1430   1422  0 20:28 pts/0    00:00:00 -bash
root       1431   1426  0 20:28 ?        00:00:00 /usr/libexec/openssh/sftp-serv
root       1450      2  0 20:44 ?        00:00:00 [flush-8:0]
root       1610   1430  1 20:50 pts/0    00:00:00 ps -ef


4、ps -a:当前终端进程


    [root@demo6 ~]# ps -a
   PID TTY          TIME CMD
  1611 pts/0    00:00:00 ps


5、ps -u:用户的进程


    [root@demo6 ~]# ps -u
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       1269  0.0  0.0   4064   588 tty2     Ss+  19:56   0:00 /sbin/mingetty
root       1271  0.0  0.0   4064   588 tty3     Ss+  19:56   0:00 /sbin/mingetty
root       1273  0.0  0.0   4064   588 tty4     Ss+  19:56   0:00 /sbin/mingetty
root       1278  0.0  0.0   4064   592 tty5     Ss+  19:56   0:00 /sbin/mingetty
root       1280  0.0  0.0   4064   588 tty6     Ss+  19:56   0:00 /sbin/mingetty
root       1284  0.0  0.1 108312  1872 tty1     Ss+  19:57   0:00 -bash
root       1430  0.0  0.1 108316  1900 pts/0    Ss   20:28   0:00 -bash
root       1612  0.0  0.1 110236  1176 pts/0    R+   20:52   0:00 ps -u


6、 ps -ax:显示详细信息。


    [root@demo6 ~]# ps -ax
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
   PID TTY      STAT   TIME COMMAND
     1 ?        Ss     0:01 /sbin/init
     2 ?        S      0:00 [kthreadd]
     3 ?        S      0:00 [migration/0]
     4 ?        S      0:00 [ksoftirqd/0]
     5 ?        S      0:00 [stopper/0]
     6 ?        S      0:00 [watchdog/0]
     7 ?        S      0:03 [events/0]
     8 ?        S      0:00 [events/0]
     9 ?        S      0:00 [events_long/0]
    10 ?        S      0:00 [events_power_ef]
    11 ?        S      0:00 [cgroup]
    12 ?        S      0:00 [khelper]
    13 ?        S      0:00 [netns]
    14 ?        S      0:00 [async/mgr]
    15 ?        S      0:00 [pm]
    16 ?        S      0:00 [sync_supers]
    17 ?        S      0:00 [bdi-default]
    18 ?        S      0:00 [kintegrityd/0]
    19 ?        S      0:00 [kblockd/0]
    20 ?        S      0:00 [kacpid]
    21 ?        S      0:00 [kacpi_notify]
    22 ?        S      0:00 [kacpi_hotplug]
    23 ?        S      0:00 [ata_aux]
    24 ?        S      0:00 [ata_sff/0]
    25 ?        S      0:00 [ksuspend_usbd]
    26 ?        S      0:00 [khubd]
    27 ?        S      0:00 [kseriod]
    28 ?        S      0:00 [md/0]
    29 ?        S      0:00 [md_misc/0]
    30 ?        S      0:00 [linkwatch]
    33 ?        S      0:00 [khungtaskd]
    34 ?        S      0:00 [kswapd0]
    35 ?        SN     0:00 [ksmd]
    36 ?        SN     0:00 [khugepaged]
    37 ?        S      0:00 [aio/0]
    38 ?        S      0:00 [crypto/0]
    45 ?        S      0:00 [kthrotld/0]
    46 ?        S      0:00 [pciehpd]
    48 ?        S      0:00 [kpsmoused]
    49 ?        S      0:00 [usbhid_resumer]
    50 ?        S      0:00 [deferwq]
    80 ?        S      0:00 [kdmremove]
    81 ?        S      0:00 [kstriped]
   112 ?        S      0:00 [ttm_swap]
   248 ?        S      0:00 [scsi_eh_0]
   251 ?        S      0:00 [scsi_eh_1]
   263 ?        S      0:00 [mpt_poll_0]
   264 ?        S      0:00 [mpt/0]
   265 ?        S      0:00 [scsi_eh_2]
   409 ?        S      0:01 [jbd2/sda2-8]
   410 ?        S      0:00 [ext4-dio-unwrit]
   494 ?        S<s    0:00 /sbin/udevd -d
   628 ?        S      0:00 [vmmemctl]
   766 ?        S      0:00 [bluetooth]
   810 ?        S      0:00 [jbd2/sda1-8]
   811 ?        S      0:00 [ext4-dio-unwrit]
   859 ?        S      0:00 [kauditd]
  1123 ?        S<sl   0:00 auditd
  1145 ?        Sl     0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
  1228 ?        Ss     0:00 /usr/sbin/sshd
  1253 ?        Ss     0:01 crond
  1267 ?        Ss     0:00 login -- root
  1269 tty2     Ss+    0:00 /sbin/mingetty /dev/tty2
  1271 tty3     Ss+    0:00 /sbin/mingetty /dev/tty3
  1273 tty4     Ss+    0:00 /sbin/mingetty /dev/tty4
  1275 ?        S<     0:00 /sbin/udevd -d
  1276 ?        S<     0:00 /sbin/udevd -d
  1278 tty5     Ss+    0:00 /sbin/mingetty /dev/tty5
  1280 tty6     Ss+    0:00 /sbin/mingetty /dev/tty6
  1284 tty1     Ss+    0:00 -bash
  1422 ?        Ss     0:00 sshd: root@pts/0
  1426 ?        Ss     0:00 sshd: root@notty
  1430 pts/0    Ss     0:00 -bash
  1431 ?        Ss     0:00 /usr/libexec/openssh/sftp-server
  1450 ?        S      0:00 [flush-8:0]
  1613 pts/0    R+     0:00 ps -ax


7、ps -aux | grep 文件名 :列出指定进程。


    [root@demo6 ~]# ps -aux | grep ceu
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root       1616  0.0  0.0 103312   872 pts/0    S+   20:55   0:00 grep ceu
[root@demo6 ~]# ps -aux | grep bak
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root       1618  0.0  0.0 103312   876 pts/0    S+   20:56   0:00 grep bak


8、useradd 用户名:创建新用户


    [root@demo6 ~]# useradd test


9、passwd:修改当前用户密码


    [root@demo6 ~]# passwd
Changing password for user root.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.


root切换到普通用户不需要密码,普通用户到普通用户需要密码,普通用户到root需要密码。
10、su:切换用户
su 用户名:用户目录没有变换
su - 用户名:到用户家目录。

[root@demo6 ~]# su test
bash: alias: net: not found
bash: alias: =: not found
bash: alias: vi /etc/sysconfig/network-scripts/ificg-eth0: not found
[test@demo6 root]$

11、exit:退出当前用户


    [test@demo6 root]$ exit
    exit
    [root@demo6 ~]#


12、whoami 及 who -m:查询当前用户。


    [root@demo6 ~]# whoami
    root
    [root@demo6 ~]# who -m
    root     pts/0        2019-07-26 20:28 (192.168.234.1)
    [root@demo6 ~]#


13、mkdir:创建文件夹
mkdir bake:只能创建一层
mkdir -pv bake/dev/abc/……/:创建多层目录

[root@demo6 ~]# mkdir red
[root@demo6 ~]# ls
10               ceu       err     file1               red
anaconda-ks.cfg  cp-test1  erro1   file100             test1
bak              cp-test2  errof1  install.log         test10
bake             demo      error   install.log.syslog  yum.repo


 [root@demo6 ~]# mkdir -pv test/test1/test11
 mkdir: created directory `test'
 mkdir: created directory `test/test1'
 mkdir: created directory `test/test1/test11'
 [root@demo6 ~]# tree
.
 ├── 10
 ├── anaconda-ks.cfg
 ├── bak
 │   └── err
 ├── bake
 ├── ceu
 ├── cp-test1
 ├── cp-test2
 ├── demo
 │   └── file1
 ├── err
 ├── erro1
 ├── errof1
 ├── error
 ├── file1
 ├── file100
 ├── install.log
 ├── install.log.syslog
 ├── red
 ├── test
 │   └── test1
 │       └── test11
 ├── test1
 │   ├── file1
 │   ├── file2
 │   ├── file3 -> file1
 │   ├── file5 -> file1
 │   ├── test4
 │   ├── test6
 │   └── test8 -> test6
 ├── test10
 └── yum.repo

 9 directories, 23 files


14、创建文件:(1)>文件名
(2)touch 文件名

[root@demo6 ~]# > file
[root@demo6 ~]# ls
10               ceu       err     file         install.log.syslog  test10
anaconda-ks.cfg  cp-test1  erro1   file1        red                 yum.repo
bak              cp-test2  errof1  file100      test
bake             demo      error   install.log  test1


    [root@demo6 ~]# touch file10
    [root@demo6 ~]# ls
     10               ceu       err     file     install.log         test1
     anaconda-ks.cfg  cp-test1  erro1   file1    install.log.syslog  test10
     bak              cp-test2  errof1  file10   red                 yum.repo
     bake             demo      error   file100  test


15、查看文件内容:cat 文件名


    [root@demo6 ~]# cat ceu
    -rw-r--r--. 1 root root 0 Jul 24 10:39 ceu


16、拼接两个文件的内容:cat 文件名 文件名1


    [root@demo6 ~]# cat ceu err
    -rw-r--r--. 1 root root 0 Jul 24 10:39 ceu
     ls: cannot access test8: No such file or directory


17、把内容写入文件:echo “内容” >>file(文件名)


    [root@demo6 ~]# echo "lucille is a girl" >> file
    [root@demo6 ~]# cat file
    lucille is a girl


18、文件内容对比: diff 文件1 文件2


    [root@demo6 ~]# diff ceu file
    1c1
    < -rw-r--r--. 1 root root 0 Jul 24 10:39 ceu
    ---
   > lucille is a girl


19、查看文件前几行:head -20 文件名 (默认为十行)

[root@demo6 ~]# cat file10
total 84
-rw-r--r--. 1 root root    0 Jul 26 20:21 10
-rw-------. 1 root root  921 Jul 24 17:00 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Jul 25 20:51 bak
drwxr-xr-x. 2 root root 4096 Jul 24 11:13 bake
-rw-r--r--. 1 root root   43 Jul 24 10:39 ceu
drwxr-xr-x. 2 root root 4096 Jul 25 20:55 cp-test1
-rw-r--r--. 1 root root    0 Jul 25 20:56 cp-test2
drwxr-xr-x. 2 root root 4096 Jul 25 19:32 demo
-rw-r--r--. 1 root root   51 Jul 24 10:39 err
-rw-r--r--. 1 root root   32 Jul 24 17:58 erro1
-rw-r--r--. 1 root root   51 Jul 24 17:59 errof1
-rw-r--r--. 1 root root  101 Jul 24 10:38 error
-rw-r--r--. 1 root root 1318 Jul 26 21:26 file
-rw-r--r--. 1 root root    6 Jul 25 19:37 file1
-rw-r--r--. 1 root root    0 Jul 26 21:34 file10
-rw-r--r--. 1 root root    0 Jul 25 19:30 file100
-rw-r--r--. 1 root root 9615 Jul 24 17:00 install.log
-rw-r--r--. 1 root root 3357 Jul 24 16:59 install.log.syslog
drwxr-xr-x. 2 root root 4096 Jul 26 21:07 red
drwxr-xr-x. 3 root root 4096 Jul 26 21:11 test
drwxr-xr-x. 2 root root 4096 Jul 25 21:54 test1
-rw-r--r--. 1 root root 2975 Jul 26 20:20 test10
-rw-r--r--. 1 root root   71 Jul 25 19:28 yum.repo
[root@demo6 ~]# head -5 file10
total 84
-rw-r--r--. 1 root root    0 Jul 26 20:21 10
-rw-------. 1 root root  921 Jul 24 17:00 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Jul 25 20:51 bak
drwxr-xr-x. 2 root root 4096 Jul 24 11:13 bake


20、 查看结尾几行:tail -20 文件名(默认为十行)


[root@demo6 ~]# tail -5 file10
drwxr-xr-x. 2 root root 4096 Jul 26 21:07 red
drwxr-xr-x. 3 root root 4096 Jul 26 21:11 test
drwxr-xr-x. 2 root root 4096 Jul 25 21:54 test1
-rw-r--r--. 1 root root 2975 Jul 26 20:20 test10
-rw-r--r--. 1 root root   71 Jul 25 19:28 yum.repo


21、添加文件中行号:cat -n 文件名


    [root@demo6 ~]# cat -n file10
     1  total 84
     2  -rw-r--r--. 1 root root    0 Jul 26 20:21 10
     3  -rw-------. 1 root root  921 Jul 24 17:00 anaconda-ks.cfg
     4  drwxr-xr-x. 2 root root 4096 Jul 25 20:51 bak
     5  drwxr-xr-x. 2 root root 4096 Jul 24 11:13 bake
     6  -rw-r--r--. 1 root root   43 Jul 24 10:39 ceu
     7  drwxr-xr-x. 2 root root 4096 Jul 25 20:55 cp-test1
     8  -rw-r--r--. 1 root root    0 Jul 25 20:56 cp-test2
     9  drwxr-xr-x. 2 root root 4096 Jul 25 19:32 demo
    10  -rw-r--r--. 1 root root   51 Jul 24 10:39 err
    11  -rw-r--r--. 1 root root   32 Jul 24 17:58 erro1
    12  -rw-r--r--. 1 root root   51 Jul 24 17:59 errof1
    13  -rw-r--r--. 1 root root  101 Jul 24 10:38 error
    14  -rw-r--r--. 1 root root 1318 Jul 26 21:26 file
    15  -rw-r--r--. 1 root root    6 Jul 25 19:37 file1
    16  -rw-r--r--. 1 root root    0 Jul 26 21:34 file10
    17  -rw-r--r--. 1 root root    0 Jul 25 19:30 file100
    18  -rw-r--r--. 1 root root 9615 Jul 24 17:00 install.log
    19  -rw-r--r--. 1 root root 3357 Jul 24 16:59 install.log.syslog
    20  drwxr-xr-x. 2 root root 4096 Jul 26 21:07 red
    21  drwxr-xr-x. 3 root root 4096 Jul 26 21:11 test
    22  drwxr-xr-x. 2 root root 4096 Jul 25 21:54 test1
    23  -rw-r--r--. 1 root root 2975 Jul 26 20:20 test10
    24  -rw-r--r--. 1 root root   71 Jul 25 19:28 yum.repo


22、定位到某一行:vim +行号 文件名

在这里插入图片描述

23、去多个空行:cat -s 文件名


    [root@demo6 ~]# cat file10
total 84
-rw-r--r--. 1 root root    0 Jul 26 20:21 10
-rw-------. 1 root root  921 Jul 24 17:00 anaconda-ks.cfg
\













drwxr-xr-x. 2 root root 4096 Jul 25 20:51 bak







drwxr-xr-x. 2 root root 4096 Jul 24 11:13 bake
-rw-r--r--. 1 root root   43 Jul 24 10:39 ceu
drwxr-xr-x. 2 root root 4096 Jul 25 20:55 cp-test1
-rw-r--r--. 1 root root    0 Jul 25 20:56 cp-test2
drwxr-xr-x. 2 root root 4096 Jul 25 19:32 demo
-rw-r--r--. 1 root root   51 Jul 24 10:39 err
-rw-r--r--. 1 root root   32 Jul 24 17:58 erro1
-rw-r--r--. 1 root root   51 Jul 24 17:59 errof1
-rw-r--r--. 1 root root  101 Jul 24 10:38 error
-rw-r--r--. 1 root root 1318 Jul 26 21:26 file
-rw-r--r--. 1 root root    6 Jul 25 19:37 file1
-rw-r--r--. 1 root root    0 Jul 26 21:34 file10
-rw-r--r--. 1 root root    0 Jul 25 19:30 file100
-rw-r--r--. 1 root root 9615 Jul 24 17:00 install.log
-rw-r--r--. 1 root root 3357 Jul 24 16:59 install.log.syslog
drwxr-xr-x. 2 root root 4096 Jul 26 21:07 red
drwxr-xr-x. 3 root root 4096 Jul 26 21:11 test
drwxr-xr-x. 2 root root 4096 Jul 25 21:54 test1
-rw-r--r--. 1 root root 2975 Jul 26 20:20 test10
-rw-r--r--. 1 root root   71 Jul 25 19:28 yum.repo
[root@demo6 ~]# cat -s file10
total 84
-rw-r--r--. 1 root root    0 Jul 26 20:21 10
-rw-------. 1 root root  921 Jul 24 17:00 anaconda-ks.cfg
\

drwxr-xr-x. 2 root root 4096 Jul 25 20:51 bak

drwxr-xr-x. 2 root root 4096 Jul 24 11:13 bake
-rw-r--r--. 1 root root   43 Jul 24 10:39 ceu
drwxr-xr-x. 2 root root 4096 Jul 25 20:55 cp-test1
-rw-r--r--. 1 root root    0 Jul 25 20:56 cp-test2
drwxr-xr-x. 2 root root 4096 Jul 25 19:32 demo
-rw-r--r--. 1 root root   51 Jul 24 10:39 err
-rw-r--r--. 1 root root   32 Jul 24 17:58 erro1
-rw-r--r--. 1 root root   51 Jul 24 17:59 errof1
-rw-r--r--. 1 root root  101 Jul 24 10:38 error
-rw-r--r--. 1 root root 1318 Jul 26 21:26 file
-rw-r--r--. 1 root root    6 Jul 25 19:37 file1
-rw-r--r--. 1 root root    0 Jul 26 21:34 file10
-rw-r--r--. 1 root root    0 Jul 25 19:30 file100
-rw-r--r--. 1 root root 9615 Jul 24 17:00 install.log
-rw-r--r--. 1 root root 3357 Jul 24 16:59 install.log.syslog
drwxr-xr-x. 2 root root 4096 Jul 26 21:07 red
drwxr-xr-x. 3 root root 4096 Jul 26 21:11 test
drwxr-xr-x. 2 root root 4096 Jul 25 21:54 test1
-rw-r--r--. 1 root root 2975 Jul 26 20:20 test10
-rw-r--r--. 1 root root   71 Jul 25 19:28 yum.repo


24、 在每一行最后加$:cat -E 文件名


    [root@demo6 ~]# cat -E file10
total 84$
-rw-r--r--. 1 root root    0 Jul 26 20:21 10$
-rw-------. 1 root root  921 Jul 24 17:00 anaconda-ks.cfg      $
\$
$
$
$
$
$
$
$
$
$
$
$
$
$
drwxr-xr-x. 2 root root 4096 Jul 25 20:51 bak$
$
$
$
$
$
$
$
drwxr-xr-x. 2 root root 4096 Jul 24 11:13 bake         $
-rw-r--r--. 1 root root   43 Jul 24 10:39 ceu$
drwxr-xr-x. 2 root root 4096 Jul 25 20:55 cp-test1$
-rw-r--r--. 1 root root    0 Jul 25 20:56 cp-test2$
drwxr-xr-x. 2 root root 4096 Jul 25 19:32 demo$
-rw-r--r--. 1 root root   51 Jul 24 10:39 err$
-rw-r--r--. 1 root root   32 Jul 24 17:58 erro1$
-rw-r--r--. 1 root root   51 Jul 24 17:59 errof1$
-rw-r--r--. 1 root root  101 Jul 24 10:38 error$
-rw-r--r--. 1 root root 1318 Jul 26 21:26 file$
-rw-r--r--. 1 root root    6 Jul 25 19:37 file1$
-rw-r--r--. 1 root root    0 Jul 26 21:34 file10$
-rw-r--r--. 1 root root    0 Jul 25 19:30 file100$
-rw-r--r--. 1 root root 9615 Jul 24 17:00 install.log$
-rw-r--r--. 1 root root 3357 Jul 24 16:59 install.log.syslog$
drwxr-xr-x. 2 root root 4096 Jul 26 21:07 red$
drwxr-xr-x. 3 root root 4096 Jul 26 21:11 test$
drwxr-xr-x. 2 root root 4096 Jul 25 21:54 test1$
-rw-r--r--. 1 root root 2975 Jul 26 20:20 test10$
-rw-r--r--. 1 root root   71 Jul 25 19:28 yum.repo$


25、打印文件标出行号:cat -n 文件名


    [root@demo6 ~]# cat -n file10
     1  total 84
     2  -rw-r--r--. 1 root root    0 Jul 26 20:21 10
     3  -rw-------. 1 root root  921 Jul 24 17:00 anaconda-ks.cfg
     4  \
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18  drwxr-xr-x. 2 root root 4096 Jul 25 20:51 bak
    19
    20
    21
    22
    23
    24
    25
    26  drwxr-xr-x. 2 root root 4096 Jul 24 11:13 bake
    27  -rw-r--r--. 1 root root   43 Jul 24 10:39 ceu
    28  drwxr-xr-x. 2 root root 4096 Jul 25 20:55 cp-test1
    29  -rw-r--r--. 1 root root    0 Jul 25 20:56 cp-test2
    30  drwxr-xr-x. 2 root root 4096 Jul 25 19:32 demo
    31  -rw-r--r--. 1 root root   51 Jul 24 10:39 err
    32  -rw-r--r--. 1 root root   32 Jul 24 17:58 erro1
    33  -rw-r--r--. 1 root root   51 Jul 24 17:59 errof1
    34  -rw-r--r--. 1 root root  101 Jul 24 10:38 error
    35  -rw-r--r--. 1 root root 1318 Jul 26 21:26 file
    36  -rw-r--r--. 1 root root    6 Jul 25 19:37 file1
    37  -rw-r--r--. 1 root root    0 Jul 26 21:34 file10
    38  -rw-r--r--. 1 root root    0 Jul 25 19:30 file100
    39  -rw-r--r--. 1 root root 9615 Jul 24 17:00 install.log
    40  -rw-r--r--. 1 root root 3357 Jul 24 16:59 install.log.syslog
    41  drwxr-xr-x. 2 root root 4096 Jul 26 21:07 red
    42  drwxr-xr-x. 3 root root 4096 Jul 26 21:11 test
    43  drwxr-xr-x. 2 root root 4096 Jul 25 21:54 test1
    44  -rw-r--r--. 1 root root 2975 Jul 26 20:20 test10
    45  -rw-r--r--. 1 root root   71 Jul 25 19:28 yum.repo


26、以某单词开头的行:grep ^单词 文件名

[root@demo6 ~]# cat book
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:b4:50:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.234.23/24 brd 192.168.234.255 scope global eth0
    inet6 fe80::20c:29ff:feb4:50b3/64 scope link
       valid_lft forever preferred_lft forever
root:abghunnn  bbdijbh
bhhunn,kskehdbbhska
root:hhbdjcdjdkkekphf
abdcchnk,m
ROOT:ttinfbvklnddn
jihcd nru nnklcdnk
huindkckniorl
hjfioemk
root:dnckjndk2151

[root@demo6 ~]# grep ^root book
root:abghunnn  bbdijbh
root:hhbdjcdjdkkekphf
root:dnckjndk2151

27、 统计root不区分大小写:grep -i 关键字 文件名

[root@demo6 ~]# grep -i root book
root:abghunnn  bbdijbh
root:hhbdjcdjdkkekphf
ROOT:ttinfbvklnddn
root:dnckjndk2151


28、统计打印的行数:grep -c 关键字 文件名


    [root@demo6 ~]# grep -c root book
3


29、打印文件的行号:grep -n 关键字 文件名


[root@demo6 ~]# grep -n root book
11:root:abghunnn  bbdijbh
13:root:hhbdjcdjdkkekphf
19:root:dnckjndk2151


30、取反:grep -v

[root@demo6 ~]# ip a |grep inet |grep -v inet
[root@demo6 ~]# ip a |grep inet |grep -v inet6
    inet 127.0.0.1/8 scope host lo
    inet 192.168.234.23/24 brd 192.168.234.255 scope global eth0
[root@demo6 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:b4:50:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.234.23/24 brd 192.168.234.255 scope global eth0
    inet6 fe80::20c:29ff:feb4:50b3/64 scope link
       valid_lft forever preferred_lft forever


31、删除文件:rm 文件名


[root@demo6 ~]# ls
10               book      demo    error   file100             test
anaconda-ks.cfg  ceu       err     file    install.log         test1
bak              cp-test1  erro1   file1   install.log.syslog  test10
bake             cp-test2  errof1  file10  red                 yum.repo
[root@demo6 ~]# rm error
rm: remove regular file `error'? y
[root@demo6 ~]# ls
10               bake  cp-test1  err     file    file100             red    test10
anaconda-ks.cfg  book  cp-test2  erro1   file1   install.log         test   yum.repo
bak              ceu   demo      errof1  file10  install.log.syslog  test1
[root@demo6 ~]#


32、强制删除: rm -rf 目录名


[root@demo6 ~]# ls
10               bake  cp-test1  err     file    file100             test    yum.repo
anaconda-ks.cfg  book  cp-test2  erro1   file1   install.log         test1
bak              ceu   demo      errof1  file10  install.log.syslog  test10
[root@demo6 ~]# rm -rf test
[root@demo6 ~]# ls
10               bake  cp-test1  err     file    file100             test1
anaconda-ks.cfg  book  cp-test2  erro1   file1   install.log         test10
bak              ceu   demo      errof1  file10  install.log.syslog  yum.repo


32、删除一个目录:rm -r 目录名(递归删除)


[root@demo6 ~]# tree
.
├── 10
├── anaconda-ks.cfg
├── bak
│   └── err
├── bake
├── book
├── ceu
├── cp-test1
├── cp-test2
├── demo
│   └── file1
├── err
├── erro1
├── errof1
├── file
├── file1
├── file10
├── file100
├── install.log
├── install.log.syslog
├── test1
│   ├── file1
│   ├── file2
│   ├── file3 -> file1
│   ├── file5 -> file1
│   ├── test4
│   ├── test6
│   └── test8 -> test6
├── test10
└── yum.repo

5 directories, 25 files
[root@demo6 ~]# rm -r test
rm: cannot remove `test': No such file or directory
[root@demo6 ~]# rm -r test1
rm: descend into directory `test1'? y
rm: remove symbolic link `test1/file5'? y
rm: remove symbolic link `test1/file3'? y
rm: remove regular file `test1/test6'? y
rm: remove regular file `test1/test4'? y
rm: remove regular file `test1/file2'? y
rm: remove regular file `test1/file1'? y
rm: remove symbolic link `test1/test8'? y
rm: remove directory `test1'? y
[root@demo6 ~]# tree
.
├── 10
├── anaconda-ks.cfg
├── bak
│   └── err
├── bake
├── book
├── ceu
├── cp-test1
├── cp-test2
├── demo
│   └── file1
├── err
├── erro1
├── errof1
├── file
├── file1
├── file10
├── file100
├── install.log
├── install.log.syslog
├── test10
└── yum.repo

4 directories, 18 files


33、删除空目录:rm -d 目录名


[root@demo6 ~]# ls
10               book      demo     erro1   file10              test10
anaconda-ks.cfg  ceu       ending   errof1  file100             yum.repo
bak              cp-test1  ending1  file    install.log
bake             cp-test2  err      file1   install.log.syslog
[root@demo6 ~]# rm -d ending1
rm: remove regular empty file `ending1'? y
[root@demo6 ~]# ls
10               bake  cp-test1  ending  errof1  file10       install.log.syslog
anaconda-ks.cfg  book  cp-test2  err     file    file100      test10
bak              ceu   demo      erro1   file1   install.log  yum.repo


34、 移动文件位置:mv 文件名
移动时,不定新名字,名字不变;名字需改变时(指定),重命名。


[root@demo6 ~]# mv ending1 ending
[root@demo6 ~]# tree
.
├── 10
├── anaconda-ks.cfg
├── bak
│   └── err
├── bake
├── book
├── ceu
├── cp-test1
├── cp-test2
├── demo
│   └── file1
├── ending
│   └── ending1
├── err
├── erro1
├── errof1
├── file
├── file1
├── file10
├── file100
├── install.log
├── install.log.syslog
├── test10
└── yum.repo

5 directories, 19 files


35、复制文件到某处:cp 文件名 需要复制到的地方


[root@demo6 ~]# cp file1 ending
[root@demo6 ~]# tree
.
├── 10
├── anaconda-ks.cfg
├── bak
│   └── err
├── bake
├── book
├── ceu
├── cp-test1
├── cp-test2
├── demo
│   └── file1
├── ending
│   ├── ending1
│   └── file1
├── err
├── erro1
├── errof1
├── file
├── file1
├── file10
├── file100
├── install.log
├── install.log.syslog
├── test10
└── yum.repo

5 directories, 20 files


36、带权限复制: cp -p


[root@demo6 ~]# cp -p file1 bak
[root@demo6 ~]# tree
.
├── 10
├── anaconda-ks.cfg
├── bak
│   ├── err
│   └── file1
├── bake
├── book
├── ceu
├── cp-test1
├── cp-test2
├── demo
│   └── file1
├── ending
│   ├── ending1
│   └── file1
├── err
├── erro1
├── errof1
├── file
├── file1
├── file10
├── file100
├── install.log
├── install.log.syslog
├── test10
└── yum.repo

5 directories, 21 files


37、复制所有:cp -a


[root@demo6 ~]# cp -a ending demo
[root@demo6 ~]# tree
.
├── 10
├── anaconda-ks.cfg
├── bak
│   ├── err
│   └── file1
├── bake
├── book
├── ceu
├── cp-test1
├── cp-test2
├── demo
│   ├── ending
│   │   ├── ending1
│   │   └── file1
│   └── file1
├── ending
│   ├── ending1
│   └── file1
├── err
├── erro1
├── errof1
├── file
├── file1
├── file10
├── file100
├── install.log
├── install.log.syslog
├── test10
└── yum.repo

6 directories, 23 files


38、查看文件类型:file 文件名


[root@demo6 ~]# file err
err: ASCII text


39、给file1做了硬链接 : ln file1 file2

创建软链接:ln -s file1 file2

(软链接:在原文件删除的情况下,失效)

(硬链接:在原文件删除后,内容依旧存在)

[root@demo6 ~]# cd linux
[root@demo6 linux]# touch file
[root@demo6 linux]# ln file file1
[root@demo6 linux]# ln -s file file2
[root@demo6 linux]# ll
total 0
-rw-r--r--. 2 root root 0 Jul 26 22:31 file
-rw-r--r--. 2 root root 0 Jul 26 22:31 file1
lrwxrwxrwx. 1 root root 4 Jul 26 22:32 file2 -> file
[root@demo6 linux]#

file2 是file1的硬链接
file3是file1的软链接
当file1被删除时,file2依旧存在,而file3此时就不存在
当重新创建file1时,file3重新连接file1,但此时file1不是原本的file1 发生错误。
在这里插入图片描述
在这里插入图片描述

40、 exec:对匹配的文件执行该参数所给出地shell命令。形式为command{} ;,注意{} 与;之间有空格。
find 查找路径,(默认当前)参数(-name filename,-user username,-type f/s/)
找到文件并删除:find -name test -exec rm -rf{};
模糊查找test相关文件并删除:find -name “test” -exec rm -rf{};

41、文件系统:类Unix系统上,是一个倒挂树形式。

bin、sbin、系统命令二进制文件Linux系统文件目录。
boot存放系统启动有关的文件
dev设备文件
etc配置文件
home用户的家目录
lib库、模块文件
opt与第三方的安装模块
use用户
var与应用相关的文件。

42、more:分屏显示
more -10 文件名:一屏十行。
Ctrl+f:向下分屏滚动
Ctrl+b: 向上分屏滚动


    [root@demo6 ~]# more -10 file10
total 84
-rw-r--r--. 1 root root    0 Jul 26 20:21 10
-rw-------. 1 root root  921 Jul 24 17:00 anaconda-ks.cfg
\






--More--(10%)




43、cut:文件操作
cut - b:按照字节个数来查找
cut -b 10- 20
cut -b 10-
cut -b -20


[root@demo6 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:b4:50:b3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.234.23/24 brd 192.168.234.255 scope global eth0
    inet6 fe80::20c:29ff:feb4:50b3/64 scope link
       valid_lft forever preferred_lft forever
[root@demo6 ~]# cut -b 10-20 linux1
OOPBACK,UP,
loopback 00
127.0.0.1/8
 ::1/128 sc
lid_lft for
<BROADCAST,
ether 00:0c
192.168.234
 fe80::20c:
lid_lft for
[root@demo6 ~]#



44、sort:排序(默认正序排列)
sort -r :倒序排列


    [root@demo6 ~]# cat file100
 10
520
10
20
5
0
5
03
5
06

[root@demo6 ~]# sort file100

0
03
06
10
 10
20
5
5
5
520
[root@demo6 ~]# sort -r file100
520
5
5
5
20
 10
10
06
03
0



45、去重:uniq
先排序,再去重。
cat 文件名 | sort | uniq


    [root@demo6 ~]# cat long
1
5
9
6
5
4
2
2
9
8
8
[root@demo6 ~]# cat long |sort |uniq
1
2
4
5
6
8
9


46、统计行数:cat - n | wc -l:


    [root@demo6 ~]# cat long
1
5
9
6
5
4
2
2
9
8
8
[root@demo6 ~]# cat -n |wc -l long
11 long


47、查询命令路径:
which : 查看文件所在路径。可以判断命令程序是否安装。
whereis:

[root@demo6 ~]# which file
/usr/bin/file
[root@demo6 ~]# whereis file
file: /usr/bin/file /usr/share/file /usr/share/man/man1/file.1.gz

48、 查询文件所在位置:
find;
locate;


[root@demo6 ~]# find bak
bak
bak/file1
bak/err
[root@demo6 ~]# locate bak
/etc/yum.repos.d/bak
/etc/yum.repos.d/bak/CentOS-Base.repo
/etc/yum.repos.d/bak/CentOS-Debuginfo.repo
/etc/yum.repos.d/bak/CentOS-Media.repo
/etc/yum.repos.d/bak/CentOS-Vault.repo
/etc/yum.repos.d/bak/CentOS-fasttrack.repo
/root/bak
/root/bake
/root/bak/err


49、’ ':强引用,可见即可得。
" ":弱引用,把变量或者是转义符正常输出结果。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值