LinuxQuestions.org
Help answer threads with 0 replies.
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 05-04-2016, 07:23 AM   #16
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397

Code:
perl -e 'print map{$s=(stat)[7];"$s $_\n" if $s >=$ARGV[0] && $s<=$ARGV[1]}<*>' $MIN $MAX
Edit: or using -s file size test (returns size in bytes)
Code:
perl -e 'print map{-s." $_\n" if -s>=$ARGV[0] && -s _<=$ARGV[1]}<*>' $MIN $MAX

Last edited by keefaz; 05-04-2016 at 10:01 AM.
 
1 members found this post helpful.
Old 05-04-2016, 09:35 AM   #17
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 4,430

Rep: Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350Reputation: 1350
@HMW Your code is very like mine although I used:
Code:
fileSize=$(stat -c "%s" --  "$f")
This guards against a filename starting with a hyphen character that would otherwise be interpreted as an option to 'stat'.
Also, the output can be made a little prettier by using 'printf' instead of 'echo'.
Code:
printf "%-70s %10d\n" "$f" "$fileSize"
Other potential improvements include:
- checking that $1 is actually less than $2
- allowing $1 and $2 to take a suffix such as K,M,G to allow for kilobyte, megabyte and gigabyte to be easily specified
- allowing for recursion into sub-directories
- and, of course grail's comment in post #15

@keefaz - Nice perl one liner! However a robust script needs some error checking.

Last edited by allend; 05-04-2016 at 09:38 AM.
 
Old 05-04-2016, 09:58 AM   #18
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 5,387

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
Quote:
Originally Posted by allend View Post
@keefaz - Nice perl one liner! However a robust script needs some error checking.
Yes, true. Had some time to waste so I played.
 
Old 05-04-2016, 10:04 AM   #19
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Xubuntu, Manjaro
Posts: 745
Blog Entries: 3

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
^Nice to see everybody's input on this. Also, this is why I love LinuxQuestions.org!

But... let's stop now, otherwise we'll soon be rewriting find!!!

Code:
find - search for files in a directory hierarchy
Synopsis

find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]
Best regards,
HMW
 
  


Reply

Tags
linux, newbie, scripts


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
Process bound to specific CPU. Are the related TCP syscalls executed on same CPU? perec-jar Linux - Networking 2 01-05-2015 02:19 PM
[SOLVED] Regular expression needed to write [[:lower:]] to [[:lower:]] and [[:upper:]] rgdacosta Programming 13 04-05-2012 01:50 PM
Force TCP traffic out over specific interface when IP is bound to another local NIC yeager Linux - Networking 7 08-17-2010 10:16 AM
file names, switching from upper to lower bhert Linux - Newbie 3 08-13-2006 10:43 PM


All times are GMT -5. The time now is 12:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration