LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 06-09-2019, 10:11 PM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Rep: Reputation: 56
Find command confusion ???


Hello

I want to find files that are less than 1 MiB.

Following is the actual list of files:
Code:
$ ls -lS
total 18636
-rw-r--r--. 1 xxxxx xxxxx 3960382 Mar 18 17:59 adwaita-day.jpg
-rw-r--r--. 1 xxxxx xxxxx 3376649 Mar 18 17:59 adwaita-morning.jpg
-rw-r--r--. 1 xxxxx xxxxx 1005300 May 27 19:54 rhel_patterncity_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  911868 May 27 19:54 rhel_patternstripe_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  860907 May 27 19:54 rhel_patterncity_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  821545 May 27 19:54 rhel_patterncity_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  813419 May 27 19:54 rhel_patternstripe_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  706510 May 27 19:54 dottexture_navy_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  679680 May 27 19:54 rhel_patterncity_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  674743 May 27 19:54 rhel_patternstripe_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  659666 May 27 19:54 dottexture_navy_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  584644 May 27 19:54 dottexture_navy_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  549745 May 27 19:54 rhel_patternstripe_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  509531 May 27 19:54 night.jpg
-rw-r--r--. 1 xxxxx xxxxx  482844 May 27 19:54 dottexture_navy_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  456058 May 27 19:54 morning.jpg
-rw-r--r--. 1 xxxxx xxxxx  447635 Mar 18 17:59 adwaita-night.jpg
-rw-r--r--. 1 xxxxx xxxxx  392746 May 27 19:54 day.jpg
-rw-r--r--. 1 xxxxx xxxxx  356827 May 13 15:26 074ea2885318037b764178e7f8c03b11b.jpg
-rw-r--r--. 1 xxxxx xxxxx  223076 May 27 19:54 corporate_engraved_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  208803 May 27 19:54 corporate_engraved_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  191219 May 27 19:54 corporate_engraved_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  163977 May 27 19:54 corporate_engraved_1800x1440.jpg
So I issue this command:
Code:
$ find . -size -$((1*1024*1024))c -ls
359751838    4 drwxr-xr-x   2 xxxxx    xxxxx        4096 Jun  9 12:35 .
359955587  164 -rw-r--r--   1 xxxxx    xxxxx      163977 May 27 19:54 ./corporate_engraved_1800x1440.jpg
359955590  188 -rw-r--r--   1 xxxxx    xxxxx      191219 May 27 19:54 ./corporate_engraved_2048x1536.jpg
359955591  204 -rw-r--r--   1 xxxxx    xxxxx      208803 May 27 19:54 ./corporate_engraved_2560x1440.jpg
359960452  220 -rw-r--r--   1 xxxxx    xxxxx      223076 May 27 19:54 ./corporate_engraved_2560x1600.jpg
359960453  384 -rw-r--r--   1 xxxxx    xxxxx      392746 May 27 19:54 ./day.jpg
359960454  472 -rw-r--r--   1 xxxxx    xxxxx      482844 May 27 19:54 ./dottexture_navy_1800x1440.jpg
359960455  572 -rw-r--r--   1 xxxxx    xxxxx      584644 May 27 19:54 ./dottexture_navy_2048x1536.jpg
359960456  648 -rw-r--r--   1 xxxxx    xxxxx      659666 May 27 19:54 ./dottexture_navy_2560x1440.jpg
359960457  692 -rw-r--r--   1 xxxxx    xxxxx      706510 May 27 19:54 ./dottexture_navy_2560x1600.jpg
359960458  448 -rw-r--r--   1 xxxxx    xxxxx      456058 May 27 19:54 ./morning.jpg
359960459  500 -rw-r--r--   1 xxxxx    xxxxx      509531 May 27 19:54 ./night.jpg
359960460  664 -rw-r--r--   1 xxxxx    xxxxx      679680 May 27 19:54 ./rhel_patterncity_1800x1440.jpg
359960461  804 -rw-r--r--   1 xxxxx    xxxxx      821545 May 27 19:54 ./rhel_patterncity_2048x1536.jpg
359960462  844 -rw-r--r--   1 xxxxx    xxxxx      860907 May 27 19:54 ./rhel_patterncity_2560x1440.jpg
359960463  984 -rw-r--r--   1 xxxxx    xxxxx     1005300 May 27 19:54 ./rhel_patterncity_2560x1600.jpg
359960464  540 -rw-r--r--   1 xxxxx    xxxxx      549745 May 27 19:54 ./rhel_patternstripe_1800x1440.jpg
359960465  660 -rw-r--r--   1 xxxxx    xxxxx      674743 May 27 19:54 ./rhel_patternstripe_2048x1536.jpg
359960466  796 -rw-r--r--   1 xxxxx    xxxxx      813419 May 27 19:54 ./rhel_patternstripe_2560x1440.jpg
359960467  892 -rw-r--r--   1 xxxxx    xxxxx      911868 May 27 19:54 ./rhel_patternstripe_2560x1600.jpg
358795372  352 -rw-r--r--   1 xxxxx    xxxxx      356827 May 13 15:26 ./074ea2885318037b764178e7f8c03b11b.jpg
380644160  440 -rw-r--r--   1 xxxxx    xxxxx      447635 Mar 18 17:59 ./adwaita-night.jpg
Perfect.

But when I use -exec option, why I'm getting this output?
Code:
$ find . -size -$((1*1024*1024))c -exec ls -l "{}" +
-rw-r--r--. 1 xxxxx xxxxx  356827 May 13 15:26 ./074ea2885318037b764178e7f8c03b11b.jpg
-rw-r--r--. 1 xxxxx xxxxx  447635 Mar 18 17:59 ./adwaita-night.jpg
-rw-r--r--. 1 xxxxx xxxxx  163977 May 27 19:54 ./corporate_engraved_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  191219 May 27 19:54 ./corporate_engraved_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  208803 May 27 19:54 ./corporate_engraved_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  223076 May 27 19:54 ./corporate_engraved_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  392746 May 27 19:54 ./day.jpg
-rw-r--r--. 1 xxxxx xxxxx  482844 May 27 19:54 ./dottexture_navy_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  584644 May 27 19:54 ./dottexture_navy_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  659666 May 27 19:54 ./dottexture_navy_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  706510 May 27 19:54 ./dottexture_navy_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  456058 May 27 19:54 ./morning.jpg
-rw-r--r--. 1 xxxxx xxxxx  509531 May 27 19:54 ./night.jpg
-rw-r--r--. 1 xxxxx xxxxx  679680 May 27 19:54 ./rhel_patterncity_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  821545 May 27 19:54 ./rhel_patterncity_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  860907 May 27 19:54 ./rhel_patterncity_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx 1005300 May 27 19:54 ./rhel_patterncity_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  549745 May 27 19:54 ./rhel_patternstripe_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  674743 May 27 19:54 ./rhel_patternstripe_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  813419 May 27 19:54 ./rhel_patternstripe_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  911868 May 27 19:54 ./rhel_patternstripe_2560x1600.jpg

.:
total 18636
-rw-r--r--. 1 xxxxx xxxxx  356827 May 13 15:26 074ea2885318037b764178e7f8c03b11b.jpg
-rw-r--r--. 1 xxxxx xxxxx 3960382 Mar 18 17:59 adwaita-day.jpg
-rw-r--r--. 1 xxxxx xxxxx 3376649 Mar 18 17:59 adwaita-morning.jpg
-rw-r--r--. 1 xxxxx xxxxx  447635 Mar 18 17:59 adwaita-night.jpg
-rw-r--r--. 1 xxxxx xxxxx  163977 May 27 19:54 corporate_engraved_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  191219 May 27 19:54 corporate_engraved_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  208803 May 27 19:54 corporate_engraved_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  223076 May 27 19:54 corporate_engraved_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  392746 May 27 19:54 day.jpg
-rw-r--r--. 1 xxxxx xxxxx  482844 May 27 19:54 dottexture_navy_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  584644 May 27 19:54 dottexture_navy_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  659666 May 27 19:54 dottexture_navy_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  706510 May 27 19:54 dottexture_navy_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  456058 May 27 19:54 morning.jpg
-rw-r--r--. 1 xxxxx xxxxx  509531 May 27 19:54 night.jpg
-rw-r--r--. 1 xxxxx xxxxx  679680 May 27 19:54 rhel_patterncity_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  821545 May 27 19:54 rhel_patterncity_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  860907 May 27 19:54 rhel_patterncity_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx 1005300 May 27 19:54 rhel_patterncity_2560x1600.jpg
-rw-r--r--. 1 xxxxx xxxxx  549745 May 27 19:54 rhel_patternstripe_1800x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  674743 May 27 19:54 rhel_patternstripe_2048x1536.jpg
-rw-r--r--. 1 xxxxx xxxxx  813419 May 27 19:54 rhel_patternstripe_2560x1440.jpg
-rw-r--r--. 1 xxxxx xxxxx  911868 May 27 19:54 rhel_patternstripe_2560x1600.jpg
Not only the output gets repeated but also shows files that are greater than 1 MiB.

