I'm fairly new to Unix commands and I just have a simple question.

One exercise I'm working on wants me to use piping along with cat and less to concatenate 2 directories (in this case /etc/passwd and /etc/group) together and then display the output one page at a time.

I've been trying ls - la | less cat /etc/passwd/ - /etc/group but I'm not sure of the exact syntax I should use. What should I change?

EDIT: Changed directories to files in the title for future reference.


When using pipes, you want to consider the order of operations before fashioning your pipeline. You'll also want to have a good understanding of what each command does.

For clarification: /etc/passwd and /etc/group are not directories, but files. You're on the right track using ls for directories, but in this case it is not needed.

To get you started, here are a few tips (also try man <command> for more details).

less is great for displaying paginated output.

cat is great for printing the contents of a file (or multiple) in a single stream to STDOUT.

Putting those together:

cat /etc/group /etc/passwd | less means "concatenate the two specified files (passwd and group) and pipe the resulting output to less, which displays them in paginated form.

| improve this answer | |
  • Great explanation and pointing out man is a great idea for a unix greenhorn. Just one thing to add for the OP: If you are searching for something (specific word or whatever), when in less, man, or vim, you can type / and then provide search criteria (n goes to the next match, assuming it exists). – nerdwaller Aug 2 '13 at 17:30

First of all, you are talking about files, not directories. Also, the ls is irrelevant. All you need to do is

cat   /etc/passwd/ /etc/group | less

catsimply prints the contents of the files you give it, giving it two files will cause it to output the contents of one after the other. less is a pager, a program that allows you to read multi-line data one page at a time.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.