0

This is first time that I am using Linux, and I need to understand some concepts about two commands. I would be happy if you could explain the process one by one.

What does this command do?

cat ../test 

And what does this command do?

cat /etc/shadow 2>&1 | wc -l 

Thank you!

0

2 Answers 2

2

"../" is the parent directory.
So "cat ../test" means "print the 'test' file located in parent directory to standard output."

Second question:
All Linux (and Unix) processes have 3 standard files.
File 0 is input (stdin).
File 1 is normal output (stdout).
File 2 is error output (stderr).
2&>1 means "transfer error output into standard output".
The pipe | means "transfer output to the input of another program"
And the whole line means "count and display number of lines in /etc/shadow (including error messages if any).

1

You probably know what the cat command does. The man page states:

cat - concatenate files and print on the standard output

../ means the parent directory of your current working directory. So, if there is a file called test at that location the cat command will print it for you on the terminal.

In the second example, the content of /etc/shadow (if you have access to), will be piped to wc command.

wc - print newline, word, and byte counts for each file

-l, --lines: print the newline counts

This will print the number of lines in /etc/shadow on the terminal (only the number of lines, not the content). The 2>&1 notation redirects file descriptor 2 (standard error) to file descriptor 1 (standard output).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.