How do I correct this?

Thanks
 
Old 06-09-2019, 11:09 PM   #2
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by ddenial View Post
Not only the output gets repeated but also shows files that are greater than 1 MiB.

How do I correct this?

Thanks
First: the size option can be easier put as "-size -1M" (capital M).
Then, the -exec as YOU did it will also work on subdirectories, as they're (almost always) smaller then 1M. So either put an extra "-type f" in the find or an extra option -d in
the ls -l (to show directories AS directories, not as their contents).
Finally the string {} doesn't need to be quoted.

See the section about "-execdir" too in the man page for find.

Last edited by ehartman; 06-10-2019 at 12:41 AM. Reason: small typing error
 
1 members found this post helpful.
Old 06-09-2019, 11:38 PM   #3
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Thanks

Quote:
Originally Posted by ehartman View Post
First: the size option can be easier put as "-size -1M" (capital M).
For some reason, find won't find files less than 1MiB. I got this from here, post-No.3

Quote:
Originally Posted by ehartman View Post
The, the -exec as YOU did it will also work on subdirectories, as they're (almost always) smaller then 1M. So either put an extra "-type f" in the find or an extra option -d in the ls -l (to show directories AS directories, not as their contents).
But there are no subdirectories. The -type f option works though. Does the . and .. are also considered as directories?
 
Old 06-10-2019, 12:44 AM   #4
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by ddenial View Post
Does the . and .. are also considered as directories?
As your output shows the contents of
Quote:
.:
total 18636
too: yes!

I don't think find will go into .., though.

BTW: find's -ls option is equivalent to ls -dils, so with i-nodes and size in blocks added.

Last edited by ehartman; 06-10-2019 at 12:54 AM.
 
1 members found this post helpful.
Old 06-10-2019, 04:13 AM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
The $(()) only takes two parameters, for three you'd have to nest $(()), so $(( 1 * $(( 1024 * 1024 )) ))c. Or I could be wrong.

Last edited by Shadow_7; 06-10-2019 at 04:14 AM.
 
Old 06-10-2019, 04:48 AM   #6
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
Odd, the "-type f" as previous suggested helps. Without it the -size seemed to get ignored. For me anyway.

$ find ./ -size $(( -1 * 50 ))k -type f 2>&1 | while read FILE; do ls -l $FILE; done

The while read just to have ls -l output to show file size. Probably a way for find to output that, and not efficient my way. I just wanted it to verify results. I could have sworn that $(( )) needed nesting, maybe a versioning quirk. Or an old programmer mental block having started on assembler where nothing took more than two parameters (or used to at least). In either case, probably better to multiply with a leading negative number for a - prefixed result. The - prefixed arithmetic operation might be interpreted as a bad parameter, than a value to a parameter. Probably just another programmer mental block though, as it seems to work regardless.
 
Old 06-11-2019, 05:59 PM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
edit: NM. I see you corrected yourself. Sorry for the noise.

Last edited by GazL; 06-11-2019 at 06:02 PM.
 
Old 06-12-2019, 02:54 PM   #8
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,801

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by ehartman View Post
I don't think find will go into .., though.
No. It doesn't. If it did, you'd have a difficult time controlling where it was supposed to look. :^D
 
Old 06-12-2019, 02:58 PM   #9
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,801

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by Shadow_7 View Post
The $(()) only takes two parameters, for three you'd have to nest $(()), so $(( 1 * $(( 1024 * 1024 )) ))c. Or I could be wrong.
No restriction on the number of arguments or on the spacing (in case that affect the arg count):
Code:
$ echo "$(( 1 * 1024 * 1024 ))"
1048576
$ echo "$(( 2 * 2 * 1024 * 1024 ))"
4194304
 
  


Reply



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
Find command confusion skoda Linux - Newbie 12 11-09-2015 07:33 AM
Linux find command -perm mode confusion diamond_D Linux - Newbie 2 03-05-2012 07:59 PM
[SOLVED] Confusion with locales: keep english command output lich000king Linux From Scratch 3 06-28-2011 01:42 PM
[SOLVED] Cat command confusion. nnjond Linux - Newbie 6 08-12-2010 09:16 AM
confusion regarding a command rajaneesh Linux - Networking 2 01-01-2010 12:54 AM

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

All times are GMT -5. The time now is 09:50 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
Open Source Consulting | Domain Registration