bash - creating a unix script to sort and process files -
situation:
i have folder on desktop named unsorted_files contains approximately 1gb of varying file types (jpg,gif,docx,png, wav,mid,csv) etc etc.
in addition this, have 3 further directories on desktop hold dedicated filetype (jpg,gif,docx).
the actual directory names these dedicated directories are:
jpgdirectory gifdirectory docxdirectory
problem:
i create bash script can run through terminal on mac os 10.10.5 separate , process these files types unsorted_files folder , place them newly created directories dependant on file type.
ie. jpg files in folder unsorted_files upon execution of script sent jpgdirectory , gif files dispatched gifdirectory
the 1 caveat is, file types out (jpgdirectory, gifdirectory, docxdirectory) must sent miscellaneous
how achieve objective bash script perspective or perhaps can done using solely terminal commands.
to automate mkdir , mv command in bash, put 'for' loop 1 below.
code:
#!/bin/bash unsorted_path="/path/to/unsorted/dir" output_path="/path/to/output/dirs" type in $(cat filetypes.txt) mkdir -p ${output_path}/${type}directory mv ${unsorted_path}/*.${type} ${output_path}/${type}directory/ done
the 'filetypes.txt' file list of file types, 1 per line such as:
jpg gif docx png wav mid csv
you hardcode file types i.e.
#!/bin/bash unsorted_path="/path/to/unsorted/dir" output_path="/path/to/output/dirs" type in jpg gif docx png wav mid csv mkdir -p ${output_path}/${type}directory mv ${unsorted_path}/*.${type} ${output_path}/${type}directory/ done
hope helps!
Comments
Post a Comment