Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From the command line, what is the easiest way to show the contents of multiple files? My directory looks like below.


Now I'd like to view the contents of all files except .htaccess. It might look something like:

Contents of file WtCgikkCFHmmuXQXp0FkZjVrnJSU64Jb9WSyZ52b.

Contents of file xdIwVHnHY7dnuM9zcPDYQGZFdoVORPyMVD2IzjgM.


I think this should be doable with a combination of find, xargs and cat, but I haven't figured out how. Thanks for your time!

share|improve this question
up vote 13 down vote accepted

The two standard commands head and tail print a header with the file name if you pass them more than one file argument. To print the whole file, use tail -n +1 (print from the first line onwards, i.e. everything).

Here, it looks like you want to see every file except the single one whose name begins with a dot. Dot files are “hidden” under unix: they don't appear in the default output of ls or in a wildcard match. So matching every non-hidden files is done with just *.

tail -n +1 *

(Strictly speaking, tail -n +1 -- * is needed in case one of the file names begins with a -.)

share|improve this answer
Short and sweet, thank you! Do you know where I can read about the -- modifier? – Znarkus Apr 30 '11 at 10:37
@Znarkus: -- to signify the end of options is a convention that most commands obey. E.g. tail -n +1 -- -f -g tells tail that -f and -g are files to read (operands) and not options. It's guideline 10 in the POSIX utility syntax guideline (a document intended for utility writers). I don't have a reading suggestion intended for end-users, I'd expect a good unix tutorial to cover it at some point. – Gilles Apr 30 '11 at 10:50

You can do it all in one with find:

$ find . -type f -not -name .htaccess -printf "\n%p\n" -exec cat {} \;

That tells find to find all files (-type f) in the current directory (.) except (-not) one named .htaccess (-name .htaccess). Then it prints (-printf) a newline followed by the filename (%p), and then runs cat on the file (-exec cat {} \;). That will give you output like:

Line 1

Line 1

Line 1
Line 2
Line 3

If you do this often it might be worth sticking it in a shell script or a function; I have one named cats that does exactly that:

for filename; do
    echo "\033[32;1m$filename\033[0m"
    cat "$filename"

It loops over each filename argument, prints out the filename (in bold green), and then cats the file:

Example screenshot

So then the command would just be:

$ find . -type f -not -name .htaccess -exec cats {} \+
share|improve this answer
The other was shorter, so accepted that. Excellent answer though, thank you! – Znarkus Apr 30 '11 at 10:37

If you want to fine tune and don't loose too much time with pipes, find and everything (altough being the most powerful toolchain you could ever find)

just try to use a for-loop, cat, etc.

share|improve this answer

To show content of all files in the current folder, try:

grep -vI "\x00" -- *

and similar, but recursively:

grep -vIr "\x00" -- .

The format would be: filename: content.

To have similar format as suggested, it would be:

grep -rvl "\x00" -- * | while read file; do printf "\n\n#### $file ####\n"; cat $file; done

Side notes:

  • Using NUL (\x00) in above examples prevents displaying binary files (which -I is actually doing, but we've to still use some pattern).
  • Using wildcard (*), it automatically ignores hidden files such as .htaccess.

See also: grep: display filename once, then display context with line numbers at Unix SE

share|improve this answer
Usually grep -r ^ is enough. – catpnosis Apr 8 at 18:48

You can use this:

cat $(find Directory/ -not -name *.htaccess)
share|improve this answer

Your Answer


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.