Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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.

share|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
    
Thank you all! I appreciate the help. –  NickV Aug 2 '13 at 17:58

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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