1、文件内容查看:
(1)查看/etc/passwd文件的第6行 
(2)查看/etc/selinux/config 以 SELINUX开头的行

(3)查找/etc/ssh/sshd_config 以no结尾的行

(4)过滤/etc/ssh/sshd_config 包含数字的行

(1)查看/etc/passwd文件的第6行

[root@server ~]# head -6 /etc/passwd | tail -1
sync:x:5:0:sync:/sbin:/bin/sync

验证

[root@server ~]# cat /etc/passwd -n1  root:x:0:0:root:/root:/bin/bash2  bin:x:1:1:bin:/bin:/sbin/nologin3  daemon:x:2:2:daemon:/sbin:/sbin/nologin4  adm:x:3:4:adm:/var/adm:/sbin/nologin5  lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin6  sync:x:5:0:sync:/sbin:/bin/sync7  shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown8  halt:x:7:0:halt:/sbin:/sbin/halt

(2)查看/etc/selinux/config 以 SELINUX开头的行

[root@server ~]# grep ^"SELINUX" /etc/selinux/config
SELINUX=enforcing
SELINUXTYPE=targeted
[root@server ~]#

验证

[root@server ~]# cat /etc/selinux/config# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted[root@server ~]#

(3)查找/etc/ssh/sshd_config 以no结尾的行

[root@server ~]# grep "no"$ /etc/ssh/sshd_config
#HostbasedAuthentication no
#IgnoreUserKnownHosts no
#PermitEmptyPasswords no
ChallengeResponseAuthentication no
#KerberosAuthentication no
#KerberosGetAFSToken no
GSSAPICleanupCredentials no
#GSSAPIKeyExchange no
#GSSAPIEnablek5users no
#GatewayPorts no
PrintMotd no
#PermitUserEnvironment no
#UseDNS no
#PermitTunnel no
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
[root@server ~]#

这里可以输入以下代码来验证,由于数据过长,就不在此演示了。

 cat /etc/ssh/sshd_config

(4)过滤/etc/ssh/sshd_config 包含数字的行

[root@server ~]# grep -v [0-9] /etc/ssh/sshd_config# This is the sshd server system-wide configuration file.  See# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#AddressFamily any
#ListenAddress ::HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key# Ciphers and keying
#RekeyLimit default none# This system is following system-wide crypto policy. The changes to
# crypto properties (Ciphers, MACs, ...) will not have any effect here.
# They will be overridden by command-line options passed to the server
# on command line.# Logging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
#LogLevel INFO

这里只展示部分数据,具体样式可以自行尝试

2、文本处理命令:
(1)查看/etc/passwd文件以 : 为分隔符的第一列内容,并按字母逆序排序

(2)使用cut命令将当前主机的ip地址切割显示

(1)查看/etc/passwd文件以 : 为分隔符的第一列内容,并按字母逆序排序

[root@server ~]# cut -d : -f 1 /etc/passwd | sort -r
xiaoming
usbmuxd
unbound
tss
tcpdump
systemd-resolve
systemd-coredump
sync
sssd
sshd
shutdown
setroubleshoot
saslauth
rtkit
rpcuser
rpc
root

(2)使用cut命令将当前主机的ip地址切割显示

[root@server ~]# ip a | head -9 | tail -1 | cut -d " " -f 6 | cut -d / -f 1
192.168.240.128

3、复制、移动 
(1)在/test目录下创建一个子目录dir,将/etc/passwd复制到该目录

(2)将/etc/ssh/sshd_config文件复制到/test目录 
(3)将/etc/yum.repos.d/目录复制到/test目录 
(4)将/etc/hosts文件复制到/test目录 
(5)将/etc/hostname文件复制到/test目录 
(6)将/test/sshd_config文件移动到/test/dir目录下并改名为sshd.conf

1)在/test目录下创建一个子目录dir,将/etc/passwd复制到该目录

[root@server ~]# mkdir /test/dir
[root@server ~]# cp -a /etc/passwd /test/dir
[root@server ~]#

(2)将/etc/ssh/sshd_config文件复制到/test目录

[root@server ~]# cp /etc/ssh/sshd_config  /test

(3)将/etc/yum.repos.d/目录复制到/test目录

[root@server ~]# cp -a  /etc/yum.repos.d/ /test

(4)将/etc/hosts文件复制到/test目录

[root@server ~]# cp /etc/hosts  /test

(5)将/etc/hostname文件复制到/test目录

[root@server ~]# cp /etc/hostname  /test

验证

