LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-01-2016, 07:09 PM   #16
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,996

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187

You can shorten your limit
Code:
(( limit = 2 * 2 ** 30 ))
 
Old 09-01-2016, 08:24 PM   #17
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,350

Rep: Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739
Yep
And should probably trim the filenames e.g. mv "$f" "$longform${f##*/}"

Last edited by allend; 09-01-2016 at 08:33 PM.
 
Old 09-02-2016, 04:41 AM   #18
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 131

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by allend View Post
Without involving find:
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 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
When I run this I get the following error:
/home/tim/bin/download_clean_sort.sh: line 46: ((: > limit : syntax error: operand expected (error token is "> limit ")

Where is this going wrong?

Many thanks
Tim
 
Old 09-02-2016, 06:31 AM   #19
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,996

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
What version of bash are you running? Also, what distribution of linux?

Last edited by grail; 09-02-2016 at 06:33 AM.
 
Old 09-02-2016, 06:40 AM   #20
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,350

Rep: Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739
Quote:
/home/tim/bin/download_clean_sort.sh: line 46: ((: > limit : syntax error: operand expected (error token is "> limit ")
The code I posted does not have that many lines. What is in that file?
 
Old 09-02-2016, 06:50 AM   #21
Entropy1024
Member
 
Registered: Dec 2012
Location: UK
Distribution: Ubuntu 16 & 17
Posts: 131

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by allend View Post
The code I posted does not have that many lines. What is in that file?
Sorry yes I spliced it into an existing script. The other parts of the script are just finding and removing small files with a certain extension.

the error code is relating to this line (Line 14 in your original code?):
(( $(stat -c %s "$f") > limit )) && mv "$f" "$longform" || mv "$f" "$shortform"

Cheers
 
Old 09-02-2016, 07:11 AM   #22
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,350

Rep: Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739
Does running my code in it's own script cause an error? You can change 'mv' to 'echo' for testing.
 
Old 09-02-2016, 07:11 AM   #23
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
not sure but to me it should be:
Code:
(( $(stat -c %s "$f") > $limit )) && mv "$f" "$longform" || mv "$f" "$shortform"
 
Old 09-02-2016, 07:21 AM   #24
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,350

Rep: Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739
From 'man bash' under ARITHMETIC EVALUATION
Quote:
Within an expression, shell variables may also be referenced by name without using the parameter expansion syntax.
 
1 members found this post helpful.
Old 09-02-2016, 07:37 AM   #25
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
That would mean $f is empty or result of $(stat -c %s "$f") is empty

Last edited by keefaz; 09-02-2016 at 07:39 AM.
 
Old 09-02-2016, 07:45 AM   #26
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,350

Rep: Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739
From 'man bash' under Command Substitution
Quote:
Command substitution allows the output of a command to replace the command name. There are two forms:
$(command)
or
`command`
Bash performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing newlines deleted.
 
Old 09-02-2016, 07:48 AM   #27
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Code:
limit=1 && (( "" > limit ))
bash: ((: > limit : syntax error: operand expected (error token is "> limit ")
 
Old 09-02-2016, 07:55 AM   #28
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,996

Rep: Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187Reputation: 3187
Maybe place an echo as first line of for loop to see value of $f. Could be no files have been found with the correct ending and then you may also need to set nullglob
 
Old 09-02-2016, 07:59 AM   #29
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
What is strange is if $f was empty, Op would have received an error from stat command as well
 
Old 09-02-2016, 08:27 AM   #30
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,350

Rep: Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739Reputation: 2739
I cannot reproduce the error in rxvt, xterm or xfce-terminal.
Code:
set | grep SHELLOPTS
returns
Quote:
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
and
Code:
shopt -p
returns
Quote:
shopt -u autocd
shopt -u cdable_vars
shopt -u cdspell
shopt -u checkhash
shopt -u checkjobs
shopt -u checkwinsize
shopt -s cmdhist
shopt -u compat31
shopt -u compat32
shopt -u compat40
shopt -u compat41
shopt -u compat42
shopt -s complete_fullquote
shopt -u direxpand
shopt -u dirspell
shopt -u dotglob
shopt -u execfail
shopt -s expand_aliases
shopt -u extdebug
shopt -u extglob
shopt -s extquote
shopt -u failglob
shopt -s force_fignore
shopt -u globstar
shopt -u globasciiranges
shopt -u gnu_errfmt
shopt -u histappend
shopt -u histreedit
shopt -u histverify
shopt -s hostcomplete
shopt -u huponexit
shopt -s interactive_comments
shopt -u lastpipe
shopt -u lithist
shopt -u login_shell
shopt -u mailwarn
shopt -u no_empty_cmd_completion
shopt -u nocaseglob
shopt -u nocasematch
shopt -u nullglob
shopt -s progcomp
shopt -s promptvars
shopt -u restricted_shell
shopt -u shift_verbose
shopt -s sourcepath
shopt -u xpg_echo
 
  


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 05:49 PM
[SOLVED] Bash Script; Sort files into directory based on data in the file name MTAS Programming 31 10-06-2010 11:47 AM
bash script help - finding last n log files in all sub folders jeepescu Programming 4 11-03-2007 07:57 PM
Bash script to sort image files dtcs Programming 5 09-26-2006 09:50 PM
bash script to sort files by extension otheralex Programming 7 08-19-2005 02:40 AM

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

All times are GMT -5. The time now is 09:48 PM.

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
Open Source Consulting | Domain Registration