linux下檔案的基本命令

來源:互聯網
上載者:User

標籤:linux   centos   檔案命令   

文本的基本命令(cat、tac、head、tail、more、less、rev)


查看檔案的內容 cat

cat -n /etc/passwd    可以列出序號顯示檔案

[[email protected] ~]# cat -n /etc/passwd     1root:x:0:0:root:/root:/bin/bash     2bin:x:1:1:bin:/bin:/sbin/nologin     3daemon:x:2:2:daemon:/sbin:/sbin/nologin     4adm:x:3:4:adm:/var/adm:/sbin/nologin     5lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin     6sync:x:5:0:sync:/sbin:/bin/sync

cat -A     每一行結尾添加$尾碼 

[[email protected] ~]# cat -A /etc/resolv.conf ; generated by /sbin/dhclient-script$nameserver 192.168.20.2$nameserver 8.8.8.8$$


查看檔案的內容分頁顯示 

more  空格鍵翻頁 斷行符號鍵上移 q鍵退出


查看檔案的內容 less 

空格鍵翻頁,斷行符號鍵向下翻,可以按方向鍵上移下移,pageup pagedown可以上下翻頁,q鍵退出

ctrl+f     向下翻頁

ctrl+b    向上翻頁

j     向下翻

k    向上翻

G    跳轉到最後一行

g    跳轉到第一行

/     往下搜尋   

?    往上搜尋


只顯示檔案前10行內容 head 

head -n 20 /etc/passwd 顯示前20行內容 

head -n20 /etc/passwd  顯示前20行內容,n後面不用空格

head -20 /etc/passwd 中間的參數n可以省略,中間不能有空格

[[email protected] ~]# head -5 /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologin


只顯示檔案後10行內容 tail

tail -n 2 /etc/passwd 顯示最後2行內容,同樣中間的參數n可以省略

tail -f /var/log/messages         # -f 動態查看 系統日誌

[[email protected] ~]# tail -5 /etc/passwdsaslauth:x:499:76:"Saslauthd user":/var/empty/saslauth:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinuser1:x:500:501::/home/user1:/bin/bashuser2:x:501:502::/home/user2:/bin/bash



左右顛倒顯示檔案的內容 rev

[[email protected] ~]# echo ‘aabb‘>huang[[email protected] ~]# cat huangaabb[[email protected] ~]# rev huangbbaa


上下顛倒顯示檔案的內容tac

[[email protected] ~]# cat huangaabbcc[[email protected] ~]# tac huangccbbaa


本文出自 “模範生的學習部落格” 部落格,請務必保留此出處http://8802265.blog.51cto.com/8792265/1621909

linux下檔案的基本命令

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.