[root@server ~]# ll /test/
total 52
-rw-r--r--. 1 root root  100 Oct 27 12:04 bashrc
drwxr-xr-x. 2 root root   20 Oct 28 11:09 dir
-rw-r--r--. 1 root root  145 Oct 27 11:35 file
-rw-r--r--. 1 root root   10 Oct 27 12:01 group
-rw-r--r--. 1 root root    7 Oct 28 11:15 hostname
-rw-r--r--. 1 root root  158 Oct 28 11:14 hosts
-rw-r--r--. 2 root root   17 Oct 27 11:27 motd.hard
-rw-r--r--. 1 root root   74 Oct 27 11:26 motd.soft
-rw-r--r--. 1 root root    0 Oct 27 11:10 passed
-rw-r--r--. 1 root root 2599 Oct 27 11:53 passwd
-rw-r--r--. 1 root root   36 Oct 27 11:42 profile
-rw-r--r--. 1 root root 4275 Oct 27 12:14 sshd.conf
-rw-r--r--. 1 root root 4275 Oct 27 12:14 sshd_config
drwxr-xr-x. 2 root root   25 Oct 16 13:52 yum.repos.d
[root@server ~]# ll /test/dir
total 4
-rw-r--r--. 1 root root 2595 Oct 27 08:19 passwd
[root@server ~]#

(6)将/test/sshd_config文件移动到/test/dir目录下并改名为sshd.conf,同时验证

[root@server ~]# mv /test/sshd_config  /test/dir/sshd.conf
[root@server ~]# ll /test/dir/sshd.conf
-rw-r--r--. 1 root root 4275 Oct 27 12:14 /test/dir/sshd.conf
[root@server ~]#

4、文件查找 
(1)在$HOME目录及其子目录中,查找2天前被更改过的文件

(2)在/etc/目录下寻找以host开头的文件 
(3)在/test/下面查找目录文件 
(4)在/test目录及子目录中,查找超过2KB的文件

(1)在$HOME目录及其子目录中,查找2天前被更改过的文件

[root@server ~]# find $HOME -mtime +2
/root/.bash_logout
/root/.bash_profile
/root/.bashrc
/root/.cshrc
/root/.tcshrc
/root/anaconda-ks.cfg
/root/.cache
/root/.cache/mesa_shader_cache
/root/.cache/mesa_shader_cache/49
/root/.cache/mesa_shader_cache/49/b76cdeb8eac746c20bd3016b1aa91f041444cd
/root/.cache/mesa_shader_cache/49/0e7d0c40d83a994d60a789ff26e72afa16df73
/root/.cache/mesa_shader_cache/1a
/root/.cache/mesa_shader_cache/1a/e3b165f292a0ff4b545ca3ac4fbf01caa604f6
/root/.cache/mesa_shader_cache/a0
/root/.cache/mesa_shader_cache/a0/93fef1a885ecd122beef63866dc816c834a795
/root/.cache/mesa_shader_cache/77
/root/.cache/mesa_shader_cache/77/59ed019172cb53ead0bed0967383ce828fc912
/root/.cache/mesa_shader_cache/ec
/root/.cache/mesa_shader_cache/ec/6655ce34b060f9ef3b2ab

(2)在/etc/目录下寻找以host开头的文件

[root@server ~]# find /etc -name host*
/etc/host.conf
/etc/hosts
/etc/avahi/hosts
/etc/hostname
/etc/nvme/hostnqn
/etc/nvme/hostid
[root@server ~]#

(3)在/test/下面查找目录文件

[root@server ~]# find /test -type d
/test
/test/dir
/test/yum.repos.d
[root@server ~]#

(4)在/test目录及子目录中,查找超过2KB的文件

[root@server ~]# find /test -size +2k
/test/passwd
/test/sshd.conf
/test/.bashrc.swp
/test/dir/passwd
/test/dir/sshd.conf
[root@server ~]#

注意,这里的k是小写的。

5、打包压缩 
(1)将/test目录下的所有文件和文件夹全部压缩成myfile.zip文件

(2)把myfile.zip文件解压到 /opt 
(3)将/opt目录下的文件全部打包并用gzip压缩成/test/newfile.tar.gz

(4)查看/test/newfile.tar.gz文件中有哪些文件?

(5)将newfile.tar.gz下载至windows客户端主机
 (6)在/test目录内,备份/etc下的所有文件并保留其权限

(1)将/test目录下的所有文件和文件夹全部压缩成myfile.zip文件

