1. 程式人生 > >Linux常用操作命令之cat

Linux常用操作命令之cat

常用操作命令 文本內容電視

cat:顯示文本文件

使用cat命令可以顯示文本文件的內容,也可以把幾個文件的內容追加到另一個文件中。如果沒有指定文件,或者文件為“-”,那麽就從標準輸入讀取。

命令語法:

 cat [選項] [文件]

選項:

-n :對輸出的所有行編號

-b :對非空輸出行編號

-s :當遇到多行的空行時,將其顯示為一行的空白行

-E :在每行結束處顯示$

例子:

  1. 顯示/etc/inittab 文件的內容
    
    [root@jdyun ~]# cat /etc/inittab 
    # inittab is only used by upstart for the default runlevel.
    #
    # ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
    #
    # System initialization is started by /etc/init/rcS.conf
    #
    # Individual runlevels are started by /etc/init/rc.conf
    #
    # Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
    #
    # Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
    # with configuration in /etc/sysconfig/init.
    #
    # For information on how to write upstart event handlers, or how
    # upstart works, see init(5), init(8), and initctl(8).
    #
    # Default runlevel. The runlevels used are:
    #   0 - halt (Do NOT set initdefault to this)
    #   1 - Single user mode
    #   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
    #   3 - Full multiuser mode
    #   4 - unused
    #   5 - X11
    #   6 - reboot (Do NOT set initdefault to this)
    # 
    id:3:initdefault:
  2. 把文件test1的內容加上行號輸入到test2文件中
    [root@jdyun data]# cat  -n test1>>test2
    [root@jdyun data]# cat test2
         1    sfsg
         2    faqeg
         3    agsg
  3. 使用cat命令創建文件test1文件
    [root@jdyun data]# cat >test1<<EOF    #開頭和結尾的EOF可用任意字符替換,習慣上使用EOF
    sfsg
    faqeg
    agsg
    EOF
    
    [root@jdyun data]# cat test1    #查看tes1中的文件內容
    sfsg
    faqeg
    agsg

本文出自 “Linux學習記錄” 博客,請務必保留此出處http://zjmlinux.blog.51cto.com/4684186/1982955

Linux常用操作命令之cat