Advertisement
dzocesrce

[OS] Copy-Pasting Files

Jan 20th, 2024
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.09 KB | None | 0 0
  1. #!/bin/bash
  2. #check if the script is called with 2 arguments
  3. if [ $# -ne 2 ]
  4. then
  5.     echo "USAGE: `hostname $0` ./source_folder ./destination_folder"
  6.     exit 1
  7. fi
  8. #stick tha argument valuez
  9. FROM=$1
  10. TO=$2
  11. #check if a destination folder exists and if not create it
  12. #-p apparently means creating all the possible subfolders so its better if used
  13. if [ ! -d $TO ]
  14. then
  15.     mkdir -p $TO
  16. fi
  17. #get the files that start with a number, have an x amount of lower case letterz and have an .out extension
  18. files=`ls -l $FROM | awk '$1~/^-/ && $9~/^[0-9][a-z][a-z]*\.out$ {print $9}'`
  19. for file in $files
  20. do
  21.     #copy-paste every file from 1 place 2 anotha
  22.     cp ${FROM}${file} ${TO}${file}
  23. done
  24. #so in the next line we just calculate the summed suze of the pasted filez that we have execute permission on
  25. total_size=`ls -l $TO | awk '$10~/^[0-9][a-z][a-z]*\.out$ {print $0}' | grep ^-..x | awk 'BEGIN {total=0;} {total+=$5} END {print total;}'`
  26. #print on screen, 20 points in tha bag and cya lata aligata
  27. echo "Vkupnata golemina na kopiranite datoteki koi korisnikot moze da gi izvrsuva e $file_size"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement