歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux基礎知識 >> Linux 常用命令總結二

Linux 常用命令總結二

日期:2017/3/2 17:13:20   编辑:Linux基礎知識

2.文件管理命令

  cat, tac, more, less, head, tail, nl, od, cd,pwd, mkdir, rmdir, tree, ls, cp, rm, mv, who, whoami, w,命令替換, history, shell變量, $PS1, HISTSIZE, HISTFILE, HISTFILESIZE, HISTCONTROL, Linux文件類型, linux FHS, linux文件應用程序組成部分,$PATH, 文件時間戳管理工具(touch), stat, ls(-l,-l --time=atime)

1 查看命令cat, tac, more, less, head, tail, nl, od

  cat : Concatenate files and print on the standard output.全部顯示

    -b : 顯示行號,不包括空白

    -n : 顯示行號,包括空白

    -T : display TAB characters as ^I, TAB空格顯示為^I, 以區分space空格

    -E : display $ at end of each line, 在每行結尾處顯示$

    -v : use ^ and M- notation, except for LFD and TAB, 在windows中換行,若使用-v則顯示為^M

    -A(=-ETv)

  more : file persual filter for crt viewing, 一頁一頁的顯示內容,功能沒有less多。

    Enter : 向下翻一行

    Space : 向後翻一屏

    b : 向前翻一屏

    :f : 顯示正在查看的文件名和所在的行數

    /String : 向下查找"String"字符串

      n : 向下繼續查找"String"字符串

    q : 退出

  less : 功能類似more, 但比more強大

    Enter: 向下翻一行

    k : 向上翻一行

    Space, PgDn : 向下翻一屏

    b, PgUp : 向前翻一屏

    /String, ?string : 查找"String"字符串

      n : 向下繼續查找"String"字符串

      N : 向上繼續查找"String"字符串

    q : 退出

  head : head [OPTION]... [FILE]..., Output the first part of files

    -c # : Print the first # bytes of each file, 顯示前#個字節,如果-#則顯示文檔後#個字節

    -n # : Print the first # lines, default is 10 lines, 顯示前#行,若果-#則顯示文檔後#行

    -q : never print headers giving file names, 不在文檔頂部顯示文件名,默認不顯示

    -v : print headers giving file names, 在文檔頂部顯示文件名, 類似==> man.config <==

  tail : tail [OPTION]... [FILE]..., Output the last part of files

  nl : nl [OPTION]... [FILE]..., Number lines of files, 顯示各種類型的行號。

  od : dump files in octal and other formats, 查看二進制文件,並以不同的格式輸出

    -t(--format=TYPE)

      a : 以原來的格式輸出

      c : ASCII碼格式輸出

      d[SIZE] : signed decimal, SIZE bytes per integer, 有符號十進制

      f[SIZE] : floating point, SIZE byters per integer, 浮點數

      o[SIZE] : octal, SIZE byters per interger, 八進制

      u[SIZE] : unsigned decimal, SIZE bytes per integer, 有符號十進制

      x[SIZE] : hexadecimal, SIZE bytes per integer, 十六進制

2.目錄命令:cd, pwd, mkdir, rmdir

  cd : Change the shell working directory.

    cd /home/zhubiao/Desktop : 絕對路徑

    cd ~ : 回到家目錄

    cd : 回到家目錄

    cd - : 回到上一目錄

    cd ~zhubiao : 回到zhubiao用戶目錄,root才有權限

    cd .. : 回到上一層目錄

  pwd : Print working directory

    -P : avoid all symlinks

  mkdir : make directories

    -m : set file mode (as in chmod), not a=rwx - umask

    -p : make parent directories as needed

    -v : print a message for each createded directory

  rmdir : remove empty directories

    -p : remove directory and its ancestors

    -v : print a message for each remove directory

  tree : List contents of directories in a tree-like format

    -a : all files are printed, by default tree does not print hidden files

    -d : list directories only, 只顯示目錄

    -N # : max display depth of the dirctory tree, 顯示#層目錄

