I don't want my ls command in my script to print results on screen
Solution 1:
Your script will print each of the commands in your pipeline to the terminal because you are running it with the -x
flag. Fromman bash
:
-x Print commands and their arguments as they are executed.
However, your approach using ls
and wc
is not the best way to count files.
To find file that is >= 20000 you can use find:
find -type f -maxdepth 1 -name 'umbrella31_*log' -size +19999c -ls
(because of how find interpreters + sign (greater than rounded up) you get n+1, therefore the odd-size n
)
count output:
(when we count files we just print a newline because we dont really need an output)
wc -l < <(find -maxdepth 1 -type f -name 'umbrella31_*log' -size +19999c -printf \\n)
-maxdepth n
Descend at most levels (a non-negative integer) levels of directories below the starting-points.
-size n
File uses n units of space, rounding up.
-ls
List current file in ls -dils format on standard output.
Solution 2:
Updated Answer
After posting script used in the question it was discovered:
#!/bin/bash -x
was used where the -x
option outputs all commands to the terminal.
Removing the -x
solved the original problem.
Original Answer
You're missing the argument flag indicator so this:
ls lX umbrella31_*log | awk '{if($5 >=20000) {print}}' | wc -l
should be this instead:
ls -lX umbrella31_*log | awk '{if($5 >=20000) {print}}' | wc -l
On my system looking for bash scripts it works like so:
$ ls -lX *.sh
-rwxrwxr-x 1 rick rick 4183 Jul 1 10:48 aptfileparse.sh
-rwxrwxr-x 1 rick rick 339 Jul 24 17:26 checkrunning.sh
-rwxrwxr-x 1 rick rick 506 Jul 15 17:54 Downloads.sh
-rwxrwxr-x 1 rick rick 78 Jul 6 11:28 runall.sh
$ ls -lX *.sh | awk '{if($5 >=200) {print}}' | wc -l
3