Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #download file from GCU with username and password, set output name and directory
- wget -O ~/Downloads/unsorted_files.zip --user=cmoyes200 --password=Bruno123 $4
- #create new directories
- mkdir ~/file_sorting
- mkdir ~/file_sorting/misc_files
- #unzip file and dump contents without creating a directory
- unzip -j ~/Downloads/unsorted_files.zip -d ~/file_sorting/misc_files
- #make new directories named after the arguments
- echo Creating directory - $1...
- mkdir ~/file_sorting/$1
- echo Creating directory - $2...
- mkdir ~/file_sorting/$2
- echo Creating directory - $3...
- mkdir ~/file_sorting/$3
- #move unsorted files into appropriate places using the arguments
- mv ~/file_sorting/misc_files/*$1 ~/file_sorting/$1
- mv ~/file_sorting/misc_files/*$2 ~/file_sorting/$2
- mv ~/file_sorting/misc_files/*$3 ~/file_sorting/$3
- #print size ordered lists of each directory. Changing directory to avoid the limitation of ls printing the full pathnames when direct referencing is used
- cd ~/file_sorting/$1
- ls -S *$1 > $1list.txt
- cd ~/file_sorting/$2
- ls -S *$2 > $2list.txt
- cd ~/file_sorting/$3
- ls -S *$3 > $3list.txt
- cd ~/file_sorting/misc_files
- ls -S > misclist.txt
- #print names of each file in reverse alphabetical order to dirlabels text file
- cd ~/file_sorting/$1
- echo ...These are the $1 files... > ~/file_sorting/dirlabels.txt
- ls | wc -l >> ~/file_sorting/dirlabels.txt
- ls -r *$1 >> ~/file_sorting/dirlabels.txt
- cd ~/file_sorting/$2
- echo ...These are the $2 files... >> ~/file_sorting/dirlabels.txt
- ls | wc -l >> ~/file_sorting/dirlabels.txt
- ls -r *$2 >> ~/file_sorting/dirlabels.txt
- cd ~/file_sorting/$3
- echo ...These are the $3 files... >> ~/file_sorting/dirlabels.txt
- ls | wc -l >> ~/file_sorting/dirlabels.txt
- ls -r *$3 >> ~/file_sorting/dirlabels.txt
- cd ~/file_sorting/misc_files
- echo ...These are the unsorted files... >> ~/file_sorting/dirlabels.txt
- ls | wc -l >> ~/file_sorting/dirlabels.txt
- ls -r >> ~/file_sorting/dirlabels.txt
- #return to home directory
- cd ~
- #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