3.檔案管理命令: ls, cp, mv, rm

  ls : List directory contents

    -l : use a long listing format, ls -l alias is ll

    -a : 顯示隱藏文件包括 ., ..,

    -A : 顯示隱藏文件, 不包括 . 和 ..目錄

    -h(--human-readable) :

    -f : do not sort, 按原來順序顯示,不排序,不顯示其他顏色

    -F : 附加數據類型(*: 可執行文件,/: 目錄,=: socket,|:管道, @:符號鏈接)

    -R : List subdrictories recursively, 顯示所有子目錄和文件

    -S : sort by file size, 按大小排序

    -t : sort by modification time, 按時間排序

    --full-time : 顯示完整修改時間

    --time=atime : 按access time排序

    --time=ctime : 按change time排序

  cp : copy files and directories

    -f(--force)

  mv : move(rename) files

  rm : remove files or directories

4 who, whoami, w

  who : Show who is logged on

  whoami : 顯示當前登錄的賬號

  w : Show who is loggend on and what they are doing

5 shell特性

  (1) history : Display or manipulate the history list

    !! : 執行上一次命令

    !$ : 引用上一次命令的最後一個參數

    Esc . : 引用上一次命令的最後一個參數, 繼續按則繼續引用上一個參數

    !string : 執行history中最近一次命令頭部包含string字符串的命令

    !# : 執行history中第#條命令,-#執行history中倒數第#條命令

    與history 相關的變量

      $HISTFILE : 當前登錄賬戶命令歷史文件存放目錄

      $HSITSIZE : 當前緩存中最多存放history 命令的條數

      $HISTFILSIZE : .bash_history 文件中命令最大數目

      $HISTCONTROL : 控制命令歷史的產生

        ignoredups : 忽略聯系重復的命令

        ignorespace : 忽略命令前有空格的命令

        ignoreboth : 忽略上面兩種

  (2) 命令, 目錄補全

    若所輸入的字符串已能決定命令或目錄是唯一的,則按一次TAB鍵,補全該命令或目錄,若不是唯一的,則按兩次TAB鍵列出首部包含該字符串的所有命令或目錄

  (3) alias,別名

    alias : 列出所有已定義的別名

    alias aliasName='command' : 定義別名

      alias lm='ls -al'

  (4) 通配符*

6 shell 變量

  (1) 變量定義並賦值 : valueName=value, valueName=${value}

    變量值可以使用" ", ' ', ``

    " " : 保持雙引號內特殊字符的原有特性

    ' ' : 單引號內的字符僅為一般字符

    ` ` : 命令

    \ : 將特殊字符變成一般字符

    TIME="Now time is `date +%F`"

  (2) 變量的使用 : $valueName, ${valueName}

  (3) 變量刪除 : unset valueName

  (4) 變量的追加 : valueName="$valueName":newValue

    TIME="$TIME":"Now time is `date +%T`"

  (5) 變成環境變量 : export valueName

  (6) 設置為不可修改 : readonly valueName

7 type : Display information about command type

  -a : 列出所有,包括別名

8 若命令太長需要轉行使用 \Enter

9 文件類型

  -(f) : 普通文件

  d : 目錄文件

  b : 塊設備,隨機讀取

  c : 字符設備

  l : 符號鏈接文件

  p : 管道文件

  s : 套接字文件, socket

10 Linux應用程序組成部分

  (1) 二進制程序:/bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin

  (2) 庫文件:/lib(64), /usr/lib(64), /usr/local/lib(64)

  (3) 配置文件:/etc, /usr/etc, /usr/local/etc

  (4)幫助文件 : /usr/share/man, /usr/share/doc, /usr/local/share/man, /usr/local/share/doc

11 文件時間戳管理工具 touch

  三個時間戳:

    atime(access time) : 訪問時間,例如使用more,cat,less等查看該文檔則訪問時間將改變

    mtime(modify time) : 修改時間

    ctime(change time) : 改變時間,元數據發生改變

  查看文件信息和時間戳

    stat fileName

    ls -l --time=atime: access time

    ls -l(ll): modify time

    ls -l --time=ctime: change time

  時間戳修改工具 : touch

    touch -a fileName : 僅修改access time 為當前時間

    touch -m fileName: 僅修改modify time 為當前時間

    touch -a -t [[CC]YY]MMDDhhmm[.ss] : 修改access time為指定時間

    touch -a --date="MM/DD/[CC]YY hh:mm:ss"

    touch -m -t [[CC]YY]MMDDhhmm[.ss] : 修改modify time為指定時間

    touch -m --date="MM/DD/[CC]YY hh:mm:ss"

    touch fileName : 若文件不存在, 則創建文件

    touch -c fileName : 若文件不存在,不創建文件,取消執行

Copyright © Linux教程網 All Rights Reserved