日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux基础命令(一)

發布時間:2023/12/31 linux 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux基础命令(一) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

linux基礎命令(一)

文章目錄

    • linux基礎命令(一)
      • 一.拍攝快照
      • 二.基礎命令和bash的特性,常用操作
        • 1.bash特性---一種是命令行終端,即CLI。
          • 1.1 bash
          • 1.2 命令歷史---history
          • 1.3 支持管道、重定向
          • 1.4 命令別名 alias
          • 1.5 光標跳轉
          • 1.6 支持變量
          • 1.6 看時間---date mkdir 創建目錄
          • 1.7 命令替換---英文中的反引號和$()
          • 1.8 支持文件名通配
          • 1.9命令行展開
        • 2. 基礎命令
          • 1.1 mkdir 創建目錄
          • 1.2date 時間
          • 1.3history 歷史命令
          • 1.4alias 命令別名
          • 1.5touch 創建文件
          • 1.6 ls 列出當前位置有什么文件

一.拍攝快照

  • 關機拍攝
  • [外鏈圖片轉存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-PidE2rME-1657154899607)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20220323161417582.png)]

二.基礎命令和bash的特性,常用操作

1.bash特性—一種是命令行終端,即CLI。

  • 支持命令歷史,命令補全

  • 支持管道、重定向

  • 支持命令別名

  • 支持命令行編輯

  • 支持命令行展開

  • 支持文件名通配

  • 支持變量

  • 支持編程

1.1 bash
  • cat–查看

  • [root@localhost ~]# echo $SHELL //當前正在用的shell /bin/bash [root@localhost ~]# cat /etc/shells //查看主機能使用的shell /bin/sh /bin/bash /usr/bin/sh /usr/bin/bash [root@localhost ~]#
1.2 命令歷史—history
  • -c 清空歷史命令

  • 47 ls /etc/sysconfig/network-scripts/48 cd /etc/sysconfig/network-scripts/49 cd50 history [root@localhost ~]# history -c [root@localhost ~]# history 1 history [root@localhost ~]#
  • -d+數字 刪除指定位置的命令歷史

  • [root@localhost ~]# history 1 ls2 hostname syl-panny3 next4 end5 hostname syl6 history 7 ls8 history [root@localhost ~]# history -d 7 [root@localhost ~]# history 1 ls2 hostname syl-panny3 next4 end5 hostname syl6 history 7 history 8 history -d 79 history [root@localhost ~]#
  • [root@localhost ~]# history 1 ls2 hostname syl-panny3 next4 end5 hostname syl6 history [root@localhost ~]#
  • 命令歷史的使用技巧

    • !n 執行命令歷史中的第n條命令

      • [root@localhost ~]# !20 ls 1.1.txt 1999 anaconda-ks.cfg q
    • !-n 執行命令歷史中倒數第n條命令

      • [root@localhost ~]# !-4 echo "$a" 50
    • !! 執行上一條命令

      • [root@localhost ~]# !! echo "$a" 50 [root@localhost ~]#
    • !string 執行命令歷史中最近一個以指定字符串開頭的命令

      • [root@localhost ~]# !cat cat /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=static NAME=ens33 DEVICE=ens33 ONBOOT=yes IPADDR=192.168.232.129 NETMASK=255.255.255.0 GATEWAY=192.168.232.2 DNS1=192.168.232.2 [root@localhost ~]#
    • !$ 引用前一個命令的最后一個參數

      • [root@localhost ~]# ls /etc/sysconfig/network-scripts/ ifcfg-ens33 [root@localhost ~]# cd !$ cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]#
    • esc,. 按下esc松開后按.,引用前一個命令的最后一個參數 按ESC + 點

  • 命令補全,輸入所選命令的首字符按Tab鍵

  • [root@localhost ~]# h halt hdparm hexdump hostname hardlink head history hostnamectl hash help hostid hwclock [root@localhost ~]# h
  • 路徑補全

  • [root@localhost ~]# ls /etc/sys sysconfig/ systemd/ sysctl.conf system-release sysctl.d/ system-release-cpe [root@localhost ~]# ls /etc/sys
1.3 支持管道、重定向
  • 管道

  • rpm -qa 查詢怎樣系統安裝的包 grep 過濾

  • [root@localhost ~]# rpm -qa|grep 'wget' [root@localhost ~]# rpm -qa|grep 'tools' python3-setuptools-wheel-39.2.0-6.el8.noarch kernel-tools-4.18.0-365.el8.x86_64 open-vm-tools-11.3.5-1.el8.x86_64 squashfs-tools-4.3-20.el8.x86_64 net-tools-2.0-0.52.20160912git.el8.x86_64 kernel-tools-libs-4.18.0-365.el8.x86_64 grub2-tools-2.02-106.el8.x86_64 grub2-tools-extra-2.02-106.el8.x86_64 kexec-tools-2.0.20-68.el8.x86_64 platform-python-setuptools-39.2.0-6.el8.noarch grub2-tools-minimal-2.02-106.el8.x86_64 dbus-tools-1.12.8-18.el8.x86_64 [root@localhost ~]#
  • 重定向

  • 清空文件

  • [root@localhost ~]# cat abc curl-7.61.1-22.el8.x86_64 libcurl-7.61.1-22.el8.x86_64 curl-7.61.1-22.el8.x86_64 libcurl-7.61.1-22.el8.x86_64 curl-7.61.1-22.el8.x86_64 libcurl-7.61.1-22.el8.x86_64 curl-7.61.1-22.el8.x86_64 libcurl-7.61.1-22.el8.x86_64 [root@localhost ~]# > abc [root@localhost ~]# cat abc [root@localhost ~]#
  • 一個大于號 覆蓋重定向 ,原文件會被覆蓋

  • [root@localhost ~]# rpm -qa|grep 'curl' > abc [root@localhost ~]# cat abc curl-7.61.1-22.el8.x86_64 libcurl-7.61.1-22.el8.x86_64 [root@localhost ~]#
  • 兩個大于號 追加重定向,原文件會保持,繼續追加

  • [root@localhost ~]# rpm -qa|grep 'curl' >> abc [root@localhost ~]# [root@localhost ~]# rpm -qa|grep 'curl' >> abc [root@localhost ~]# rpm -qa|grep 'curl' >> abc [root@localhost ~]# cat abc curl-7.61.1-22.el8.x86_64 libcurl-7.61.1-22.el8.x86_64 curl-7.61.1-22.el8.x86_64 libcurl-7.61.1-22.el8.x86_64 curl-7.61.1-22.el8.x86_64 libcurl-7.61.1-22.el8.x86_64 curl-7.61.1-22.el8.x86_64 libcurl-7.61.1-22.el8.x86_64 [root@localhost ~]#
1.4 命令別名 alias
  • [root@localhost ~]# alias cdnet='cd /etc/sysconfig/network-scripts/' [root@localhost ~]# [root@localhost ~]# cdnet [root@localhost network-scripts]# cd [root@localhost ~]#
1.5 光標跳轉
  • ctrl +a 到最開始
  • ctrl +e 到最后
  • ctrl + 左右鍵
  • trl +w 刪除所選前一個命令
  • ctrl +u 刪除所選前面
  • ctrl +k 刪除所選后面
