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

歡迎訪問 生活随笔!

生活随笔

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

linux

1.Linux常见命令

發(fā)布時間:2023/12/8 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 1.Linux常见命令 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

基本概念

  • 目錄:文件夾
  • 根目錄:所有文件最上級目錄"/"
  • 子目錄:位于其他目錄下層的目錄【/home/tarena】
  • 父目錄:子目錄的上層目錄".."
  • 當前目錄:"."標記
  • 主目錄:"~"標記,位于/home下,目錄名和用戶名相同
  • 路徑:
  • 絕對路徑
  • 相對路徑
  • Linux常見命令

    格式:命令 【-選項】 【參數(shù)】(中間帶空格)

    • 清屏:clear
    • 打印當前目錄:pwd
    • 改變當前目錄:cd 【制定的目標目錄】
    cd /home/tarena 切換到/home/tarena目錄下 cd .. 進入上級目錄 cd ./tarena 進入當前目錄下的tarena目錄里面 cd ~ 進入主目錄 cd / 進入根目錄
    • 顯示目錄內(nèi)容:ls
      • ls -a,顯示全部內(nèi)容,包括隱藏文件
      • ls -l,顯示詳細信息,包括文件屬性
    ls /home/tarenacd 查看/home/tarena目錄下的內(nèi)容 ls -l /home/tarena 查看/home/tarena目錄里面內(nèi)容的詳細信息 ls /usr/include/stdio.h 查看此文件是否存在 ls -l /usr/include/stdio.h查看此文件的詳細信息 ls 查看當前目錄下的內(nèi)容 ls -l 查看當前目錄下內(nèi)容的詳細信息 ls ..查看上一級目錄里面內(nèi)容的詳細信息 ls -l .. 查看上一級目錄里面內(nèi)容的詳細信息 ls stdio.h 查看當前目錄下是否存在stdio.h文件 ls -l stdio.h 查看當前目錄下stdio.h文件的詳細信息 ls ~查看主目錄里面的內(nèi)容 ls -l ~查看主目錄里面內(nèi)容的詳細信息 ls / 查看根目錄里面的內(nèi)容 ls -l / 查看根目錄里面內(nèi)容的詳細信息
    • 創(chuàng)建空文件:touch 【文件】
    touch /home/tarena/hello.txt在/home/tarna目錄下創(chuàng)建空文件hello.txt touch hello.txt 在當前目錄下創(chuàng)建空文件hello.txt touch ~/hollo2.txt在主目錄下創(chuàng)建空文件hello2.txt
    • 創(chuàng)建空目錄:mkdir
      • 如果需要一次創(chuàng)建多級目錄,需要使用-p選項:mkdir -p 目錄1/目錄2/目錄3
    mkdir /home/tarena/hello 在/home/tarena目錄下創(chuàng)建空目錄hello mkdir hello1 在當前目錄下創(chuàng)建空目錄hello1 mkdir ~/hello2在主目錄下創(chuàng)建空目錄hello2 mkdir -p hello3/hello4/hello5
    • 修改權(quán)限chmod
      • 符號模式
        • chmod u/g/o/a +/-/= r/w/x 文件
        • u/g/o/a:屬主/屬組/其他/所有
        • +/-/= :增加/減去/設(shè)置
        • r/w/x:讀取/寫入/執(zhí)行
    chmod a+x hello.txt chmod u-r hello.txt chmod a=rwx hello.txt
      • 數(shù)字模式
        • chmod 644 myfile
          • 將權(quán)限用三位數(shù)字表示,有左到右依次表示對應(yīng)屬主,同組和其他,
          • 每一位都是從4(讀)/2(寫)/1(執(zhí)行)三個數(shù)中選出若干個取和
    chmod 777 hello.txt chmod 644 hello.txt chmod544 hello.txt
    • 拷貝:cp
      • 拷貝文件:cp 【源文件】 【目標文件】
      • 原名拷貝文件:cp 【源文件】【存在目錄】
      • 拷貝目錄:cp -fr 【源目錄】 【存在目錄】
      • 原名拷貝目錄:cp -fr 【 源目錄】 【存在目錄】
    mkdir /home/tarena/cptest cd /home/tarena/cptest/ touch hello.txt mkdir hello ls cp hello.txt hello.txt//拷貝hello.txt生成一個新文件hello1.txt cp -fr hello hello1//拷貝hello.txt到一個新的目錄hello1 cp hello.txt hello //拷貝hello.txt文件到hello目錄里去 cp -fr hello hello1 //拷貝hello目錄到hello1目錄里 cp -fr hello1 ~/hello2 //拷貝hello1目錄到主目錄/home/tarena目錄里面去并且命名為hello2目錄
    • 更名和移動:mv
      • 更名文件:mv 【源文件】 【目標文件】
      • 移動文件:mv 【源文件】 【存在目錄】
      • 更名文件:mv 【源目錄】 【目標目錄】
      • 移動目錄:mv 【源目錄】 【存在目錄】
    mkdir /home/tarena/mvtest cd /home/tarena/mvtest touch hello.txt mkdir hello ls mv hello.txt hello.txt ls mv hello.txt hello1 ls ls hello1 mkdir hello2 ls mv hello2 hello1 ls ls hello1
    • 刪除:rm
      • 刪除文件:rm 文件1 文件2 ……文件n
      • 刪除目錄:rm -fr 目錄1 目錄2 ……目錄n
    rm /home/tarenacd/hello.txt cd /home/tarena rm -fr mvtest ls /home/tarena/hello.txt ls /home/tarena/cptest sudo rm -fr //使用管理員權(quán)限強制刪除
    • echo命令
      • echo 信息:將信息輸出到顯示器上
      • echo 信息 > 文件:將信息輸出到文件中保存但是先把文件的內(nèi)容清空后再保存
      • echo 信息 >> 文件:將信息保存到文件的尾部,文件原先內(nèi)容依舊保留
    echo belist touch /home/tarena/hello.txt echo belist > belist1 cat hello.txt echo belist2 > hello.txt cat hello.txt echo belist3 >> hello.txt cat hello.txt echo 1234 >> hello.txt cat hello.txt echo belist4 >hello.txt
    • 創(chuàng)建鏈接:ln命令
      • 硬鏈接:ln 【目標文件】 【鏈接文件】
      • 軟鏈接:ln -s 【目標文件】 【鏈接文件】
    • 顯示文件
      • cat 【文件】:顯示文件內(nèi)容
      • more 【文件】:分屏顯示文件內(nèi)容
      • head -n 【文件】:顯示文件前n行(缺省10行)內(nèi)容
      • tail -n 【文件】:顯示文件后n行(缺省10行)內(nèi)容
      • tail -f 【文件】:隨文件增長,顯示其追加內(nèi)容
    cat /user/include/stdio.h //全部顯示 more /user/include/stdio.h //分屏顯示,回車走一行,空格走一屏,q退出 head -15 /usr/include/stdio.h 只看文件的前15行 tail -15 /user/include/stdio.htouch /home/tarena/hello.txt tail -f /home/tarena/hello.txt //此刻停止不動,實驗完畢可以ctrl+c強制退出 echo 12345 >> /home/tarena/hello.txt//然后去終端觀察有何不同ctrl+shift+c可以在一個終端中創(chuàng)建另一個終端,切換按alt+數(shù)字(終端編號)
    • 查找文件或目錄:find 【目錄 】【文件】
      • 查找特定目錄下,滿足特定條件的文件或目錄。
        • -name 【文件或目錄名】
        • -perm 【權(quán)限】
        • -user 【屬主】
        • -group 【屬組】
        • -ctime/atime/mtime -n/+n
        • -type d/f/l/p/b/c
        • -size nc
    cd /home/tarenafind . -name hello.txt 在當前目錄下找一個hello.txt的文件find /user/include -name stdio.h 到/user/include目錄下找stdio.h文件find . -user tarena -group tarena -name hello.txt find . -perm 664 -user tarena -group tarena -name hello.txt find . -mtime +10 -perm 664 -user tarena -group tarena -name hell.txt find . -mtime +10 -size 100c -perm 664 -user tarena -group tarena -name hello.txt
    • 查找內(nèi)容:grep 【選項】【正則表達式】【文件/目錄】
      • -n:同時顯示匹配行上下的n行
      • -c:只顯示匹配的行數(shù),不顯示匹配行的內(nèi)容
      • -h:當在多個文件中查找時,不顯示文件名前綴
      • -i:忽略大小寫
      • -v:顯示不匹配行
      • -r:在目錄及其子目錄中查找
      • -w:將表達式作為一個單詞查找
    cd /home/tarena touch hello.txt echo 1234 >> hello.txt echo abc1234 >> hello.txt echo you've >> hello.txt echo printf >> hello.txt echo printf1234 >> hello.txt cat hello.txt grep -Rn "1234" hello.txt grep -Rn "printf" hello.txt grep -Rnw "printf" hello.txt grep -Rn "1234" * //在當前目錄下的所有文件中搜索1234 grep -Rn "1234" *.txt //在當前目錄下所有以.txt結(jié)尾的文件中搜索1234 grep -Rn "main" /user/include //到/user/include目錄下搜索main grep -Rn "main" /user/include/*.h //到/user/include目錄下,然后在所有以.h結(jié)尾的文件中搜索main
    • 打包解包:tar
      • 打包:
        • tar -jcvf A.tar.bz2 A
        • tar -zcvf A.tar.gz A
      • 解包
        • tar -xvf A.tar.bz2
        • tar -xvf A.tar.gz
    mkdir -p /home/tarena/tartest/hello cd /home/tarena/tartest/hello touch hello.txt echo 1234>> hello.txt cd .. ls tar -jcvf hello.tar.bz2 hello tar -zcvf hello.tar.gz hello ls rm -fr hello tar -xvf hello.tar.bz2 rm -fr hello tar -xvf hello.tar.gz cat hello/hello.txt

    文件詳細信息

    • - rwx rw- r-- 1 root root 6 jul 25 11:48 myfile
    • - --- --- --- - ---- ---- - ----------- -----
    • A B. C. D. E. F. G. H I. J
      • A:文件類型,d(目錄)/-(普通)/1(軟鏈接)
      • B:屬主權(quán)限,r(讀)/w(寫)/x(執(zhí)行)/-(無)
      • C:同組權(quán)限,r(讀)/w(寫)/x(執(zhí)行)/-(無)
      • D:其他權(quán)限,r(讀)/w(寫)/x(執(zhí)行)/-(無)
      • E:硬鏈接數(shù),文件的別名
      • F:屬主的名稱
      • G:屬組的名稱
      • H:字節(jié)數(shù)
      • I:最后的修改時間
      • J:文件名
      • 針對目錄的寫權(quán)限:在該目錄下增刪字目錄或文件
      • 針對目錄的執(zhí)行權(quán)限:訪問該目錄下的內(nèi)容

    文件通配符

    • *
      • 通配若干任意字符:ls*.txt
    • ?
      • 通配 一個任意字符:ls file_?.txt
    • []
      • 通配一個在特定字符集中的字符:ls file_[a-c].txt
    mdkir /home/tarena/file cd /home/tarena/file touch file_1.txt touch file_2.txt touch file_a.txt touch file_11.txt touch file_b.txt touch file_aa.txt ls *.txt ls file_?.txt ls file_[a-z].txt ls file_[0-9][0-9].txt

    I/O重定向和管道

    • >
      • 輸出重定向:echo hello > a.txt
    • <
      • 輸入重定向:cat < a.txt > b.txt
    • >>
      • 追加:echo world >> b.txt
    • |
      • 管道符:將前一個命令的輸出作為后一個命令的輸入
      • ls -l /etc | more
      • 命令行分隔符,在一個命令行中分隔多個命令
      • cal;pwd;date
    • \
      • 續(xù)行符,繼續(xù)在下一行輸入命令
    cat \ /etc/passwd \ |\ grep \ tarena

    總結(jié)

    以上是生活随笔為你收集整理的1.Linux常见命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。