linux学习第五周命令与文件权限

2019-07-30  本文已影响0人  亮仔_c1b5
  1. 上次内容回顾
    0.1 find 命令练习
    0.2 find 命令
    0.3 find命令及应用场景
  2. 今日内容
  3. 设置别名
    2.1 说明
    2.2 配置流程
  4. 权限配置
    3.1 权限计算:
    3.2 修改权限:
  5. 用户相关的配置文件
    4.1 用户相关文件
  6. Linux基础优化
    5.1 添加用户
    5.2 PS1
    5.3 关闭SeLinux
    5.4 关闭防火墙
    5.5 yum源
    5.6 Linux字符集
  7. 正则表达式
    6.1 常见必会特殊符号
    1 引号
  8. 重定向符号系列
    6.2 三剑客-grep
    6.3 正则表达式
    1.基础正则
  9. 扩展正则

1.find命令

参数 含义
-maxdepth 最大深度
-name 名字
-type 类型
-size 大小 10k 1M
-mtime 修改时间
-iname 查找的实际不区分大小写
-group
-user
-perm 权限
-a
-o
!

1.1find命令及应用场景

2.设置别名

2.1说明

2.2 配置流程

#linux系统别名 配置
rm == rm -i
[root@oldboy64-yl ~]# alias 
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias eth0='vim /etc/sysconfig/network-scripts/ifcfg-eth0'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
alias rm='echo command bny'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@oldboy64-yl ~]# 
alias 昵称=‘命令’
alias rm='rm -i'

[root@oldboy64-yl ~]# alias rm='echo command not found'
[root@oldboy64-yl ~]# rm
command not found
[root@oldboy64-yl ~]# rm oldboy01.txt 
command not found oldboy01.txt
[root@oldboy64-yl ~]# \rm oldboy01.txt 
[root@oldboy64-yl ~]# ll
total 180332
-rw-r--r--   1 root root 10223461 Jul 24 00:57 10.0.0.200_2019-07-24_etc.tar.gz
-rw-r--r--   1 root root       41 Jul 26 23:45 1.txt
-rw-r--r--   1 root root        9 Jul 26 19:27 2.txt

[root@oldboy64-yl ~]# tail -5 /etc/profile
unset -f pathmunge
alias rm='echo command bny'
export PS1="[\[\e[34;1m\]\u@\[\e[0m\]\[\e[32;1m\]\H\[\e[0m\] \[\e[31;1m\]\w\[\e[0m\]]\\$ "
alias net='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
alias eth0='vim /etc/sysconfig/network-scripts/ifcfg-eth0'
[root@oldboy64-yl ~]# source /etc/profile
[root@oldboy64-yl ~]# alias rm
alias rm='echo command bny'
[root@oldboy64-yl ~]# rm oldboy02.txt 
command bny oldboy02.txt
[root@oldboy64-yl ~]# 
[root@oldboy64-yl ~]# vim /root/.bashrc 

  1 # .bashrc
  2 
  3 # User specific aliases and functions
  4 
  5 #alias rm='rm -i'      #加上注释就行
  6 alias cp='cp -i'
  7 alias mv='mv -i'
  8 
  9 # Source global definitions
 10 if [ -f /etc/bashrc ]; then
 11         . /etc/bashrc
 12 fi

3. 权限配置

权限 数字 含义
r 4 可读
w 2 可写(修改)
x 1 execute(执行)命令或脚本
- 0 没有权限

3.1权限计算

[root@oldboy64-yl ~]# ll
total 180332
-rw-r--r--   1 root root 10223461 Jul 24 00:57 10.0.0.200_2019-07-24_etc.tar.gz
-rw-r--r--   1 root root       41 Jul 26 23:45 1.txt
-rw-r--r--   1 root root        9 Jul 26 19:27 2.txt
-       rw-         r--                 r--   1 root root  3580282 Jul 27 23:11 50万行日志access.zip
类型 所有者  所属用户组   其他人
        420        400              400
        6            4                  4
        644

3.2 修改权限:

[root@oldboy64-yl ~]# chmod 644 oldboy02.txt 
[root@oldboy64-yl ~]# ll oldboy02.txt 
-rw-r--r-- 1 root root 0 Jul 13 23:55 oldboy02.txt
[root@oldboy64-yl ~]# chmod 777 oldboy02.txt 
[root@oldboy64-yl ~]# ll oldboy02.txt 
-rwxrwxrwx 1 root root 0 Jul 13 23:55 oldboy02.txt
[root@oldboy64-yl ~]# 
u
g + | - |=
o
[root@oldboy64-yl ~]# chmod a+x oldboy02.txt
[root@oldboy64-yl ~]# chmod +x oldboy02.txt    #最常用
[root@oldboy64-yl ~]# chmod ugo+x oldboy02.txt 
[root@oldboy64-yl ~]# chmod u+x,g+x,o+x oldboy02.txt 
[root@oldboy64-yl ~]#
[root@oldboy64-yl ~]# ll oldboy02.txt 
-rwxrwxrwx 1 root root 0 Jul 13 23:55 oldboy02.txt
[root@oldboy64-yl ~]# chown oldboy.oldboy oldboy02.txt 
[root@oldboy64-yl ~]# ll oldboy02.txt 
-rwxrwxrwx 1 oldboy oldboy 0 Jul 13 23:55 oldboy02.txt
[root@oldboy64-yl ~]# 

4. 用户相关的配置文件

[root@oldboy64-yl ~]# which useradd adduser 
/sbin/useradd
/sbin/adduser
[root@oldboy64-yl ~]# ll `which useradd adduser`
lrwxrwxrwx. 1 root root      7 Jun 30 17:48 /sbin/adduser -> useradd
-rwxr-x---. 1 root root 118232 Oct 31  2018 /sbin/useradd
[root@oldboy64-yl ~]# 

4.1 用户相关文件

[root@oldboy64-yl ~]# head /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
[root@oldboy64-yl ~]# 
第1列 第2列 第3列 第4列 第5列 第6列 第7列
用户名 密码位 用户UID 用户GID 用户说明信息 用户家目录 用户使用的命令解释器(运行的命令谁替你执行)
root x 0 0 root /root /bin/bash
nobody x 99 99 Nobody / /sbin/nologin
oldboy x 1000 1000 /home/oldboy /bin/bash
[root@oldboy64-yl ~]# grep 'nobody' /etc/passwd
nobody:x:99:99:Nobody:/:/sbin/nologin
[root@oldboy64-yl ~]# su - oldboy 
Last login: Sun Jul 28 21:35:17 CST 2019 on pts/0
[oldboy@oldboy64-yl ~]$ su - nobody 
Password: 
su: Authentication failure
用户分类 UID 作用
root 0 皇帝
虚拟用户(傀儡用户) 1-999(C7)1-499(c6 c5) 让系统服务正常运行所需要的用户 无法登陆系统 判断:/sbin/nologin
普通用户 1000+(c7)500+(c6 c5) 普通用户

Linux基础优化

5.1添加用户

[root@oldboy64-yl ~]# useradd lidao
[root@oldboy64-yl ~]# su - lidao 
Last login: Sun Jul 28 12:35:45 CST 2019 on pts/0
[lidao@oldboy64-yl ~]$ 

su 与 su -
su - 是su命令的参数 - == -l == --login
切换用户的时候更新用户的环境变量

#通过普通用户启动服务
# 监牢模式(通过普通用户 运行 服务)
[root@oldboy64-yl ~]# su - oldboy -c whoami
oldboy

5.2 PS1

[root@oldboy64-yl ~]# export PS1='[\u@\h \W]\$'

5.3 关闭SeLinux

enforce selinux正在运行
permissive selinux关闭,会提示警告信息
disabled selinux彻底关闭
[root@oldboy64-yl oldboy]#ll /etc/sysconfig/selinux 
lrwxrwxrwx 1 root root 17 Jun 30 17:48 /etc/sysconfig/selinux -> ../selinux/config
[root@oldboy64-yl oldboy]#vim /etc/selinux/config

  1 
  2 # This file controls the state of SELinux on the system.
  3 # SELINUX= can take one of these three values:
  4 #     enforcing - SELinux security policy is enforced.
  5 #     permissive - SELinux prints warnings instead of enfo    rcing.
  6 #     disabled - No SELinux policy is loaded.
  7 SELINUX=disabled
  8 # SELINUXTYPE= can take one of three values:
  9 #     targeted - Targeted processes are protected,
 10 #     minimum - Modification of targeted policy. Only sele    cted processes are protected. 
 11 #     mls - Multi Level Security protection.
 12 SELINUXTYPE=targeted
 13 
 14 
~                                                             
~                                                             
"/etc/selinux/config" 14L, 542C             1,0-1         All
[root@oldboy64-lnb ~]# getenforce
Enforcing
[root@oldboy64-lnb ~]# setenforce
usage: setenforce [ Enforcing | Permissive | 1 | 0 ]
[root@oldboy64-lnb ~]# setenforce 0
[root@oldboy64-lnb ~]# getenforce
Permissive
[root@oldboy64-lnb ~]# grep 'disabled'
/etc/selinux/config
# disabled - No SELinux policy is loaded.
SELINUX=disabled
[root@oldboy64-lnb ~]# getenforce
Permissive

5.4 关闭防火墙

[root@oldboy64-lnb ~]# #检查
[root@oldboy64-lnb ~]# systemctl is-active
firewalld.service
active
[root@oldboy64-lnb ~]# #只要是active 就表示在运行中
[root@oldboy64-lnb ~]#
[root@oldboy64-lnb ~]# systemctl stop
firewalld.service
[root@oldboy64-lnb ~]#
[root@oldboy64-lnb ~]# systemctl is-active
firewalld.service
inactive

永久 - 让防火墙在开机不自启动

[root@oldboy64-lnb ~]# #检查开机自启动
[root@oldboy64-lnb ~]# systemctl is-enabled
firewalld.service
enabled
[root@oldboy64-lnb ~]# #enanbled 开机自启动
[root@oldboy64-lnb ~]# #systemctl enable/disable
firewalld
[root@oldboy64-lnb ~]# systemctl disable
firewalld.service
Removed symlink /etc/systemd/system/multiuser.
target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbusorg.
fedoraproject.FirewallD1.service.
[root@oldboy64-lnb ~]# systemctl is-enabled
firewalld.service
disabled
[root@oldboy64-yl ~]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled;    #开机不会自启动 vendor preset: enabled)
   Active: inactive (dead)   #当前已经关闭
     Docs: man:firewalld(1)
[root@oldboy64-yl ~]# systemctl start firewalld.service 
[root@oldboy64-yl ~]# systemctl status firewalld.service 
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-07-29 00:08:10 CST; 14s ago
     Docs: man:firewalld(1)
 Main PID: 53037 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─53037 /usr/bin/python -Es /usr/sbin/firewalld ...

Jul 29 00:08:09 oldboy64-yl systemd[1]: Starting firewalld ...
Jul 29 00:08:10 oldboy64-yl systemd[1]: Started firewalld -...
Hint: Some lines were ellipsized, use -l to show in full.
[root@oldboy64-yl ~]# 

5.5 yum源

[root@oldboy64-lnb ~]# ll /etc/yum.repos.d/
total 36
-rw-r--r--. 1 root root 2523 Jul 14 12:41 CentOSBase.
repo #√
-rw-r--r--. 1 root root 1309 Nov 23 2018 CentOSCR.
repo
-rw-r--r--. 1 root root 649 Nov 23 2018 CentOSDebuginfo.
repo
-rw-r--r--. 1 root root 314 Nov 23 2018 CentOSfasttrack.
repo
-rw-r--r--. 1 root root 630 Nov 23 2018 CentOSMedia.
repo
-rw-r--r--. 1 root root 1331 Nov 23 2018 CentOSSources.
repo
-rw-r--r--. 1 root root 5701 Nov 23 2018 CentOSVault.
repo
-rw-r--r--. 1 root root 664 Jul 14 12:50 epel.repo    #√
[root@oldboy64-yl ~]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1      #保留yum下载的rpm包
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
[root@oldboy64-yl ~]# echo $LANG 
en_US.UTF-8   #语言,字符集
[root@oldboy64-yl ~]# export LANG=zh_CN.UTF-8  #临时
[root@oldboy64-yl ~]# vim /etc/locale.conf   #永久

  1 LANG=en_US.UTF-8

[root@oldboy64-yl ~]# localectl set-locale LANG=zh_CN.UTF-8
Connection closed.

Disconnected from remote host(root) at 16:15:10.

Type `help' to learn how to use Xshell prompt.
[c:\~]$ 

Connecting to 10.0.0.200:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Last login: Tue Jul 30 15:57:08 2019 from 10.0.0.1
[root@oldboy64-yl ~]# echo $LANG 
en_US.UTF-8

[root@oldboy64-yl ~]# echo $LANG 
zh_CN.UTF-8
[root@oldboy64-yl ~]#

排查
检查Linux字符集
检查远程连接工具字符集
解决
修改字符集 统一

6. 正则表达式

6.1 常见必会特殊符号

1 引号

引号系列
单引号 所见即所得原封不动显示/输出
双引号 与单引号类似 会对特殊符号进行解析(运行)
不加引号 与双引号类似 支持{}*通配符
反引号 优先执行里面的命令
#加单引号
[root@oldboy64-yl ~]# echo 'oldboy $LANG $(hostname) `whoami`'
oldboy $LANG $(hostname) `whoami`
#加双引号
[root@oldboy64-yl ~]# echo "oldboy $LANG $(hostname) `whoami`" 
oldboy en_US.UTF-8 oldboy64-yl root
#不加引号
[root@oldboy64-yl ~]# echo oldboy $LANG $(hostname) `whoami` {1..5}
oldboy en_US.UTF-8 oldboy64-yl root 1 2 3 4 5
[root@oldboy64-yl ~]# 
[root@oldboy64-yl ~]# echo "oldboy $LANG $(hostname) `whoami` {1..5}"
oldboy en_US.UTF-8 oldboy64-yl root {1..5}
[root@oldboy64-yl ~]# echo 'oldboy $LANG $(hostname) `whoami` {1..5}'
oldboy $LANG $(hostname) `whoami` {1..5}
[root@oldboy64-yl ~]# 

2. 重定向符号系列

重定向符号系列
> 或 1> 重定向 先清空文件内容 然后再写入
>> 或 1>> 追加 内容追加到文件结尾
2> 错误输出重定向 记录错误提示
2>> 错误输出追加重定向 记录错误提示
2>&1 记录正确和错误输出
< 或 0< 输入重定向
<< 或 0<< 追加输入重定向
[root@oldboy64-yl ~]# echo oldboy >> oldboy.txt 2>&1
[root@oldboy64-yl ~]# cat oldboy.txt
oldboy
[root@oldboy64-yl ~]# eho oldboy >> oldboy.txt 2>&1
[root@oldboy64-yl ~]# cat oldboy.txt
oldboy
-bash: eho: command not found
[root@oldboy64-yl ~]# echo {1-9} |tr '123' 'abc'
{a-9}
[root@oldboy64-yl ~]# echo {1..9} |tr '123' 'abc'
a b c 4 5 6 7 8 9
[root@oldboy64-yl ~]# echo {1..9} |tr '1-3' 'a-c'
a b c 4 5 6 7 8 9
[root@oldboy64-yl ~]#为何使用管道?
[root@oldboy64-yl ~]# 一个命令解决不了问题
[root@oldboy64-yl ~]# echo {1..9} > num.txt
[root@oldboy64-yl ~]# cat num.txt
1 2 3 4 5 6 7 8 9
[root@oldboy64-yl ~]# tr '123' 'abc' < num.txt 
a b c 4 5 6 7 8 9
[root@oldboy64-yl ~]# 
[root@oldboy64-yl ~]# cat >>oldboy.txt<<EOF 
> sdf
> kjlkjlk
> llk
> EOF
[root@oldboy64-yl ~]# cat oldboy.txt
oldboy
-bash: eho: command not found
sdf
kjlkjlk
llk
[root@oldboy64-yl ~]# 
[root@oldboy64-yl ~]# cat >>oldboy.txt<<EOF
> $LANG
> $(hostname)
> EOF
[root@oldboy64-yl ~]# cat oldboy.txt
oldboy
-bash: eho: command not found
sdf
kjlkjlk
llk
en_US.UTF-8
oldboy64-yl
#追加多行 包含特殊符号
[root@oldboy64-yl ~]# cat >>oldboy.txt<<'EOF'   
$LANG
$(hostname)
EOF

[root@oldboy64-yl ~]# cat oldboy.txt
oldboy
-bash: eho: command not found
sdf
kjlkjlk
llk
en_US.UTF-8
oldboy64-yl
$LANG
$(hostname)
[root@oldboy64-yl ~]# 

6.2 三剑客-grep

grep
-v 排除
-w 精确过滤 按照单词进行匹配
-R 递归过滤 默认是当前目录及子目录下面进行查找
-l 只显示文件名 不显示内容
[root@oldboy64-yl /tmp]# grep 'oldboy' oldboy.txt 
oldboy64-yl
oldboy
oldboyoldboy
aoldboy
oldboyalex
oldboy.txt 
I am oldboy teacher!
my blog is http://oldboy.blog.51cto.com 
our size is http://blog.oldboyedu.com 
[root@oldboy64-yl /tmp]# grep 'oldboy' oldboy.txt -v
zh_CN.UTF-8
I teach linux.

I like badminton ball ,billiard ball and chinese chess!
my qq is 49000448

not 4900000448.
my god ,i am not oldbey,but OLDBOY!
地方
[root@oldboy64-yl /tmp]# 
[root@oldboy64-yl /tmp]# grep 'oldboy' oldboy.txt 
oldboy64-yl
oldboy
oldboyoldboy
aoldboy
oldboyalex
oldboy.txt 
I am oldboy teacher!
my blog is http://oldboy.blog.51cto.com 
our size is http://blog.oldboyedu.com 
[root@oldboy64-yl /tmp]# grep -Rl 'oldboy'
grep: test.txt.soft: No such file or directory
etc.soft/group-
etc.soft/group
etc.soft/gshadow-
etc.soft/gshadow
etc.soft/hosts

6.3 正则表达式

1.基础正则

基础正则表达式
^ 以……开头的行 ^oldboy
$ 以……结尾的行 m$
^$ 空行 ^$
. 任意一个字符
\ 转义字符 脱掉马甲 打回原形(去掉特殊含义)
* 前一个字符连续出现0次或0次以上 000 999999999
.* 所有.*
[] [abc] 匹配a或b或c 1次匹配1个字符
[] [^abc] 排除 不要a或不要b或不要c
[root@oldboy64-yl /tmp]# grep '^m' oldboy.txt 
my blog is http://oldboy.blog.51cto.com 
my qq is 49000448
my god ,i am not oldbey,but OLDBOY!
[root@oldboy64-yl /tmp]# 
[root@oldboy64-yl /tmp]# grep 'm $' oldboy.txt
my blog is http://oldboy.blog.51cto.com 
our size is http://blog.oldboyedu.com 
[root@oldboy64-yl /tmp]# cat -A oldboy.txt 
zh_CN.UTF-8$
oldboy64-yl$
oldboy$
oldboyoldboy$
aoldboy$
oldboyalex$
oldboy.txt $
I am oldboy teacher!$
I teach linux.$
$
I like badminton ball ,billiard ball and chinese chess!$
my blog is http://oldboy.blog.51cto.com $
our size is http://blog.oldboyedu.com $
my qq is 49000448$
$
not 4900000448.$
my god ,i am not oldbey,but OLDBOY!$
M-eM-^\M-0M-fM-^VM-9$
[root@oldboy64-yl /tmp]# grep -n '^$' oldboy.txt 
10:
15:
[root@oldboy64-yl /tmp]# cat -n oldboy.txt 
     1  zh_CN.UTF-8
     2  oldboy64-yl
     3  oldboy
     4  oldboyoldboy
     5  aoldboy
     6  oldboyalex
     7  oldboy.txt 
     8  I am oldboy teacher!
     9  I teach linux.
    10  
    11  I like badminton ball ,billiard ball and chinese chess!
    12  my blog is http://oldboy.blog.51cto.com 
    13  our size is http://blog.oldboyedu.com 
    14  my qq is 49000448
    15  
    16  not 4900000448.
    17  my god ,i am not oldbey,but OLDBOY!
    18  地方
[root@oldboy64-yl /tmp]# 
[root@oldboy64-yl /tmp]# grep '.' oldboy.txt
zh_CN.UTF-8
oldboy64-yl
oldboy
oldboyoldboy
aoldboy
oldboyalex
oldboy.txt 
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com 
our size is http://blog.oldboyedu.com 
my qq is 49000448
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
地方
[root@oldboy64-yl /tmp]# grep '.' oldboy.txt -o
z
h
_
C
N
.
U
[root@oldboy64-yl /tmp]# tr '\n' '\t' < oldboy.txt
zh_CN.UTF-8 oldboy64-yl oldboy  oldboyoldboy    aoldboy oldboyalex  oldboy.txt  I am oldboy teacher! I teach linux.     I like badminton ball ,billiard ball and chinese chess! my blog is http://oldboy.blog.51cto.com     our size is http://blog.oldboyedu.com   my qq is 49000448       not 4900000448. my god ,i am not oldbey,but OLDBOY! 地方  [root@oldboy64-yl /tmp]# 

贪婪性:正则表示所有的时候(.*) 或表示连续出现 能吃多少就吃多少(贪婪性)

'[a-z]'
[A-Z]
[a-Z]==[a-zA-Z]
[0-9]
[0-Z]

[root@oldboy64-yl /tmp]# grep -v '^$' oldboy.txt 
zh_CN.UTF-8
oldboy64-yl
oldboy
oldboyoldboy
aoldboy
oldboyalex
oldboy.txt 
I am oldboy teacher!
I teach linux.
I like badminton ball ,billiard ball and chinese chess!
my blog is http://oldboy.blog.51cto.com 
our size is http://blog.oldboyedu.com 
my qq is 49000448
not 4900000448.
my god ,i am not oldbey,but OLDBOY!
地方
[root@oldboy64-yl /tmp]# 

2.扩展正则

符号
+ 前一个字符连续出现1次及一次以上 一般+与[]一起使用
| 或者
{} a{n,m}前一个字符a连续出现至少n次,最多m次
a{n}前一个字符a连续出现n次
a{n,}
a{,m}
() 整体 或 后向引用(sed)
? 前一个字符连续出现0次或一次
image.png

连续出现
5555555555
7777777777
现在连续出现
oldboy
57934579
kslfjsl

[root@oldboy64-yl /tmp]# egrep 'oldboy|blog' oldboy.txt 
oldboy64-yl
oldboy
oldboyoldboy
aoldboy
oldboyalex
oldboy.txt 
I am oldboy teacher!
my blog is http://oldboy.blog.51cto.com 
our size is http://blog.oldboyedu.com 

7.作业

1.写出查询file.txt以abc结尾的行

[root@oldboy64-yl /tmp]# grep 'abc$' file.txt 

2.删除file.txt文件中的空行

[root@oldboy64-yl /tmp]# grep '^$' file.txt -n
9:
10:
11:
[root@oldboy64-yl /tmp]# 

3.查找最后创建时间是3天前,后缀是*.log的文件并删除(三种方法)

[root@oldboy64-yl /tmp]# find /oldboy/ -type f -name "*.log" -mtime +3|xargs rm -f
[root@oldboy64-yl /tmp]# find /oldboy/ -type f -name "*.log" -mtime +3 -exec rm -f {} \;
[root@oldboy64-yl /tmp]# \rm -f `find /oldboy/ -type f -name "*.log" -mtime +3`

4.删除/etc/fstab文件中所有以#开头的行的行首的# 号及#后面的所有空白字符;

[root@oldboy64-yl /tmp]# sed -r 's@^#[ \t]+@@g' /etc/fstab 

#
/etc/fstab
Created by anaconda on Sun Jun 30 17:47:28 2019
#
Accessible filesystems, by reference, are maintained under '/dev/disk'
See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=47ec2d05-84dd-4131-86ec-426c706e9c01 /                       xfs     defaults        0 0
UUID=daff218d-4ecc-484c-a479-efabd96c0467 /boot                   xfs     defaults        0 0
UUID=f8a73e41-694e-4e02-bbb0-3dbc06d90f25 swap                    swap    defaults        0 0
/dev/sda3 /data xfs defaults 0 0
[root@oldboy64-yl /tmp]# 

5.在/var/sync/log/cef_watchd-20080424.1og文件中查找大小写不敏感“mysql"字符串中的命令是

[root@oldboy64-yl /tmp]# find /var/sync/log/cef_watchd-20080424.log -type f -iname 'mysql'

6.为了在/var/sync/log 目录中查找更改时间在5日以前的文件井删除它们,linux命令是

[root@oldboy64-yl /tmp]# find /var/sync/log -type f -mtime +5 |xargs rm -f

7.把data目录及其子目录下所有以扩展名.txt结尾的文件中包含oldgirl的字符串全部替换为oldboy.

[root@oldboy64-yl /tmp]# find /data/ -type f -name '*.txt' |xargs sed 's#oldgirl#oldboy#g'

8.有文件file1

[root@oldboy64-yl /tmp]# grep -n '^$' file1.txt 
9:
10:
11:
[root@oldboy64-yl /tmp]# grep  'abc$' file1.txt 
[root@oldboy64-yl /tmp]# head -3 file1.txt 
oldboy
oldboy
alex

9.当前系统中没有任何文本编辑器(vi,emacs,vim,edit等),如何过来掉注释行和空行查看/etc/ssh/sshd_config文件

[root@oldboy64-yl /tmp]# egrep -vn '^#|^$' /etc/ssh/sshd_config 

剩余题目 https://www.jianshu.com/p/61d8883719ac

上一篇下一篇

猜你喜欢

热点阅读