cat命令汇总整理
Cat命令:一般用作打開文件,查看文件內容(可以一次查看多個文件),參數有如下幾個:
?????? -a 或 –all,顯示全部
?????? -b 或--number-nonblank 對非空輸出行編號
-n 或 --number 由 1 開始對所有輸出的行數編號
-s 或 --squeeze-blank 當遇到有連續兩行以上的空白行,就代換為一行的空白行
A.用于查看文件內容:cat blank.txt???? 查看名為blank的txt文件內容;
B.用于創建新的文件并輸入內容:cat > filename <<EOF,enter后輸入文件內容,結尾處<<EOF結束;
C . 將幾個文件合為一個文件:cat filename1 filename2 filename3 > newfilename? ,舉例如下:<cat還可以把一個或多個已存在的文件內容,追加到一個已存在的文件中:
cat s01 ?s02? s03 >> sA ,’>’意思是創建,’>>’是追加,不要記錯>
A例.[root@localhost ~]# cat -n initial-setup-ks.cfg original-ks.cfg
???? 1?? #version=DEVEL
???? 2?? # Install OS instead of upgrade
???? 3?? install
???? 4?? # X Window System configuration information
???? 5?? xconfig? --startxonboot
?
?B例.[root@localhost ~]# cat > 123 << EOF #新建一個以123命名的文件
> hallo world
> how are you
> i am? fine
> EOF ? ??
[root@localhost ~]# cat 123
hallo world
how are you
i am? fine
[root@localhost ~]# cat >> 123
i am very hot,how about you ?
^C
[root@localhost ~]# cat 123
hallo world
how are you
i am? fine
i am very hot,how about you ??已經累加到目標文件
?
C例.[root@localhost ~]# cat > 123 #新建3份文件,分別為123、abc、EFG,并為各文件輸入內容?
this is the frist file^C
[root@localhost ~]# cat > abc
the second file is setting now^C
[root@localhost ~]# cat > EFG
the last one ^C
[root@localhost ~]# ls -a
. 123? anaconda-ks.cfg? .bash_logout?? .bashrc? .config? .dbus? initial-setup-ks.cfg? original-ks.cfg? .xauth7xzQQg
..? abc? .bash_history??? .bash_profile? .cache?? .cshrc?? EFG??? mongodb_simple??????? .tcshrc
[root@localhost ~]# cat 123 abc EFG > newone
[root@localhost ~]# ls -a ? #查看目錄時,目標文件已經存在,
.?? 123? anaconda-ks.cfg? .bash_logout?? .bashrc? .config? .dbus? initial-setup-ks.cfg? newone #目標文件夾 ? .tcshrc
..? abc? .bash_history??? .bash_profile? .cache?? .cshrc?? EFG??? mongodb_simple?????? ?original-ks.cfg? .xauth7xzQQg
?
轉載于:https://www.cnblogs.com/bryant-dai/p/7419296.html
總結
- 上一篇: 利用WiFi Pineapple Nan
- 下一篇: 第46条:不要使用 dispatch_g