Bash Script to sort video files to correct folders
I have a little Bash script set up to find video files then move them to a certain folder depending on size. It works fine. An extract of the script I used is below:
Code:
find /home/tim/readynas/Tim/Download/Downloaded/ -type f \( -iname \*.mkv -o -iname \*.avi -o -iname \*.wmv -o -iname \*.mp4 -o -iname \*.m4v \) -size +2G -exec mv -f {} /home/tim/readynas/Videos/Longform/ \; If file ends in .mkv or .mp4 or .avi then If file larger than 2 gig then move to long If file smaller than 2 gig then move to short However I'm unsure how this would look in a script. Can I do something like: Code:
if /home/tim/readynas/Tim/Download/Downloaded/ -type f \( -iname \*.mkv -o -iname \*.avi -o -iname \*.wmv -o -iname \*.mp4 -o -iname \*.m4v \) then Regards Tim |
Code:
for i in $(find /home/tim/readynas/Tim/Download/Downloaded/ -type f \( -iname \*.mkv -o -iname \*.avi -o -iname \*.wmv -o -iname \*.mp4 -o -iname \*.m4v \); do |
Quote:
Does the first line create a string called 'i' that contains all files ending with desired extension? The next line then lists 'i' then pipes to list again? Whats the print $5 do? Sorry, I'm pretty new to Bash Cheers |
It could be more elegant visually (?) but not efficiently wise than using 2 lines of find command maybe with xargs to move all found filenames in one go (for each line)
|
This should print the name of all the file you intend do find.
Code:
for i in $(find /home/tim/readynas/Tim/Download/Downloaded/ -type f \( -iname \*.mkv -o -iname \*.avi -o -iname \*.wmv -o -iname \*.mp4 -o -iname \*.m4v \); do do this Code:
ls -l <some dir eg /tmp> So we print it out. Code:
ls -l <some dir eg /tmp> | awk '{print $5}' but when we do this Code:
$(ls -l <some FILENAME> | awk '{print $5}') for example do this Code:
date |
Quote:
That's great information. I'm slowly figuring it all out. When I attempt to run the script I get: /home/tim/bin/download_clean_sort.sh: line 30: unexpected EOF while looking for matching `)' /home/tim/bin/download_clean_sort.sh: line 64: syntax error: unexpected end of file I thought that by adding a second ) just before the ; would fix it but I then get more errors. Where should that second ) go? Cheers Tim |
inux-6e72:~ # for i in $(find /etc/init.d -type f \( -iname \*.sh \)); do echo $i ; done
/etc/init.d/mw_APCH.sh /etc/init.d/test.sh linux-6e72:~ # |
Quote:
/home/tim/bin/download_clean_sort.sh: line 32: syntax error in conditional expression: unexpected token `;' /home/tim/bin/download_clean_sort.sh: line 32: syntax error near `;t' /home/tim/bin/download_clean_sort.sh: line 32: `if [[ $(ls -l $i | ls -l | awk '{print $5}') -gt 10000]];then' I tried adding a space after the ; but this did not work either. OK figured out it needed a space after the 10000 :) |
Code:
linux-6e72:~ # ls -l /etc/init.d/*\.sh Code:
#!/bin/bash |
Quote:
Code:
Quote:
Cheers for all your time and patience Tim |
I would add some cautioning to the current solution:
1. If any of the file names have white space in them the for loop solution will fail 2. Should your default long listing output differ on future machines the ls / awk combination will also fail As it is working for you in its current form these are not a concern at this point :) However, a safer solution would be to use a while loop and then something like stat to get the size of the files. |
Quote:
Code:
[schneidz@mom moo-vees]$ file white-men-cant-jump.mkv |
One liner:
Code:
find /home/tim/readynas/Tim/Download/Downloaded/ \ |
Quote:
|
Without involving find:
Code:
#!/bin/bash |
All times are GMT -5. The time now is 06:18 PM. |