Linux查看顯示編輯文本文件




1:cat


-bash-4.1$ cat --help
用法:cat [選項]... [文件]...
將[文件]或標准輸入組合輸出到標准輸出。

  -A, --show-all           等於-vET
   -b, --number-nonblank    對非空輸出行編號
   -e                       等於-vE
   -E, --show-ends          在每行結束處顯示"$"
   -n, --number             對輸出的所有行編號
   -s, --squeeze-blank      不輸出多行空行
   -t                       與-vT 等價
   -T, --show-tabs          將跳格字符顯示為^I
   -u                       (被忽略)
   -v, --show-nonprinting   使用^ 和M- 引用,除了LFD和 TAB 之外
       --help        顯示此幫助信息並退出
       --version        顯示版本信息並退出

如果沒有指定文件,或者文件為"-",則從標准輸入讀取。

示例:
   cat f - g  先輸出f 的內容,然后輸出標准輸入的內容,最后輸出g 的內容。
   cat        將標准輸入的內容復制到標准輸出。



使用示例:

-bash-4.1$ cat run.sh
#!/bin/bash

gcc -o a resamp.c
./a
#ximage < SEG_C3NA_Velocity_resamp.dat n1=201

pscube <SEG_C3NA_Velocity_resamp.dat n1=201 n2=300 n3=300 >v.eps

gimp v.eps
-bash-4.1$





2:head(查看文件開頭)

-bash-4.1$ head --help
用法:head [選項]... [文件]...
將每個指定文件的頭10 行顯示到標准輸出。
如果指定了多於一個文件,在每一段輸出前會給出文件名作為文件頭。
如果不指定文件,或者文件為"-",則從標准輸入讀取數據。

長選項必須使用的參數對於短選項時也是必需使用的。
   -c,  --bytes=[-]K    顯示每個文件的前K 字節內容;
             如果附加"-"參數,則除了每個文件的最后K字節數據外
             顯示剩余全部內容
   -n, --lines=[-]K    顯示每個文件的前K 行內容;
             如果附加"-"參數,則除了每個文件的最后K 行外顯示
             剩余全部內容
   -q, --quiet, --silent    不顯示包含給定文件名的文件頭
   -v, --verbose        總是顯示包含給定文件名的文件頭
       --help        顯示此幫助信息並退出
       --version        顯示版本信息並退出

K 后面可以跟乘號:
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,
GB 1000*1000*1000, G 1024*1024*1024, 對於T, P, E, Z, Y 同樣適用。

head使用示例:
-bash-4.1$ head rm.sh
#!/bin/bash

rm *.class
rm */*.class
rm */*/*.class
rm */*/*/*.class
rm */*/*/*/*.class
rm */*/*/*/*/*.class
rm */*/*/*/*/*/*.class
rm */*/*/*/*/*/*/*.class
-bash-4.1$


3:tail (查看文本文件末端)


-bash-4.1$ tail --help
用法:tail [選項]... [文件]...
顯示每個指定文件的最后10 行到標准輸出。
若指定了多於一個文件,程序會在每段輸出的開始添加相應文件名作為頭。
如果不指定文件或文件為"-" ,則從標准輸入讀取數據。

長選項必須使用的參數對於短選項時也是必需使用的。
   -c, --bytes=K        輸出最后K 字節;另外,使用-c +K 從每個文件的
             第K 字節輸出
   -f, --follow[={name|descriptor}]
         即時輸出文件變化后追加的數據。
             -f, --follow 等於--follow=descriptor
   -F        即--follow=name --retry
   -n, --lines=K            output the last K lines, instead of the last 10;
                            or use -n +K to output lines starting with the Kth
       --max-unchanged-stats=N
                            with --follow=name, reopen a FILE which has not
                            changed size after N (default 5) iterations
                            to see if it has been unlinked or renamed
                            (this is the usual case of rotated log files).
                            With inotify, this option is rarely useful.
       --pid=PID        同 -f 一起使用,當 PID 所對應的進程死去后終止
   -q, --quiet, --silent    不輸出給出文件名的頭
       --retry        即使目標文件不可訪問依然試圖打開;在與參數
             --follow=name 同時使用時常常有用。
   -s, --sleep-interval=N   with -f, sleep for approximately N seconds
                              (default 1.0) between iterations.
                            With inotify and --pid=P, check process P at
                            least once every N seconds.
   -v, --verbose            always output headers giving file names
       --help        顯示此幫助信息並退出
       --version        顯示版本信息並退出

使用示例:
-bash-4.1$ tail rm.sh
rm */*/*/*/*/*~
rm */*/*/*/*/*/*~
rm */*/*/*/*/*/*/*~

echo "# # #"
ls
echo "# # #"
pwd
echo "# # #"

-bash-4.1$





4:more分頁顯示文件內容


-bash-4.1$ more rm.sh
#!/bin/bash

rm *.class
rm */*.class
rm */*/*.class
rm */*/*/*.class
rm */*/*/*/*.class
rm */*/*/*/*/*.class
rm */*/*/*/*/*/*.class
rm */*/*/*/*/*/*/*.class

rm *.pyc
rm */*.pyc
rm */*/*.pyc
rm */*/*/*.pyc
--More--(29%)


5:less分頁查看文件內容


                    SUMMARY OF LESS COMMANDS

      Commands marked with * may be preceded by a number, N.
       Notes in parentheses indicate the behavior if N is given.

  h  H                 Display this help.
   q  :q  Q  :Q  ZZ     Exit.
  ---------------------------------------------------------------------------

                           MOVING

  e  ^E  j  ^N  CR  *  Forward  one line   (or N lines).
   y  ^Y  k  ^K  ^P  *  Backward one line   (or N lines).
   f  ^F  ^V  SPACE  *  Forward  one window (or N lines).
   b  ^B  ESC-v      *  Backward one window (or N lines).
   z                 *  Forward  one window (and set window to N).
   w                 *  Backward one window (and set window to N).
   ESC-SPACE         *  Forward  one window, but don't stop at end-of-file.
   d  ^D             *  Forward  one half-window (and set half-window to N).
   u  ^U             *  Backward one half-window (and set half-window to N).
   ESC-)  RightArrow *  Left  one half screen width (or N positions).
   ESC-(  LeftArrow  *  Right one half screen width (or N positions).
   F                    Forward forever; like "tail -f".
   r  ^R  ^L            Repaint screen.
   R                    Repaint screen, discarding buffered input.
         ---------------------------------------------------
         Default "window" is the screen height.
         Default "half-window" is half of the screen height.
  ---------------------------------------------------------------------------

                          SEARCHING

HELP -- Press RETURN for more, or q when done

使用示例:
$less rm.sh
#!/bin/bash

rm *.class
rm */*.class
rm */*/*.class
rm */*/*/*.class
rm */*/*/*/*.class
rm */*/*/*/*/*.class
rm */*/*/*/*/*/*.class
rm */*/*/*/*/*/*/*.class

rm *.pyc
rm */*.pyc
rm */*/*.pyc
rm */*/*/*.pyc
rm.sh


6:grep

Linux系統中grep命令是一種強大的文本搜索工具,它能使用正則表達式搜索文本,並把匹 配的行打印出來。grep全稱是Global Regular Expression Print,表示全局正則表達式版本,它的使用權限是所有用戶



-bash-4.1$ grep --help
用法: grep [選項]... PATTERN [FILE]...
在每個 FILE 或是標准輸入中查找 PATTERN。
默認的 PATTERN 是一個基本正則表達式(縮寫為 BRE)。
例如: grep -i 'hello world' menu.h main.c
 
正則表達式選擇與解釋:
   -E, --extended-regexp     PATTERN 是一個可擴展的正則表達式(縮寫為 ERE)
   -F, --fixed-strings       PATTERN 是一組由斷行符分隔的定長字符串。
   -G, --basic-regexp        PATTERN 是一個基本正則表達式(縮寫為 BRE)
   -P, --perl-regexp         PATTERN 是一個 Perl 正則表達式
   -e, --regexp=PATTERN      用 PATTERN 來進行匹配操作
   -f, --file=FILE           從 FILE 中取得 PATTERN
   -i, --ignore-case         忽略大小寫
   -w, --word-regexp         強制 PATTERN 僅完全匹配字詞
   -x, --line-regexp         強制 PATTERN 僅完全匹配一行
   -z, --null-data           一個 0 字節的數據行,但不是空行
 
Miscellaneous:
   -s, --no-messages         suppress error messages
   -v, --invert-match        select non-matching lines
   -V, --version             display version information and exit
       --help                display this help text and exit
 
輸出控制:
   -m, --max-count=NUM       NUM 次匹配后停止
   -b, --byte-offset         輸出的同時打印字節偏移
   -n, --line-number         輸出的同時打印行號
       --line-buffered       每行輸出清空
   -H, --with-filename       為每一匹配項打印文件名
   -h, --no-filename         輸出時不顯示文件名前綴
       --label=LABEL         將LABEL 作為標准輸入文件名前綴
   -o, --only-matching       show only the part of a line matching PATTERN
   -q, --quiet, --silent     suppress all normal output
       --binary-files=TYPE   assume that binary files are TYPE;
                             TYPE is 'binary', 'text', or 'without-match'
   -a, --text                equivalent to --binary-files=text
   -I                        equivalent to --binary-files=without-match
   -d, --directories=ACTION  how to handle directories;
                             ACTION is 'read', 'recurse', or 'skip'
   -D, --devices=ACTION      how to handle devices, FIFOs and sockets;
                             ACTION is 'read' or 'skip'
   -r, --recursive           like --directories=recurse
   -R, --dereference-recursive
                             likewise, but follow all symlinks
       --include=FILE_PATTERN
                             search only files that match FILE_PATTERN
       --exclude=FILE_PATTERN
                             skip files and directories matching FILE_PATTERN
       --exclude-from=FILE   skip files matching any file pattern from FILE
       --exclude-dir=PATTERN directories that match PATTERN will be skipped.
   -L, --files-without-match print only names of FILEs containing no match
   -l, --files-with-matches  print only names of FILEs containing matches
   -c, --count               print only a count of matching lines per FILE
   -T, --initial-tab         make tabs line up (if needed)
   -Z, --null                print 0 byte after FILE name
 
文件控制:
   -B, --before-context=NUM  打印以文本起始的NUM 行
   -A, --after-context=NUM   打印以文本結尾的NUM 行
   -C, --context=NUM         打印輸出文本NUM 行
   -NUM                      same as --context=NUM
       --group-separator=SEP use SEP as a group separator
       --no-group-separator  use empty string as a group separator
       --color[=WHEN],
       --colour[=WHEN]       use markers to highlight the matching strings;
                             WHEN is 'always', 'never', or 'auto'
   -U, --binary              do not strip CR characters at EOL (MSDOS/Windows)
   -u, --unix-byte-offsets   report offsets as if CRs were not there
                             (MSDOS/Windows)



使用示例:

$ grep ‘test’ d*
顯示所有以d開頭的文件中包含 test的行。
$ grep ‘test’ aa bb cc
顯示在aa,bb,cc文件中匹配test的行。
$ grep ‘[a-z]\{5\}’ aa
顯示所有包含每個字符串至少有5個連續小寫字符的字符串的行。
$ grep ‘w\(es\)t.*\1′ aa
如果west被匹配,則es就被存儲到內存中,並標記為1,然后搜索任意個字符(.*),這些字符后面緊跟着 另外一個es(\1),找到就顯示該行。如果用egrep或grep -E,就不用”\”號進行轉義,直接寫成’w(es)t.*\1′就可以了


-bash-4.1$ grep "clas" rm.sh
rm *.class
rm */*.class
rm */*/*.class
rm */*/*/*.class
rm */*/*/*/*.class
rm */*/*/*/*/*.class
rm */*/*/*/*/*/*.class
rm */*/*/*/*/*/*/*.class
-bash-4.1$

-bash-4.1$ grep "float " conio.h resamp.c

resamp.c: float *v = (float*)malloc(sizeof(float)*nx*ny*nz);

-bash-4.1$


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM