Before participating in the CTF competition when the temporary write, there are a lot of shortcomings, but can be used, put it out to share to everyone, hope to help everyone.
Script one: Record the current directory situation
#!/bin/bash
function Getdir () {
for element in ' LS $ '
Do
Dirfile=$1 "/" $element
If [-D $dirfile]
Then
Getdir $dirfile
Else
#将目录结构和大小存为一个临时文件
Echo ' Du-ab $dirfile ' >>/t.txt
#echo $dirfile >>./dir.txt
Fi
Done
}
# Monitored Directories
Dir= "/root/yxy"
Getdir $DIR
function Getdir1 () {
for element in ' LS $ '
Do
Dir_or_file=$1 "/" $element
If [-D $dirfile]
Then
Getdir1 $dirfile
Else
#将目录结构和大小存为一个临时文件
Echo ' Du-ab $dirfile ' >/t1.txt
#echo $dirfile >>./dir.txt
Fi
Done
}
Dir= "/root/yxy"
Getdir1 $DIR
Echo ' diff./t.txt./t1.txt ' >> diff.txt
Rm./t1.txt
Script two: Compare the record of script one, restore the change directory or file
#!bin/bash
function Backup () {
#发生变化的文件, the full path under the backup directory
Backup_dir= "/backup/" ' Tail-n1./diff.txt | awk ' {print $4} ' | Cut-d/F 3-'
#想要恢复的目录, restore files to this directory
Backupfile= ' Cat./diff.txt | awk ' {print $4} ' | cut-d/-f-3 '
for element in ' LS $ '
Do
Dirfile=$1 "/" $element
If [-D $dirfile]
Then
Backup $dirfile
elif [[-F $backup _dir && $backup _dir! = $dirfile]]
Then
CP $backup _dir $backupfile
Else
#要删除的文件
dir= $DIR ' Tail-n1 diff.txt | Awk-f "/" ' {print '/' $NF} '
#这里不能用-r,diff.txt not at the same time, add-R will delete the entire directory
Rm-f $dir
Fi
Done
}
#监控目录
Dir= "/root/yxy"
Backup $DIR
CTF game Linux file monitoring and recovery shell