- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- files greater than size in a filesystem sorted by ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 01:01 AM
тАО02-25-2011 01:01 AM
what is the best and fastest solution to list file(s) greater than size (in MB) in a filesystem sorted by size.
i saw a solution in thread "How to find the greatest size file in certain mount point?".
is it a good solution solution to use "find ... -exec ll " or should it better to use perl ?
here my way :
# start of script:
mul()
{
# multiply of digit > 32 bit
bc<
$1*$2
EOF
}
# File_size in MB
CHECK_FILE_SIZE=20
typeset -E check_file_size_bytes
check_file_size_bytes=`mul ${CHECK_FILE_SIZE} 1048576`
find /tmp -xdev -size +${check_file_size_bytes}c -print
# now i have to use "find | ls | sort" ?
find /tmp -xdev -size +${check_file_size_bytes}c
-exec ls -ls {} \; | sort -n -r
regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 01:36 AM
тАО02-25-2011 01:36 AM
Re: files greater than size in a filesystem sorted by size
Using your logic, I would improve the syntax as follows:
CHECK_FILE_SIZE=20
typeset -E CHECK_FILE_SIZE_BYTES
CHECK_FILE_SIZE_BYTES=`echo "scale=0;${CHECK_FILE_SIZE}*1048576"|bc`
find /tmp -xdev -size +${CHECK_FILE_SIZE_BYTES}c -exec -ls -ld \;|sort -nr
Have not you thought of changing the value set in the script CHECK_FILE_SIZE by a variable dynamic value "$n" parsed from prompt? The same suggestion apply for the path value (/tmp) used by find command. i.e:
#./your_scriptname /tmp 20
Rgds
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 02:07 AM
тАО02-25-2011 02:07 AM
Re: files greater than size in a filesystem sorted by size
Please find attached a new version. This uses parsing values from prompt ($1=MountPoint and $2=FileSizeMb). Then try:
#./script_name /tmp 20
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 02:27 AM
тАО02-25-2011 02:27 AM
Re: files greater than size in a filesystem sorted by size
also a little bug :-)
old:
find $1 -xdev -size +${FILE_SIZE_BYTES}c -exec ls -ld \;|sort -nr
new:
find $1 -xdev -size +${FILE_SIZE_BYTES}c -exec ls -ld {} \;|sort -nr
Thx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 02:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 04:31 AM
тАО02-25-2011 04:31 AM
Re: files greater than size in a filesystem sorted by size
i improve sort to "sort -k5nr"
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 04:49 AM
тАО02-25-2011 04:49 AM
Re: files greater than size in a filesystem sorted by size
Rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 06:00 AM
тАО02-25-2011 06:00 AM
Re: files greater than size in a filesystem sorted by size
You should optimize by allowing 'find' not to spawn an 'ls' for every file it sees! Instead of using the '\;' terminator to '-exec' use '+'. Do something like:
# find . -xdev -type f -size +1000c -exec ls -ld {} +|sort -nrk5,5
Notice the addition of '-type f' to confine the output to only files.
Instead of coding the value 1048576 use (1024*1024). It's much clearer. Now you could write:
# check_file_size_bytes=$(mul ${CHECK_FILE_SIZE} 1024*1024))
...and in doing so also avoid the archaic backticks and use the $(...) POSIX syntax.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 07:15 AM
тАО02-25-2011 07:15 AM
Re: files greater than size in a filesystem sorted by size
# find . -xdev -type f -size +1000c -exec ls -ld {} +|sort -nrk5,5
i hear it first time to use "+"
# check_file_size_bytes=$(mul ${CHECK_FILE_SIZE} 1024*1024))
i tested it and the right syntax is
check_file_size_bytes=$(mul ${CHECK_FILE_SIZE} 1024*1024 )
also it isn't possible
check_file_size_bytes=$(mul ${CHECK_FILE_SIZE} (1024*1024) )
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2011 07:35 AM
тАО02-25-2011 07:35 AM
Re: files greater than size in a filesystem sorted by size
> i hear it first time to use "+"
Yes, this acts (and may in fact be better) than using 'xargs' to collect multiple arguments and present them as a bundle to a process.
# find . -type f -exec ls -l {} \;
# find . -type f | xargs ls -l
# find . -type f -exec ls -l {} +
One caveat: If you were passing your output to a script that *expected* only one argument you would need to use the '\;' form so that only one argument would be received for every script invocation.
Regards!
...JRF...