LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-02-2016, 10:12 AM   #31
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,628

Rep: Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943Reputation: 2943

My suggestion of nullglob would mean prior to that I also would get errors from stat for the 4 extensions.
 
1 members found this post helpful.
Old 09-02-2016, 10:16 AM   #32
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,742

Rep: Reputation: 1300Reputation: 1300Reputation: 1300Reputation: 1300Reputation: 1300Reputation: 1300Reputation: 1300Reputation: 1300Reputation: 1300Reputation: 1300
Quote:
Originally Posted by Entropy1024 View Post
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
It would be easier to use:
Code:
$(stat --printf "%s\n" filename)
Much simpler than the "$(ls -l <some FILENAME> | awk '{print $5}')" which is a bit awkward and slow
 
Old 09-02-2016, 08:47 PM   #33
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 5,032

Rep: Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762Reputation: 1762
OK - I have now seen the error, which occurs if no file with a particular extension is present.
As grail suggested, adding the nullglob setting suppresses the error here.
Code:
#!/bin/bash

topdir="/home/tim/readynas/Tim/Download/Downloaded/"
cd "$topdir"

longform="/home/tim/readynas/Videos/Longform/"
shortform="/home/tim/readynas/Videos/Shortform/"

(( limit=2*1024*1024*1024 ))

shopt -s nullglob
shopt -s globstar

for f in **/*.{avi,m4v,mkv,mp4,wmv}; do
 (( $(stat -c %s "$f") > limit )) && mv "$f" "$longform" || mv "$f" "$shortform"
done

shopt -u globstar
shopt -u nullglob

Last edited by allend; 09-03-2016 at 12:27 AM.
 
Old 09-03-2016, 04:26 AM   #34
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 127

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by allend View Post
OK - I have now seen the error, which occurs if no file with a particular extension is present.
As grail suggested, adding the nullglob setting suppresses the error here.
Code:
#!/bin/bash

topdir="/home/tim/readynas/Tim/Download/Downloaded/"
cd "$topdir"

longform="/home/tim/readynas/Videos/Longform/"
shortform="/home/tim/readynas/Videos/Shortform/"

(( limit=2*1024*1024*1024 ))

shopt -s nullglob
shopt -s globstar

for f in **/*.{avi,m4v,mkv,mp4,wmv}; do
 (( $(stat -c %s "$f") > limit )) && mv "$f" "$longform" || mv "$f" "$shortform"
done

shopt -u globstar
shopt -u nullglob
Many thanks for all the great help. I'm learning a lot from these examples.
Tim
 
Old 09-03-2016, 04:31 AM   #35
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 127

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by allend View Post
OK - I have now seen the error, which occurs if no file with a particular extension is present.
As grail suggested, adding the nullglob setting suppresses the error here.
Code:
#!/bin/bash

topdir="/home/tim/readynas/Tim/Download/Downloaded/"
cd "$topdir"

longform="/home/tim/readynas/Videos/Longform/"
shortform="/home/tim/readynas/Videos/Shortform/"

(( limit=2*1024*1024*1024 ))

shopt -s nullglob
shopt -s globstar

for f in **/*.{avi,m4v,mkv,mp4,wmv}; do
 (( $(stat -c %s "$f") > limit )) && mv "$f" "$longform" || mv "$f" "$shortform"
done

shopt -u globstar
shopt -u nullglob
Many thanks for all the great help. I'm learning a lot from these examples.
Tim
 
  


Reply

Tags
bash, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Script to sort video files into different folders MidKnightLoki Linux - General 1 11-20-2012 06:49 PM
[SOLVED] Bash Script; Sort files into directory based on data in the file name MTAS Programming 31 10-06-2010 12:47 PM
bash script help - finding last n log files in all sub folders jeepescu Programming 4 11-03-2007 08:57 PM
Bash script to sort image files dtcs Programming 5 09-26-2006 10:50 PM
bash script to sort files by extension otheralex Programming 7 08-19-2005 03:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration