Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #! /bin/csh
  2.  
  3. if ($#argv != 3) then
  4. echo "Wrong args count!"
  5. exit 1
  6. endif
  7. set dir1="`eval echo $1`"
  8. set dir2="`eval echo $2`"
  9. set n="$3"
  10.  
  11. if (! -d "$dir1") then
  12. echo "$dir1 is not a directory"
  13. exit 1
  14. endif
  15. echo
  16. if(`find "$dir1" -maxdepth 1 -type f | wc -l`< $n) then
  17. echo "$dir1 has less then $n files"
  18. exit 1
  19. endif
  20.  
  21. if (! -e "$dir2") then
  22. mkdir "$dir2"
  23. endif
  24.  
  25. if (! -d "$dir2") then
  26. echo "$dir2 is not a directory"
  27. exit 1
  28. endif
  29.  
  30. set minFiles = `find "$dir1" -maxdepth 1 -type f -printf '%s %p\n'| sort -n | head -$n | cut -d' ' -f2-`
  31.  
  32. set minFiles = `echo $minFiles | sed 's/ \//\n\//g'| sed 's/ /_SPACE_/g'`
  33.  
  34. foreach file ($minFiles)
  35. set temp = `echo "$file" | sed 's/_SPACE_/ /g'`
  36. mv "$temp" "$dir2"
  37. end
  38.  
  39. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement