Advertisement
Guest User

Untitled

a guest
Nov 11th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. #download file from GCU with username and password, set output name and directory
  2. wget -O ~/Downloads/unsorted_files.zip --user=cmoyes200 --password=Bruno123 $4
  3. #create new directories
  4. mkdir ~/file_sorting
  5. mkdir ~/file_sorting/misc_files
  6.  
  7. #unzip file and dump contents without creating a directory
  8. unzip -j ~/Downloads/unsorted_files.zip -d ~/file_sorting/misc_files
  9.  
  10. #make new directories named after the arguments
  11. echo Creating directory - $1...
  12. mkdir ~/file_sorting/$1
  13. echo Creating directory - $2...
  14. mkdir ~/file_sorting/$2
  15. echo Creating directory - $3...
  16. mkdir ~/file_sorting/$3
  17.  
  18. #move unsorted files into appropriate places using the arguments
  19. mv ~/file_sorting/misc_files/*$1 ~/file_sorting/$1
  20. mv ~/file_sorting/misc_files/*$2 ~/file_sorting/$2
  21. mv ~/file_sorting/misc_files/*$3 ~/file_sorting/$3
  22.  
  23. #print size ordered lists of each directory. Changing directory to avoid the limitation of ls printing the full pathnames when direct referencing is used
  24. cd ~/file_sorting/$1
  25. ls -S *$1 > $1list.txt
  26. cd ~/file_sorting/$2
  27. ls -S *$2 > $2list.txt
  28. cd ~/file_sorting/$3
  29. ls -S *$3 > $3list.txt
  30. cd ~/file_sorting/misc_files
  31. ls -S > misclist.txt
  32.  
  33. #print names of each file in reverse alphabetical order to dirlabels text file
  34. cd ~/file_sorting/$1
  35. echo ...These are the $1 files... > ~/file_sorting/dirlabels.txt
  36. ls | wc -l >> ~/file_sorting/dirlabels.txt
  37. ls -r *$1 >> ~/file_sorting/dirlabels.txt
  38. cd ~/file_sorting/$2
  39. echo ...These are the $2 files... >> ~/file_sorting/dirlabels.txt
  40. ls | wc -l >> ~/file_sorting/dirlabels.txt
  41. ls -r *$2 >> ~/file_sorting/dirlabels.txt
  42. cd ~/file_sorting/$3
  43. echo ...These are the $3 files... >> ~/file_sorting/dirlabels.txt
  44. ls | wc -l >> ~/file_sorting/dirlabels.txt
  45. ls -r *$3 >> ~/file_sorting/dirlabels.txt
  46. cd ~/file_sorting/misc_files
  47. echo ...These are the unsorted files... >> ~/file_sorting/dirlabels.txt
  48. ls | wc -l >> ~/file_sorting/dirlabels.txt
  49. ls -r >> ~/file_sorting/dirlabels.txt
  50.  
  51. #return to home directory
  52. cd ~
  53.  
  54. #In the future I would try to utilise looping commands rather than trying to repeat each line 3 or 4 times for each directory. I feel like the method can also be clumsy because of the need for repeated directory changes, however I was unable to work around ls outputting the full paths instead of just file names whenever used with direct referencing outside of the directory. The lack of loops prevented me from completing extension 2 as I'm unable to easily adapt the script to more arguments. My list files display the number of files +1. I couldn't figure out how to discount the actual list file itself from the count, nor could I format the result in a more explanatory way than simply a number. I made use of the wget command to download the zip file from gcu, as well as login with a username and password as well as output the file to a specific path with a specific name.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement