linux基本命令學習筆記,linux命令學習筆記

來源:互聯網
上載者:User

linux基本命令學習筆記,linux命令學習筆記
0.ls -lh
    人性化顯示目前的目錄下檔案的屬性

1.連結:
    永久連結(本身即檔案指標,和原檔案指標等價)
        ln filename1 filename2
    軟連結(本身是指標,建立了指向原檔案的指標)
        ln -s 絕對路徑 filename2

2.搜尋:
    檔案搜尋
        locate(速度快,但只能按檔案名稱搜尋)
            資料庫中搜尋 /var/lib/mlocate 每天更新一次
            強制更新 updatedb 或 locate locate
            設定檔 /etc/updatedb.conf

        find(強大,慢、難)
            find path -name filename
                (-iname 不區分大小寫
                 -user 按所有者搜尋
                 -nouser 搜尋沒有所有者的檔案,
                        垃圾檔案或核心檔案或外來檔案
                )
            搜尋內容完全符合,否則加萬用字元 * ? []
            eg: find /root -name "ab[cd]"

            find /var/log/ -mtine +10
            尋找10天前修改的檔案
                (-10 10天內修改的檔案
                 10  10天當天修改的檔案
                 +10 10天前修改的檔案

                 -atime 檔案訪問時間
                 -ctime 改變檔案屬性
                 -mtime 修改檔案內容
                 -size  檔案大小 k M
                 -inum  i節點查檔案名稱
                )

            find /etc -size +20k -a -size -50k
                -a 邏輯與
                -o 邏輯或

            find cmd1 -exec cmd2 {} \;
                -exec cmd {} \;固定搭配
                cmd1的處理結果給cmd2處理


    命令搜尋
        whereis 命令名
            只能查系統命令
        which 命令名
            顯示命令別名

    
    字串搜尋
        grep [options] string filename
            -i 忽略大小寫
            -v 排除指定字元集

3.協助
    man -f cmd
    相當於whatis cmd

    apropos cmd
    尋找關於cmd的協助資訊
    
    cmd --help

    shell內部命令協助
        help cmd
        用 whereis cmd 確定cmd是否為內部命令

    info cmd
    巨大詳細的協助

4.壓縮
    zip zipname srcname
        -r 壓縮目錄
    unzip zipname filename
        解壓不用參數,源檔案保留

    gzip 源檔案 (源檔案消失)
        -r 壓縮目錄(目錄下的檔案)
        -d 解壓縮 gunzip

    bzip2 源檔案 (不能壓縮目錄)
        -k 保留源檔案
        -d 解壓 bunzip2

    tar -cvf 打包檔案名稱 源檔案
        (-c 打包
         -x 解包
         -v 過程
         -f 指定打包檔案名稱
        )
    tar -zcvf 壓縮檔名 源檔案
        (-z .gz
         -j .bz2
        )
    tar -zxvf 壓縮包 -C 解壓位置
        -C 指定解壓位置
    tar -ztvf 壓縮包
        -t 查看壓縮包內的檔案,不解壓

5.關機
    shutdown [options] time
        -r 重啟
        -h 關機  halt  poweroff  init 0
        -c 取消上一條shutdown命令
    
    init 6 (??嘗試修複??)

    logout (退出遠端管理終端)

6.掛載
    mount 查看已掛載目錄
    mount -a 自動掛載 /etc/fstab 裡面的內容
    
    mount [-t 檔案系統] [-o 特殊選項] 裝置檔案名稱 掛載點
        -t ext4 iso9660
    
    mount -o remount,noexec /home/
        重掛載/home 不能執行可執行檔
    mount -o remount,exec /home/
        重掛載/home

    掛載光碟片
        mkdir /mnt/cdrom
        mount -t iso9660 /dev/sr0 /mnt/cdrom/
    卸載
        umount 裝置檔案名稱或掛載點

    掛載隨身碟
        fdisk -l
        mount -t vfat /dev/sdb1 /mnt/usb/

    -t選項一般情況下可以省略

7.查看登入使用者資訊
    w
    who
    last 讀取的 /var/log/wtmp
    lastlog  /var/log/lastlog

8.shell
    /etc/shells裡麵包含了Linux能用的shell
    輸入shell名即可進入指定shell

    指令碼執行
        chmod 755 filename.sh
        ./filename.sh

        bash filename.sh
    
    別名
        alias 查看系統已有別名
        alias ls='ls --color=never'
        alias rm='rm -rf'

        unalias 別名

        ~/.bashrc 別名環境變數設定檔
    
    快速鍵
        Ctrl+c 終止
        Ctrl+l 清屏
        Ctrl+u 刪除游標前所有字元
        Ctrl+a 游標跳到行首
        Ctrl+e 游標跳到行末
        Ctrl+z 把命令放到後台
        Ctrl+r 在曆史命令中搜尋

    曆史命令
        history [options] [file]
            -c 清空曆史命令
            -w 儲存曆史命令到檔案 ~/.bash_history
        環境變數設定檔  /etc/profile
        !n 執行第n條曆史命令
        !! 重複執行上一條命令
        !字串 重複執行最後一條以字串開頭的命令

    輸出重新導向
        命令 > 檔案
        命令 >> 檔案
        錯誤命令 2>檔案
        錯誤命令 2>>檔案

        命令 > 檔案 2>&1
        命令 >> 檔案 2>&1
        命令 &> 檔案
        命令 &>> 檔案
        alias fuck='ls &>/dev/null'
        命令 > 檔案1 2>檔案2

    輸入重新導向
        wc

    管道符
        ;  命令1 ; 命令2   分隔字元,無影響
        && 命令1 && 命令2  命令1執行成功才能執行命令2
        || 命令1 || 命令2  命令1執行則2不執行,否則2執行

        date;locate "l";date
        ls && echo yes || echo no 正確yes錯誤no

        命令1 | 命令2  命令1的結果給命令2
        netstat -an | grep ESTABLISHED | wc -l
    
    萬用字元
        ? * [] [-] [^]


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.