ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Since ls -lS sorts files by size, head -1 returns the bigger one. That's it. Where do you see such a complexity?
When I copy-paste your command (searching from ~), without the 'cut' part, I get many lines, not just one line.
This is what 'man xargs' says in the beginning:
Code:
This manual page documents the GNU version of xargs. xargs reads items from the standard input, delimited by blanks (which can be protected with double or single
quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any initial-arguments followed by items read from stan-
dard input. Blank lines on the standard input are ignored.
When I copy-paste your command (searching from ~), without the 'cut' part, I get many lines, not just one line.
That's really odd. Whatever the output is, the head -1 should give just one line. It works on my system. Anyway, as usual, there are many ways to do the same task in linux.
That's really odd. Whatever the output is, the head -1 should give just one line. It works on my system. Anyway, as usual, there are many ways to do the same task in linux.
Try the command without 'head' in a filesystem with a lot of files and watch output - you'll see it doesn't do what it should - my point is:
Code:
find /usr -type f -print0 | xargs -0 ls -lS | head -10000 | less
yields, among other things, this (seen from inside 'less' with -N on):
, i.e. overall you do not the longest file on top, so 'head- 1' won't bring you the needed file.
You're right. This is because the standard input is buffered through the pipe, so xargs receive a certain number of file names at a time and execute the command. I stand corrected.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.