Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.