1.6 支持變量
  • echo 打印

  • [root@localhost ~]# a=100 [root@localhost ~]# echo $a 100 [root@localhost ~]#
  • 英文中的雙引號—弱引用 echo “$a”

  • 英文中的單引號—強引用 echo ‘$a’

  • [root@localhost ~]# echo "$a" 100 [root@localhost ~]# echo '$a' $a [root@localhost ~]#
  • PATH—當前系統所有命令所在的位置

  • [root@localhost ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin [root@localhost ~]# lls -bash: lls: command not found [root@localhost ~]#
  • [root@localhost ~]# ls 1.1.txt 20220323 abc bin 1999 20220323143400 anaconda-ks.cfg q [root@localhost ~]# cp /usr/bin/ls /root/bin/lls //把/usr/bin/ls cp /root/bin/ lls(重新命名) [root@localhost ~]# ls bin/ lls [root@localhost ~]# lls 1.1.txt 20220323 abc bin 1999 20220323143400 anaconda-ks.cfg q
1.6 看時間—date mkdir 創建目錄
  • 年 year Y
    月 month m
    日 day d
    時 hour H
    分 minute M
    秒 seconds S

  • [root@localhost ~]# date '+%Y%m%d' 20220323 [root@localhost ~]# date '+%Y%m%d%H%M%S' 20220323143256 [root@localhost ~]# date Wed Mar 23 14:33:16 CST 2022 [root@localhost ~]#
1.7 命令替換—英文中的反引號和$()
  • 反引號

  • [root@localhost ~]# mkdir `date '+%Y%m%d%H%M%S'` [root@localhost ~]# ls 1.1.txt 1999 20220323143400 abc anaconda-ks.cfg q
  • $()

  • [root@localhost ~]# date '+%Y%m%d' 20220323 [root@localhost ~]# mkdir $(date '+%Y%m%d') [root@localhost ~]# ls 1.1.txt 20220323 abc q 1999 20220323143400 anaconda-ks.cfg [root@localhost ~]#
1.8 支持文件名通配
  • *匹配任意長度的任意字符

  • *9看的是以9結尾

  • 9*看的是以9開頭

  • [root@localhost ~]# ls 1* 1.1.txt 102 105 108 111 114 117 120 100 103 106 109 112 115 118 1999 101 104 107 110 113 116 119 [root@localhost ~]# ls 3* ls: cannot access '3*': No such file or directory [root@localhost ~]# ls 9* 90 91 92 93 94 95 96 97 98 99 [root@localhost ~]# ls a* abc anaconda-ks.cfga: b c d [root@localhost ~]# ls *9 109 119 1999 69 79 89 99 [root@localhost ~]#
  • ?匹配任意單個字符

  • [root@localhost ~]# ls ? c e g i k m o r t v x z d f h j l n p s u w ya: b c dq: [root@localhost ~]# ls ?? 66 69 72 75 78 81 84 87 90 93 96 99 67 70 73 76 79 82 85 88 91 94 97 68 71 74 77 80 83 86 89 92 95 98 [root@localhost ~]# ls ??? 100 102 104 106 108 110 112 114 116 118 120 abc 101 103 105 107 109 111 113 115 117 119 ___bin: lls [root@localhost ~]#
  • []匹配指定范圍內的任意單個字符

  • [root@localhost ~]# ls [c-g] c d e f g [root@localhost ~]# ls [c,g] , c g [root@localhost ~]#
  • [[:space:]] 表示空白字符

  • [[:punct:]] 表示標點符號

    • [root@localhost ~]# ls [[:punct:]] , [root@localhost ~]#
  • [[:lower:]] 表示小寫字母

  • [[:upper:]] 表示大寫字母

  • [[:alpha:]] 表示大小寫字母

  • [[:digit:]] 表示數字

  • [[:alnum:]] 表示數字和大小寫字母

1.9命令行展開
  • ~展開為用戶的家目錄
  • ~USERNAME 展開為指定用戶的家目錄

2. 基礎命令

1.1 mkdir 創建目錄
  • [root@localhost ~]# mkdir -p a/{b/{235,147},c/123,d/{aaa/199,bbb}} [root@localhost ~]# ls 1.1.txt 20220323 a anaconda-ks.cfg q 1999 20220323143400 abc bin [root@localhost ~]# [root@localhost ~]# tree a a |-- b | |-- 147 | `-- 235 |-- c | `-- 123 `-- d|-- aaa| `-- 199`-- bbb9 directories, 0 files [root@localhost ~]#
1.2date 時間
[root@localhost ~]# date Wed Mar 23 16:02:20 CST 2022 [root@localhost ~]#
1.3history 歷史命令
[root@localhost ~]# history 1 history 2 ls3 cat abc4 > abc5 cat
1.4alias 命令別名
[root@localhost ~]# cdnet -bash: cdnet: command not found [root@localhost ~]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# cd [root@localhost ~]# alias cdnet='cd /etc/sysconfig/network-scripts/' [root@localhost ~]# cdnet [root@localhost network-scripts]# cd
1.5touch 創建文件
  • [root@localhost ~]# touch 2022 [root@localhost ~]# ls 1.1.txt 2022 20220323143400 abc bin 1999 20220323 a anaconda-ks.cfg q [root@localhost ~]#
  • [root@localhost ~]# touch {c..z} [root@localhost ~]# touch {66..120}
1.6 ls 列出當前位置有什么文件
  • [root@localhost ~]# ls 1.1.txt 20220323 a anaconda-ks.cfg q 1999 20220323143400 abc bin [root@localhost ~]#
  • ls -l

  • [root@localhost ~]# ls -l total 8 -rw-r--r--. 1 root root 88 Mar 1 19:16 1.1.txt -rw-r--r--. 1 root root 0 Mar 23 13:31 1999 drwxr-xr-x. 2 root root 6 Mar 23 14:37 20220323 drwxr-xr-x. 2 root root 6 Mar 23 14:34 20220323143400 drwxr-xr-x. 5 root root 33 Mar 23 15:23 a -rw-r--r--. 1 root root 0 Mar 23 15:02 abc -rw-------. 1 root root 1092 Mar 1 17:08 anaconda-ks.cfg drwxr-xr-x. 2 root root 17 Mar 23 14:48 bin drwxr-xr-x. 2 root root 6 Mar 23 13:30 q [root@localhost ~]#

alhost ~]#

- ls -l- ``` [root@localhost ~]# ls -l total 8 -rw-r--r--. 1 root root 88 Mar 1 19:16 1.1.txt -rw-r--r--. 1 root root 0 Mar 23 13:31 1999 drwxr-xr-x. 2 root root 6 Mar 23 14:37 20220323 drwxr-xr-x. 2 root root 6 Mar 23 14:34 20220323143400 drwxr-xr-x. 5 root root 33 Mar 23 15:23 a -rw-r--r--. 1 root root 0 Mar 23 15:02 abc -rw-------. 1 root root 1092 Mar 1 17:08 anaconda-ks.cfg drwxr-xr-x. 2 root root 17 Mar 23 14:48 bin drwxr-xr-x. 2 root root 6 Mar 23 13:30 q [root@localhost ~]#

總結

以上是生活随笔為你收集整理的linux基础命令(一)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。