- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Finding files with specific size
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
Forums
Discussions
Discussions
Discussions
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
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
03-13-2003 05:58 PM
03-13-2003 05:58 PM
Hi Friends,
I am using the above command to display the files with the size specified but I am getting the files which are even smaller than the size listed above. Although I've looked into the -size n & c options, but still it doesn't help.
I am trying to search for files with size=84bytes and delete those. Am I missing something somewhere...??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2003 07:07 PM
03-13-2003 07:07 PM
Solution"...-size +n..." equates to :
+ : greater than
n : n blocks of 512 bytes.
"...-size -n..."
- : less than n blocks.
"...-size n..."
equal to n blocks.
"...-size +nc..."
+ : greater than
nc : characters (* one char = on byte *)
For "...size=84 bytes and delete..."
cd /dir
find . -size 84c -exec rm {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2003 07:09 PM
03-13-2003 07:09 PM
Re: Finding files with specific size
I'm not sure how to find files of an exact size using the 'find' command since it uses blocks for the size. I did figure out a way to do it using Perl. There is a Perl utility called find2perl which will take the parameters for a find command and write a little Perl script to do the same thing. I did that and modified the script to find files of exactly 84 bytes. I've posted the script as an attachment.
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2003 07:13 PM
03-13-2003 07:13 PM
Re: Finding files with specific size
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2003 07:31 PM
03-13-2003 07:31 PM
Re: Finding files with specific size
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2003 07:42 PM
03-13-2003 07:42 PM
Re: Finding files with specific size
That's really great to have good people like you. Yes, I've implemented the same and it's working fine. Still doing some more cosmetic changes in the perl script to suit the needs.
Would you be able to indicate the possibility of merging the 2 commands into 1, i.e., display it first and then delete it?
find
find . -size 84c -exec rm {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2003 08:41 PM
03-13-2003 08:41 PM
Re: Finding files with specific size
#find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2003 01:32 AM
03-14-2003 01:32 AM
Re: Finding files with specific size
# perl -MFile::Find -e'find(sub{-f&&-s==84&&print},".")'
does find all files with size 84, and in a system independant way. Here it is on cygwin:
LT03:/tmp 6 $ ll ????.???
-rwxrwxrwx+ 1 Administ None 32768 Nov 5 21:49 MMC3.tmp*
-rwxrwxrwx+ 1 Administ None 32768 Nov 5 21:49 MMC4.tmp*
-rwxrwxrwx+ 1 Administ None 32768 Nov 5 21:49 MMC5.tmp*
-rwxrwxrwx+ 1 Administ None 10678 Dec 2 16:22 Off2.tmp*
-rwxrwxrwx+ 1 Administ None 11158 Dec 5 07:28 Off3.tmp*
-rwxrwxrwx+ 1 Administ None 13558 Feb 11 18:40 Off4.tmp*
-rw-rw-rw- 1 lt03 None 1824 Jan 10 15:03 XWin.log
LT03:/tmp 7 $ perl -MFile::Find -le'find(sub{-f&&-s==1824&&print},".")'
XWin.log
LT03:/tmp 8 $
replace the 'print' with any action you like
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2003 06:31 AM
03-14-2003 06:31 AM
Re: Finding files with specific size
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2003 06:51 AM
03-14-2003 06:51 AM
Re: Finding files with specific size
option -M means use module ...
in this case, I want to use File::Find, a module shipped with the perl5 CORE distribution, giving you system independent 'find' functionality in perl
use 'man File::Find' to find out more about it
here's the script in verbose mode:
--8<---
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my @dirs_to_find = (".");
sub action
{
-f or return; # only 'files' please, no dir's or pipes
-s == 84 or return; # Only need files with size 84
unlink $File::Find::name; # remove the file
}, @dirs_to_find);
-->8---
clear?
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2003 06:57 AM
03-14-2003 06:57 AM
Re: Finding files with specific size
Change
--8<---
sub action
{
-f or return; # only 'files' please, no dir's or pipes
-s == 84 or return; # Only need files with size 84
unlink $File::Find::name; # remove the file
}, @dirs_to_find);
-->8---
to
--8<---
sub action
{
-f or return; # only 'files' please, no dir's or pipes
-s == 84 or return; # Only need files with size 84
unlink $File::Find::name; # remove the file
}
find (\&action, @dirs_to_find);
-->8---
I'm so used to the 'find (sub{},".")' notation, that I used it :/
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-14-2003 07:29 AM
03-14-2003 07:29 AM
Re: Finding files with specific size
If you want to do the ll and rm in "one go" with find:
find . -size 84c -type f | xargs -i echo "ll {};rm {}" |sh
rgds, Robin.