[root@localhost ~]# find / -name "nn"
/var/spool/mail/nn
/usr/share/locale/nn
/home/nn
[root@localhost ~]# find / -name "nn" -type f
/var/spool/mail/nn
[root@localhost ~]# ls /opt/
[root@localhost ~]# find / -name "nn*" -type f
/sys/fs/selinux/policy_capabilities/nnp_nosuid_transition
/sys/fs/selinux/class/process2/perms/nnp_transition
/var/spool/mail/nn
/usr/lib64/python2.7/nntplib.py
/usr/lib64/python2.7/nntplib.pyc
/usr/lib64/python2.7/nntplib.pyo
/usr/share/i18n/locales/nn_NO
[root@localhost ~]# ls -l /etc/*.conf
[root@localhost ~]# find / -name "*http*" -type f
[root@localhost ~]# rm -rf ./opt/*
[root@localhost ~]# ls /opt/
[root@localhost ~]# touch a.txt
[root@localhost ~]# pwd
/root
[root@localhost ~]# rm -rf a.txt
[root@localhost ~]# touch /opt/a.txt
[root@localhost ~]# stat /opt/a.txt
文件:"/opt/a.txt"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:34049772 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-15 09:33:03.149654707 +0800
最近更改:2024-07-15 09:33:03.149654707 +0800
最近改动:2024-07-15 09:33:03.149654707 +0800
创建时间:-
[root@localhost ~]# touch /opt/b.txt -m -d "2024-7-14 00:00"
[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root 0 7月 15 09:33 a.txt
-rw-r--r--. 1 root root 0 7月 14 00:00 b.txt
[root@localhost ~]#
Touch创建文件,没有文件就新建,有文件就修改
[root@localhost ~]# touch /opt/c.txt -m -d "2024-7-13 00:00"
[root@localhost ~]# touch /opt/d.txt -m -d "2024-7-12 00:00"
[root@localhost ~]# touch /opt/e.txt -m -d "2024-7-11 00:00"
[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root 0 7月 15 09:33 a.txt
-rw-r--r--. 1 root root 0 7月 14 00:00 b.txt
-rw-r--r--. 1 root root 0 7月 13 00:00 c.txt
-rw-r--r--. 1 root root 0 7月 12 00:00 d.txt
-rw-r--r--. 1 root root 0 7月 11 00:00 e.txt
[root@localhost ~]# touch /opt/f.txt
[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root 0 7月 15 09:33 a.txt
-rw-r--r--. 1 root root 0 7月 14 00:00 b.txt
-rw-r--r--. 1 root root 0 7月 13 00:00 c.txt
-rw-r--r--. 1 root root 0 7月 12 00:00 d.txt
-rw-r--r--. 1 root root 0 7月 11 00:00 e.txt
-rw-r--r--. 1 root root 0 7月 15 09:38 f.txt
[root@localhost ~]# touch /opt/f.txt -m -d "2024-7-10 00:00"
[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root 0 7月 15 09:33 a.txt
-rw-r--r--. 1 root root 0 7月 14 00:00 b.txt
-rw-r--r--. 1 root root 0 7月 13 00:00 c.txt
-rw-r--r--. 1 root root 0 7月 12 00:00 d.txt
-rw-r--r--. 1 root root 0 7月 11 00:00 e.txt
-rw-r--r--. 1 root root 0 7月 10 00:00 f.txt
Touch 文件名称 -m -d “日期时间格式”
使用find按时间搜索,找到旧的文件删掉
[root@localhost ~]# find /opt/ -mtime +3
/opt/e.txt
/opt/f.txt
[root@localhost ~]# find /opt/ -mtime -3
/opt/
/opt/a.txt
/opt/b.txt
/opt/c.txt
[root@localhost ~]# ls /opt/
a.txt b.txt c.txt d.txt e.txt f.txt
[root@localhost ~]# ls /opt/ -a
[root@localhost ~]# find /opt/ -mtime +3|xargs rm -rf
[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root 0 7月 15 09:33 a.txt
-rw-r--r--. 1 root root 0 7月 14 00:00 b.txt
-rw-r--r--. 1 root root 0 7月 13 00:00 c.txt
-rw-r--r--. 1 root root 0 7月 12 00:00 d.txt
Find -exec 对查找到的结果进行修改
[root@localhost ~]# touch /opt/e.txt -m -d "2024-7-11 00:00"
[root@localhost ~]# touch /opt/f.txt -m -d "2024-7-10 00:00"
[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root 0 7月 15 09:33 a.txt
-rw-r--r--. 1 root root 0 7月 14 00:00 b.txt
-rw-r--r--. 1 root root 0 7月 13 00:00 c.txt
-rw-r--r--. 1 root root 0 7月 12 00:00 d.txt
-rw-r--r--. 1 root root 0 7月 11 00:00 e.txt
-rw-r--r--. 1 root root 0 7月 10 00:00 f.txt
[root@localhost ~]# find /opt/ -mtime +3 -exec rm -rf {} \;
[root@localhost ~]# ls -l /opt/
总用量 0
-rw-r--r--. 1 root root 0 7月 15 09:33 a.txt
-rw-r--r--. 1 root root 0 7月 14 00:00 b.txt
-rw-r--r--. 1 root root 0 7月 13 00:00 c.txt
-rw-r--r--. 1 root root 0 7月 12 00:00 d.txt
[root@localhost ~]# ls -l /opt/ > a.txt
[root@localhost ~]# vi a.txt
[root@localhost ~]# ls -l ./ > a.txt
[root@localhost ~]# vi a.txt
[root@localhost ~]# ls -l /opt/ >> a.txt
[root@localhost ~]# vi a.txt
下载
下载文件
下载目录
下载文件
[root@localhost ~]# scp root@192.168.1.22:/opt/a.txt /opt/
The authenticity of host '192.168.1.22 (192.168.1.22)' can't be established.
ECDSA key fingerprint is SHA256:4N5F9+Cg5aYSBRzBSXR4ZPSX/6LHuB6KC0WUzGs1WNI.
ECDSA key fingerprint is MD5:d9:62:00:ef:1b:99:0c:6b:7d:17:ef:ea:89:d0:58:7e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.22' (ECDSA) to the list of known hosts.
root@192.168.1.22's password:
a.txt 100% 0 0.0KB/s 00:00
[root@localhost ~]# scp root@192.168.1.22:/opt/a.txt /opt/
root@192.168.1.22's password:
a.txt 100% 0 0.0KB/s 00:00
[root@localhost ~]# ls /opt/
- txt b.txt c.txt d.txt
[root@localhost ~]# mkdir /opt/d0
[root@localhost ~]# cp /opt/a.txt /opt/d0/
[root@localhost ~]# cp /opt/b.txt /opt/d0/
[root@localhost ~]# cp /opt/c.txt /opt/d0/
[root@localhost ~]# tree /opt/
[root@localhost ~]# ls /opt/
[root@localhost ~]# ls /opt/d0/
[root@localhost ~]# ls /opt/ -R
[root@localhost ~]# cp /opt/d0/ ./
cp: 略过目录"/opt/d0/"
[root@localhost ~]# cp -r /opt/d0/ ./
[root@localhost ~]# rm -rf /opt/*
[root@localhost ~]# tree /opt/
下载 把数据从远程主机保存到本地主机
上传 把本地文件保存到远程主机
计划任务
查看是否存在计划任务
[root@localhost ~]# cronrab -l
[root@localhost ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
每分钟自动将opt目录中的文件名写到root目录下的list中
[root@localhost ~]# dd if=/dev/zero of=/opt/hhhhh.txt bs=100M count=1
记录了1+0 的读入
记录了1+0 的写出
104857600字节(105 MB)已复制,1.02438 秒,102 MB/秒
[root@localhost ~]# vi list
[root@localhost ~]# dd if=/dev/zero of=/opt/zzzzzzzz.txt bs=100M count=1
记录了1+0 的读入
记录了1+0 的写出
104857600字节(105 MB)已复制,0.687205 秒,153 MB/秒
[root@localhost ~]# touch /opt/aaa.txt -m -d "2024-7-10 09:00"
[root@localhost ~]# stat /opt/aaa.txt
文件:"/opt/aaa.txt"
大小:0 块:0 IO 块:4096 普通空文件
设备:fd00h/64768d Inode:34049774 硬链接:1
权限:(0644/-rw-r--r--) Uid:( 0/ root) Gid:( 0/ root)
环境:unconfined_u:object_r:usr_t:s0
最近访问:2024-07-15 14:10:12.126510367 +0800
最近更改:2024-07-10 09:00:00.000000000 +0800
最近改动:2024-07-15 14:10:12.126510367 +0800
创建时间:-
[root@localhost ~]# find /opt/ -mtime +3
/opt/aaa.txt
[root@localhost ~]# find /opt/ -mtime +3 -exec rm -rf {} \;
[root@localhost ~]# ls /opt/
[root@localhost ~]# find /opt/ -mtime +3 |xargs rm -rf
[root@localhost ~]# dd id=/dev/zero of=/opt/aaa.mp4 bs=5M count=1
[root@localhost ~]# find /opt/ -size +2M
[root@localhost ~]# find /opt/ -size +2M -exec rm -rf {} \;
[root@localhost ~]# find /opt/ -size +2M
练习:
#练习1
[root@localhost ~]# ls -la /etc/
总用量 1060
drwxr-xr-x. 76 root root 8192 7月 15 10:49 .
dr-xr-xr-x. 17 root root 224 7月 12 23:12 ..
-rw-r--r--. 1 root root 16 7月 12 23:12 adjtime
-rw-r--r--. 1 root root 1518 6月 7 2013 aliases
-rw-r--r--. 1 root root 12288 7月 12 23:14 aliases.db
drwxr-xr-x. 2 root root 236 7月 12 23:09 alternatives
-rw-------. 1 root root 541 4月 11 2018 anacrontab
-rw-r--r--. 1 root root 55 4月 11 2018 asound.conf
drwxr-x---. 3 root root 43 7月 12 23:09 audisp
drwxr-x---. 3 root root 83 7月 12 23:14 audit
drwxr-xr-x. 2 root root 22 7月 12 23:09 bash_completion.d
-rw-r--r--. 1 root root 2853 4月 11 2018 bashrc
drwxr-xr-x. 2 root root 6 4月 11 2018 binfmt.d
-rw-r--r--. 1 root root 38 4月 29 2018 centos-release
-rw-r--r--. 1 root root 51 4月 29 2018 centos-release-upstream
drwxr-xr-x. 2 root root 6 8月 4 2017 chkconfig.d
-rw-r--r--. 1 root root 1108 4月 13 2018 chrony.conf
-rw-r-----. 1 root chrony 481 9月 15 2017 chrony.keys
drwxr-xr-x. 2 root root 21 7月 12 23:09 cron.d
#练习2
[root@localhost ~]# ls -ld /etc/*a* /etc/a*
-rw-r--r--. 1 root root 16 7月 12 23:12 /etc/adjtime
-rw-r--r--. 1 root root 16 7月 12 23:12 /etc/adjtime
-rw-r--r--. 1 root root 1518 6月 7 2013 /etc/aliases
-rw-r--r--. 1 root root 1518 6月 7 2013 /etc/aliases
-rw-r--r--. 1 root root 12288 7月 12 23:14 /etc/aliases.db
-rw-r--r--. 1 root root 12288 7月 12 23:14 /etc/aliases.db
drwxr-xr-x. 2 root root 236 7月 12 23:09 /etc/alternatives
drwxr-xr-x. 2 root root 236 7月 12 23:09 /etc/alternatives
-rw-------. 1 root root 541 4月 11 2018 /etc/anacrontab
-rw-------. 1 root root 541 4月 11 2018 /etc/anacrontab
-rw-r--r--. 1 root root 55 4月 11 2018 /etc/asound.conf
-rw-r--r--. 1 root root 55 4月 11 2018 /etc/asound.conf
drwxr-x---. 3 root root 43 7月 12 23:09 /etc/audisp
drwxr-x---. 3 root root 43 7月 12 23:09 /etc/audisp
drwxr-x---. 3 root root 83 7月 12 23:14 /etc/audit
drwxr-x---. 3 root root 83 7月 12 23:14 /etc/audit
drwxr-xr-x. 2 root root 22 7月 12 23:09 /etc/bash_completion.d
-rw-r--r--. 1 root root 2853 4月 11 2018 /etc/bashrc
-rw-r--r--. 1 root root 38 4月 29 2018 /etc/centos-release
#练习3
[root@localhost ~]# ls -l /etc/*.conf
-rw-r--r--. 1 root root 55 4月 11 2018 /etc/asound.conf
-rw-r--r--. 1 root root 1108 4月 13 2018 /etc/chrony.conf
-rw-r--r--. 1 root root 1285 4月 11 2018 /etc/dracut.conf
-rw-r--r--. 1 root root 112 4月 11 2018 /etc/e2fsck.conf
-rw-r--r--. 1 root root 38 4月 11 2018 /etc/fuse.conf
-rw-r--r--. 1 root root 842 11月 6 2016 /etc/GeoIP.conf
-rw-r--r--. 1 root root 9 6月 7 2013 /etc/host.conf
-rw-r--r--. 1 root root 7265 7月 12 23:09 /etc/kdump.conf
-rw-r--r--. 1 root root 590 4月 11 2018 /etc/krb5.conf
-rw-r--r--. 1 root root 28 2月 28 2013 /etc/ld.so.conf
-rw-r-----. 1 root root 191 10月 12 2017 /etc/libaudit.conf
-rw-r--r--. 1 root root 2391 10月 13 2013 /etc/libuser.conf
-rw-r--r--. 1 root root 19 7月 12 23:12 /etc/locale.conf
-rw-r--r--. 1 root root 662 7月 31 2013 /etc/logrotate.conf
-rw-r--r--. 1 root root 5171 6月 10 2014 /etc/man_db.conf
-rw-r--r--. 1 root root 936 4月 11 2018 /etc/mke2fs.conf
-rw-r--r--. 1 root root 1746 7月 12 23:09 /etc/nsswitch.conf
-rw-r--r--. 1 root root 72 7月 15 10:49 /etc/resolv.conf
-rw-r--r--. 1 root root 3232 4月 11 2018 /etc/rsyslog.conf
-rw-r--r--. 1 root root 216 4月 12 2018 /etc/sestatus.conf
-rw-r-----. 1 root root 1786 4月 11 2018 /etc/sudo.conf
#练习4
[root@localhost ~]# ls -l /etc/y*
-rw-r--r--. 1 root root 970 4月 13 2018 /etc/yum.conf
/etc/yum:
总用量 4
drwxr-xr-x. 2 root root 6 4月 13 2018 fssnap.d
drwxr-xr-x. 2 root root 54 7月 12 23:12 pluginconf.d
drwxr-xr-x. 2 root root 26 4月 13 2018 protected.d
drwxr-xr-x. 2 root root 37 4月 13 2018 vars
-rw-r--r--. 1 root root 444 4月 13 2018 version-groups.conf
/etc/yum.repos.d:
总用量 4
-rw-r--r--. 1 root root 69 7月 12 15:17 trow.repo
#练习5
[root@localhost ~]# find /var/ -type f -name "*.log"
/var/log/tuned/tuned.log
/var/log/audit/audit.log
/var/log/anaconda/anaconda.log
/var/log/anaconda/X.log
/var/log/anaconda/program.log
/var/log/anaconda/packaging.log
/var/log/anaconda/storage.log
/var/log/anaconda/ifcfg.log
/var/log/anaconda/ks-script-QzDmqg.log
/var/log/anaconda/ks-script-aPpej_.log
/var/log/anaconda/journal.log
/var/log/boot.log
/var/log/vmware-vmsvc.log
/var/log/yum.log
#练习6
[root@localhost ~]# sudo mkdir /opt/test
#练习7
[root@localhost ~]# cd /opt/test
[root@localhost test]# touch abc.txt def.txt ghi.txt xxx.txt yyy.txt
#练习8
[root@localhost test]# touch -d "2024-7-15" abc.txt
[root@localhost test]# touch -d "2024-7-14" def.txt
[root@localhost test]# touch -d "2024-7-13" ghi.txt
[root@localhost test]# touch -d "2024-7-12" xxx.txt
[root@localhost test]# touch -d "2024-7-11" yyy.txt
#练习9
[root@localhost test]# mkdir a
#练习10
[root@localhost test]# cp abc.txt def.txt ghi.txt xxx.txt yyy.txt a/
[root@localhost test]# ls a/
abc.txt def.txt ghi.txt xxx.txt yyy.txt
#练习11
[root@localhost test]# tar -czvf ~/bak.tar.gz /opt/test/a
tar: 从成员名中删除开头的“/”
/opt/test/a/
/opt/test/a/abc.txt
/opt/test/a/def.txt
/opt/test/a/ghi.txt
/opt/test/a/xxx.txt
/opt/test/a/yyy.txt
#练习12
[root@localhost test]# find /opt/test -type f -mtime +3 -exec rm -f {} \;
#练习13
[root@localhost test]# find /opt -type f -mtime -3 -exec rm -f {} \;
#练习14
[root@localhost test]# find /opt -type f -mtime 3 -exec rm -f {} \;
#练习15
[root@localhost ~]# cp /opt/test/a/* /opt/test/
#练习16
[root@localhost ~]# mkdir /opt/test0
#练习17
[root@localhost ~]# mkdir /opt/test0
[root@localhost ~]# cd /opt/test0/
[root@localhost test0]# fallocate -l 5M a.mp4
[root@localhost test0]# fallocate -l 20M b.mp4
[root@localhost test0]# fallocate -l 80M c.mp4
#练习18
[root@localhost test0]# mkdir /opt/test0/b/
#练习19
[root@localhost test0]# cp /opt/test0/* /opt/test0/b/
cp: 略过目录"/opt/test0/b"
#练习20
[root@localhost test0]# find /opt/test0/ -type f -size +20M
/opt/test0/c.mp4
/opt/test0/b/c.mp4
[root@localhost test0]# find /opt/test0/ -type f -size +20M -delete
#练习21
[root@localhost test0]# find /opt/test0/ -type f -size -20M
/opt/test0/a.mp4
/opt/test0/b/a.mp4
[root@localhost test0]# find /opt/test0/ -type f -size -20M -delete
#练习22
[root@localhost test0]# find /opt/test0/ -type f -size 20M -exec rm -f {} +
#练习23
[root@localhost test0]# cp -r /opt/test0/b/ /opt/test0/
#练习24
WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Mon Jul 15 16:10:04 2024
[root@localhost ~]#
#练习25
[root@localhost ~]# scp ~/bak.tar.gz nn@192.168.1.23:/opt/
The authenticity of host '192.168.1.23 (192.168.1.23)' can't be established.
ECDSA key fingerprint is SHA256:4N5F9+Cg5aYSBRzBSXR4ZPSX/6LHuB6KC0WUzGs1WNI.
ECDSA key fingerprint is MD5:d9:62:00:ef:1b:99:0c:6b:7d:17:ef:ea:89:d0:58:7e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.23' (ECDSA) to the list of known hosts.
nn@192.168.1.23's password:
scp: /opt//bak.tar.gz: Permission denied
#练习26
[root@localhost ~]#scp -r nn@192.168.1.22:/etc/skel/ /opt/skel_from_newhost/
nn@192.168.1.22's password:
.bash_logout 100% 18 14.7KB/s 00:00
.bash_profile 100% 193 216.6KB/s 00:00
.bashrc 100% 231 281.8KB/s 00:00
#练习27
#!/bin/bash
TIMESTAMP=$(date +%Y%m%d%H%M%S)
tar -czvf /tmp/yum_repos_${TIMESTAMP}.tar.gz /etc/yum.repos.d/*.repo
echo "Yum repositories have been compressed and saved to /tmp/yum_repos_${TIMESTAMP}.tar.gz"
[root@localhost ~]# chmod +x /usr/local/bin/compress_repos.sh
0 1 * * 3 /usr/local/bin/compress_repos.sh