How can I print the total number of file descriptors with index 24 [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
How can I print the total number of file descriptors with index 24 for all the running processes?
I tried something: $
ls /proc/*/fd 2> errors.txt > stdout.txt | grep "^24" stdout.txt | wc -l
This solution returns 0 everytime.
I mention that my task ask me to write an one liner in order to solve it.

ls /proc/*/fd 2>/dev/null | grep -c '^24$'

Related

What do terminal commands ls > wc and ls | wc show? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I know what the commands ls and wc do, but I can not find out what ls > wc and ls | wc will show. Can someone please help me flush out the meaning of this commands?
ls | wc The output from the ls command is piped into the wc command. So it will count the words which are in the output of ls. So you see simply the number of files read by ls.
ls > wc This creates a new file in your current working directory with the name wc with the output of your ls command. The program wc is not used here, simply a new file with the same name is created. You can simply look into this new file with your favorite editor or simply use cat for it.

What does grep -v _1_ <file_name> do? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 1 year ago.
Improve this question
I'm new to bash scripting, can someone tell me what is the meaning of the below command.
grep -v _1_ <file_name> > <new_file>
The -v switch inverts the criteria, so it shows only the lines which does NOT contain the string _1_ and logs the output into the file <new_file>.
The question is wrong, you have written the command as:
grep -v _1_ <file_name> > <new_file>
While it should be:
grep -v _1_ <file1> > <file2>
You can use grep on more file than one, which means that you are looking for something in more than one file.
The -v part is already explained by Antonio.

how to get the total size of certain folders in bash? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
How can I get the total size of the certain folders?
For example I have a list of specific folder names in users.txt
# cat users.txt
user1
user2
user3
all this folders are locate in /home/
I have tried to execute:
# for i in `cat users.txt`; do du -shc /home/$i/; done
3.9M /home/user1/
3.9M total
141M /home/user2/
141M total
75M /home/user3/
75M total
but I need a total size of all of this folders.
du -shc $(sed 's#^#/home/#' users.txt)
That uses the contents of users.txt, prepended with /home/, as the arguments to du, so it will sum them for you.
You can pass output of du to tail -n 1 or execute
du -s directory
To get only size you can do
du -s directory | cut -f1

Meaning of command ls -lt | wc -l [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
My friend just passed me this command to count the number of files in a directory:
$ ls -lt | wc -l
Can someone please help me flush out the meaning of this command? I know that ls is to list all the files. But what does -lt mean?
Also, I get a different count if I use ls | wc -l with no -lt option. Why is that the case?
You'll want to get familiar with the "man (manual) pages":
$ man ls
In this case you'll see:
-l (The lowercase letter ``ell''.) List in long format. (See below.) If
the output is to a terminal, a total sum for all the file sizes is
output on a line before the long listing.
-t Sort by time modified (most recently modified first) before sorting the
operands by lexicographical order.
Another way you can see the effect of the options is to run ls without piping to the wc command. Compare
$ ls
with
$ ls -l
and
$ ls -lt

new line separator for each grep result sh script [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there a way to have each result of grep followed by newline
for example if the result of grep is:
1
2
3
I need it to be:
1
2
3
grep "pattern" /path/to/file | awk '{print $0,"\n"}'

Resources