1.显示/etc/passwd的前15行内容
[root@blueendingnova xiang]# head -15 /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin games:x:12:100:games:/usr/games:/sbin/nologin ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin nobody:x:99:99:Nobody:/:/sbin/nologin systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin dbus:x:81:81:System message bus:/:/sbin/nologin
[root@blueendingnova xiang]# head -n 15 /etc/passwd
head 取文件的前多少行,默认是前10
2.显示/etc/ssh/sshd_config文件的最后5行内容
[root@blueendingnova xiang]# tail -5 /etc/ssh/sshd_config #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server
[root@blueendingnova xiang]# tail -n 5 /etc/ssh/sshd_confi
tail 从文件的末尾开始读取内容,默认是读取文件的最后10
tail -n +2 从第2行开始到末尾 --->优势:可以去掉第1行,标题行
tail -n -2 取最后2行
tail -n 2 取最后2行
tail -2 取最后2行
3.显示/etc/ssh/sshd_config文件的第20行内容
[root@blueendingnova xiang]# head -n 20 /etc/ssh/sshd_config |tail -1 #ListenAddress ::
4.显示/etc/ssh/sshd_config文件的第10行到20行内容
[root@blueendingnova xiang]# cat -n /etc/ssh/sshd_config |head|tail -6 5 6 # This sshd was compiled with PATH=/usr/local/bin:/usr/bin 7 8 # The strategy used for options in the default sshd_config shipped with 9 # OpenSSH is to specify options with their default value where 10 # possible, but leave them commented. Uncommented options override the
nl 和cat -n 的区别: nl不会给空行编号,而cat -n 会给空格编号
[root@blueendingnova xiang]# nl /etc/ssh/sshd_config |head|tail -6
4 # This sshd was compiled with PATH=/usr/local/bin:/usr/bin
5 # The strategy used for options in the default sshd_config shipped with
6 # OpenSSH is to specify options with their default value where
7 # possible, but leave them commented. Uncommented options override t
5.动态监控文件/var/log/messages文件,然后新开一个终端重定向内容123456到/var/log/messages里,最后退出tail命令
[root@nfs-server ~]# tail -f /var/log/messages Apr 13 16:42:32 nfs-server systemd: Created slice User Slice of root. Apr 13 16:42:32 nfs-server systemd: Started Session 1 of user root. Apr 13 16:42:32 nfs-server systemd-logind: New session 1 of user root. Apr 13 16:43:11 nfs-server systemd-logind: New session 2 of user root. Apr 13 16:43:11 nfs-server systemd: Started Session 2 of user root. Apr 13 16:44:41 nfs-server chronyd[703]: Selected source 84.16.73.33 Apr 13 16:48:00 nfs-server systemd-logind: New session 3 of user root. Apr 13 16:48:00 nfs-server systemd: Started Session 3 of user root. Apr 13 16:57:59 nfs-server systemd: Starting Cleanup of Temporary Directories... Apr 13 16:57:59 nfs-server systemd: Started Cleanup of Temporary Directories. 123456
[root@nfs-server ~]# echo 123456 >> /var/log/message
tail -f machi.txt 动态的监控文件末尾的变化,一旦文件末尾有内容输入,马上读取出来,输出到屏幕上
tailf = tail -f
按ctrl+c强行退出
重定向: 将本来应该在屏幕上的输出,重新定义输出的方向,输出到文件里,改变了内容的输出方向
作用: 可以将我们需要保存的内容,写到一个文件里
>> 追加输出重定向: 作用将内容输出追加到文件的末尾,不覆盖原来文件的内容,如果文件不存在会自动新建
> 将内容输出到文件里,但是会覆盖原来文件里的内容,如果文件不存在会自动新建
6.显示w命令输出的内容,但是需要从第2行开始显示到末尾,不显示第1行
[root@nfs-server ~]# w |tail -n +2 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty1 16:42 27:51 0.02s 0.02s -bash root pts/0 192.168.18.1 16:43 7.00s 0.03s 0.00s w root pts/1 192.168.18.1 16:48 10:47 0.01s 0.01s -bash
wc 统计文件的行,字节数,单词
[root@sanchuang ~]# man wc 查看wc的使用手册 manual 手册
wc - print newline, word, and byte counts for each file
-l, --lines
print the newline counts
10.在/changde文件夹下新建10个空文件 zhang1.txt到zhang10.txt
[root@nfs-server changde]# touch zhang{1..10}.txt [root@nfs-server changde]# ls zhang10.txt zhang2.txt zhang4.txt zhang6.txt zhang8.txt zhang1.txt zhang3.txt zhang5.txt zhang7.txt zhang9.txt
12.复制所有的zhang开头的文件到/lianxi
[root@nfs-server changde]# cp zhang* /lianxi [root@nfs-server changde]# cd /lianxi [root@nfs-server lianxi]# ls changde zhang1.txt zhang3.txt zhang5.txt zhang7.txt zhang9.txt zhang10.txt zhang2.txt zhang4.txt zhang6.txt zhang8.txt
* 通配符: 通通匹配的符号,代表任意个任意字符
13.复制zhang8.txt到/lianxi改名为zhang800.txt
[root@nfs-server lianxi]# cp /lianxi/changde/zhang8.txt /lianxi/zhang800.txt [root@nfs-server lianxi]# ls changde zhang1.txt zhang3.txt zhang5.txt zhang7.txt zhang8.txt zhang10.txt zhang2.txt zhang4.txt zhang6.txt zhang800.txt zhang9.txt
复制,粘贴,重命名
14.复制hunan文件夹到shandong文件夹里
[root@nfs-server lianxi]# cp /hunan/* /shandong -r
复制文件夹的时候,需要接选项 -r -R, -r, --recursive 递归: 将文件夹里的子文件夹,子文件夹里的子文件都复制过去 copy directories recursively
标签:sbin,入门,16,server,nfs,linux,txt,root From: https://www.cnblogs.com/Himawari/p/17315718.html