The first pipe is an expensive (and error prone) way to mimic the behaviour of ls *; not sure what it should be good for. wc -l yields the count of lines, not words.
Please note that options to any command are introduced by a - (minus sign), NOT a – (Unicode U+2014, "EM DASH") character which leads to a syntax error.
Another way to count the number of (non-hidden) entries in a directory in pure shell, which is also more accurate (it will count filenames that contain newlines correctly):
or
Unless the directory is empty. Then these options report 1 instead of zero..
To mitigate these corner cases, in bash 4 one can use :
so that * expands to the null string if the directory is empty (except for hidden files).
or one could try something like:
--
Quote:
Originally Posted by rbatte1
Why not just:-
This negates the need for xargs entirely.
[..]
Note: this could be shortened still to
Since -1 is the default option of ls when the output is not a terminal
Last edited by Scrutinizer; 09-24-2016 at 02:34 AM..
These 2 Users Gave Thanks to Scrutinizer For This Post:
Just a small observation on the side: "-1" is unnecessary in this case, because ls will format its output in only one (instead of several) columns already if it notices that the output is not going to a terminal. See the following transcript:
hi, anyone can help on this piece of truss output?
8094: 0.7028 write(4, 0x0043BE90, 236) = 236
8094: T S H \0\0\0EC020101\0\0\0\0\0\0\0\0\0 "02\0\0 303\0\0 I D
8094: \f %\0\0\0\0 2\0F67F\0\0\0\0 @06FFC99A ;
8094: L D6\0 303
8094: ... (6 Replies)
On my VIo I see the following for my disks:
$ lspath | grep hdisk6
Enabled hdisk6 fscsi0 200600a0b82193f7,4000000000000
Enabled hdisk6 fscsi0 200700a0b82193f7,4000000000000
Enabled hdisk6 fscsi2 200600a0b82193f8,4000000000000
Failed hdisk6 fscsi2 200700a0b82193f8,4000000000000
$ lspath |... (8 Replies)
Hi All
I am running a insatll script in linux which installs the project.
Could you please help in interpreting this command
gawk '{ if (substr($1,0,1) == "\047") gsub("^\047+|\047+$", "", $1); print }'
where $1 = BBME
Thanks (1 Reply)
I have used SAR -b to get some Unix cache / buffer metrics and the results are confusing me a bit.
The pread/s & pwrit/s are showing 0. However the lread/s and lwrit/s are showing figures. I note also that the bread/s and bwrit/s are showing figures. I believe that pread/s and pwrit/s is not... (3 Replies)
Hi there,
do someone have detailed information how to interpret the uptime command or rather which values can be called normal?
(i know what the information means, but i have no idea if these values are ok or to high:
3:02pm an 13:53, 2 Benutzer, Durchschnittslast: 10,06, 12,05, 13,00)
... (5 Replies)
I am using bash shell; my requirement is to run a long command.
Now I have split this long command into a number of shell variables.
Some of these shell variables contain special character ':'
At the end, when the intended long command is executed as a series of small shell variables the ':'... (7 Replies)
I executed the following command in the korn shell:
$ variable1="qwerty" ls | sort
and the shell executed the 'ls | sort' command.
I would have expected an error message from the shell, but instead of that the shell ran the 'ls | sort' command and didn't realize the variable assignement. ... (1 Reply)