[root@server ~]# zip -r myfile.zip *adding: anaconda-ks.cfg (deflated 44%)adding: Desktop/ (stored 0%)adding: Documents/ (stored 0%)adding: Downloads/ (stored 0%)adding: file-10-24 (stored 0%)adding: initial-setup-ks.cfg (deflated 48%)adding: Music/ (stored 0%)adding: Pictures/ (stored 0%)adding: Public/ (stored 0%)adding: Templates/ (stored 0%)adding: Videos/ (stored 0%)

(2)把myfile.zip文件解压到 /opt

[root@server ~]# unzip myfile.zip -d /opt
Archive:  myfile.zipinflating: /opt/anaconda-ks.cfgcreating: /opt/Desktop/creating: /opt/Documents/creating: /opt/Downloads/extracting: /opt/file-10-24inflating: /opt/initial-setup-ks.cfgcreating: /opt/Music/creating: /opt/Pictures/creating: /opt/Public/creating: /opt/Templates/creating: /opt/Videos/
[root@server ~]#

验证

[root@server ~]# ll /opt
total 8
-rw-------. 1 root root 1382 Oct 16 12:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Desktop
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Documents
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Downloads
-rw-r--r--. 1 root root    0 Oct 24 07:39 file-10-24
-rw-r--r--. 1 root root 1654 Oct 16 13:04 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Music
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Pictures
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Public
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Templates
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Videos
[root@server ~]#

(3)将/opt目录下的文件全部打包并用gzip压缩成/test/newfile.tar.gz,并验证。

[root@server ~]# tar -czf /test/newfile.tar.gz /opt/*
tar: Removing leading `/' from member names
tar: Removing leading `/' from hard link targets
[root@server ~]# ll
total 12
-rw-------. 1 root root 1382 Oct 16 12:54 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Desktop
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Documents
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Downloads
-rw-r--r--. 1 root root    0 Oct 24 07:39 file-10-24
-rw-r--r--. 1 root root 1654 Oct 16 13:04 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Music
-rw-r--r--. 1 root root 3283 Oct 28 11:28 myfile.zip
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Pictures
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Public
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Templates
drwxr-xr-x. 2 root root    6 Oct 16 13:28 Videos
[root@server ~]#

(4)查看/test/newfile.tar.gz文件中有哪些文件?

[root@server test]# tar tf newfile.tar.gz
opt/anaconda-ks.cfg
opt/Desktop/
opt/Documents/
opt/Downloads/
opt/file-10-24
opt/initial-setup-ks.cfg
opt/Music/
opt/Pictures/
opt/Public/
opt/Templates/
opt/Videos/
[root@server test]#

(5)将newfile.tar.gz下载至windows客户端主机

进入根目录下test文件中,找到newfile.tar.gz文件,并将它下载到Windows

(6)在/test目录内,备份/etc下的所有文件并保留其权限

[root@server ~]# cp -a /etc/*

查看

[root@server ~]# ll /test
total 1356
drwxr-xr-x.  3 root root        28 Oct 16 12:45 accountsservice
-rw-r--r--.  1 root root        16 Oct 16 13:04 adjtime
-rw-r--r--.  1 root root      1529 Apr 15  2020 aliases
drwxr-xr-x.  3 root root        65 Oct 16 12:47 alsa
drwxr-xr-x.  2 root root      4096 Oct 16 12:50 alternatives
drwxr-xr-x.  4 root root        58 Oct 16 12:47 anaconda
-rw-r--r--.  1 root root       541 Jun 12  2019 anacrontab
-rw-r--r--.  1 root root        55 Jun 14  2021 asound.conf
-rw-r--r--.  1 root root         1 Aug 12  2018 at.deny
drwxr-x---.  4 root root       100 Oct 16 12:46 audit
drwxr-xr-x.  3 root root       228 Oct 16 12:53 authselect
drwxr-xr-x.  4 root root        71 Oct 16 12:46 avahi
drwxr-xr-x.  2 root root       150 Oct 16 12:48 bash_completion.d
-rw-r--r--.  1 root root      3027 Oct 24 07:58 bashrc
-rw-r--r--.  1 root root       535 Apr 17  2021 bindresvport.blacklist
drwxr-xr-x.  2 root root         6 Sep 23  2021 binfmt.d
drwxr-xr-x.  2 root root        23 Oct 16 12:45 bluetooth
-rw-r-----.  1 root brlapi      33 Oct 16 12:46 brlapi.key
drwxr-xr-x.  7 root root        84 Oct 16 12:46 brltty
-rw-r--r--.  1 root root     25696 Oct 21  2020 brltty.conf
-rw-r--r--.  1 root root         0 Oct 30 00:24 cd
drwxr-xr-x.  2 root root         6 Jul 27  2021 chkconfig.d
drwxr-xr-x.  3 root root        36 Oct 16 12:47 chromium

linux相关命令------文件内容显示以及文件其他命令相关推荐

  1. Linux文件内容显示

    目录 1.文件内容浏览 2.cut命令使用 3.uniq命令使用 4.sort命令 5.替换大小写 1.文件内容浏览 a.cat查看/etc/passwd文件内容,且输出时带行号 cat -n 对输出 ...

  2. 【Linux】查看文件内容的5个常用命令

    前言 不管是在日常工作连接远程服务器中,还是在平时个人电脑使用中(如果使用的Mac OS 或 Linux系统的话),都离不开强大的Terminal终端. 比如,查看远程服务器上的程序运行日志,使用终端 ...

  3. linux 查看文件内容 显示行号

    linux 系统中文件内容显示行号分为临时显示和永久显示两种,本文对两种方式进行介绍 1.文件内容临时显示行号 1. 1使用 vi 或者vim 命令打开文件 打开后的文件内容日如下 1. 2直接输入以 ...

  4. linux中sed -i命令修改文件内容、在文件中插入行、删除文件中删除行

    文章目录 0.sed -i与sed 1.修改文件内容 2.在文件中插入行 3.在文件中删除行 4.使用find查找文件,并用 | xargs传输文件名给sed命令 0.sed -i与sed sed - ...

  5. Linux 命令之 less -- 分屏上下翻页浏览文件内容(查看文件内容/显示文件内容)

    文章目录 介绍 语法格式 常用选项 浏览文本内容的快捷键 向前滚屏 向后滚屏 跳跃 搜索 退出 less 参考示例 (一)查看文件 (二)ps查看进程信息并通过less分页显示 (三)查看命令历史使用 ...

  6. linux中合并多个文件内容到一个文件的例子

    Windows 中实现合并多个文件内容到一个文件中  代码如下 复制代码 copy *.sql MERGE.sql Linux 或 类Unix 下实现合并多个文件内容到一个文件中  代码如下 复制代码 ...

  7. Linux 批量清除文件内容而不删除文件

    Linux批量清理多个文件内容而不删除文件 清理单个文件,可以这样:echo > myLog.log 但是,如果我要清理一堆文件,比如在/logs目录下面的所有以.log结尾的文件的内容,而不删 ...

  8. 删除文件时显示该文件不在此文件夹中的原因

    问题描述 删除文件时显示该文件不在此文件夹中,在网上搜索资料都是新建一个bat通过拖拽删除. 但是具体为什么无法删除并没有说明,于是我通过排除法,一步步删除子文件夹,直到找到无法删除的文件. 原因分析 ...

  9. EXCEL宏根据指定行数来切割excel文件内容成新文件

    EXCEL宏根据指定行数来切割excel文件内容成新文件 宏内容 Sub splitexcel() Dim r, c, i, totalhangshu, fileshu, bt As Long App ...

最新文章

  1. MXNet中x.grad源码追溯
  2. Python 命令行参数
  3. 解读.net垃圾回收和CLR 4.0对垃圾回收所做的改进之一-.Net编程教程
  4. Linux 下升级 python2 到python3
  5. C#三层架构第九课之反射和工厂模式实现多数据库访问
  6. [转]经典SQL语句大全
  7. java监听上传文件,Springmvc文件上传监听详解
  8. jQuery学习笔记02
  9. 如何写前端技术方案文档?
  10. 解决Xcode 9.x 没有代码提示
  11. 去除360安全卫士的广告弹窗(亲测有效)
  12. 如何做一个自律的人?
  13. Ubuntu 重置用户密码
  14. Content negotiation
  15. python用于爬虫的包是_Python 爬虫之抓包的理解
  16. MySQL数据库创建表一系列操作
  17. 技巧分享篇---如何从GitHub上下载某个项目中单个文件的方法
  18. 如何修改psd文件?psd样式怎么修改文字?
  19. python批量读取图片处理并保存
  20. Android页面监听虚拟键盘弹出、收起

热门文章

  1. 【BZOJ2069】ZAW(POI2004)-最短路+二进制分组
  2. iOS 设置中清除缓存功能
  3. 富豪刑警 富豪刑警修斯库界面效果实现
  4. 超级好看又易上手教你用python画樱花
  5. 【IntelliJ IDEA】idea修改文件的file is read-only
  6. PostgreSQL表膨胀终结者
  7. 数据分析-思维分析逻辑day01
  8. 【Android 应用】小白之签名文件的生成。
  9. nvenc vs x264 对比(1)
  10. 正则表达式--教程一 简介(共三篇)