Advertisement
dzocesrce

[OS] File backup

Jan 20th, 2024
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.74 KB | None | 0 0
  1. #!/bin/bash
  2. #check if there iz a backup subdirectory, and if there ain't make some
  3. if [ ! -d ./backup ]
  4. then
  5.     mkdir ./backup
  6. fi
  7. #get all tha filez from tha current directory
  8. FILES=`ls -l | grep ^- | awk '{print $9}'`
  9. for file in $FILES
  10. do
  11.     filename=`$file >> awk -F. '{print $1}'`
  12.     #firstly copy all the files from the current directory and paste them in the subdirectory
  13.     cp $file ./backup/$file
  14.     #secondly rename them or rather change their extension to .backup
  15.     mv ./backup/$file ./backup/${filename}.backup
  16. done
  17. touch modified.txt
  18. #so with the mtime command we can list all files/directories that have or have not been modified in the last x dayz
  19. echo "`find . -type f -mtime -1`" >> modified.txt
  20. cat modified.txt
  21.  
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement