失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > linux常用命令练习:wc cut | tee tail

linux常用命令练习:wc cut | tee tail

时间:2020-01-29 02:15:19

相关推荐

linux常用命令练习:wc cut | tee tail

linux常用命令相关练习:

1、只显示/etc/inittab 文件有多少行,其他信息不显示:

#wc -l /etc/inittab | cut -d' ' -f1

[root@xuelinux ~]# wc -l /etc/inittab | cut -d' ' -f1

26

2、统计/usr/bin目录下的文件个数:

#ls /usr/bin | wc -l

[root@xuelinux ~]# ls /usr/bin | wc -l

1748

3、取出当前系统上所有用户的shell,要求,每种shell只显示一次,并且按顺序进行显示;

#cut -d: -f7 /etc/passwd |sort -u

[root@xuelinux ~]# cut -d: -f7 /etc/passwd |sort -u

/bin/bash

/bin/sync

/sbin/halt

/sbin/nologin

/sbin/shutdown

4、思考:如何显示/var/log目录下每个文件的内容类型?

[root@xuelinux ~]# file /var/log/* 或者file `ls /var/log`

/var/log/anaconda.ifcfg.log: ASCII text

/var/log/anaconda.log:UTF-8 Unicode English text

/var/log/anaconda.program.log: ASCII English text, with very long lines, with overstriking

5、取出/etc/inittab文件的第六行;

[root@xuelinux ~]# head -6 /etc/inittab | tail -1 先取前六行然后通过管道取最后一行

#

6、取出/etc/passwd文件中倒数第9个用户的用户名和shell,

显示到屏幕上并讲其保存至/tmp/users文件中;

[root@xuelinux ~]# tail -9 /etc/passwd | head -1 | cut -d: -f1,7|tee/tmp/users

rpcuser:/sbin/nologintee 内容显示在屏幕上并保存至指定目录

7、显示/etc目录下所有以pa开头的文件,并统计其个数;

[root@xuelinux ~]# ls -d /etc/pa* | wc -l

4

8、不使用文本编辑器,将alias cls=clear 一行内容添加至当前用户的.bashrc文件中;

[root@xuelinux ~]# echo "alias cls=clear" >>.bashrc

[root@xuelinux ~]# tail .bashrc

alias rm='rm -i'

alias cp='cp -i'

alias mv='mv -i'

# Source global definitions

if [ -f /etc/bashrc ]; then

. /etc/bashrc

fi

alias cls=clear

如果觉得《linux常用命令练习:wc cut | tee tail》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。