I believe there's a simple fix but cannot debug it out.

I have file called "file name with space" How do I cat this file from Linux bash ?

  • 3
    cat "file name with space" or cat file\ name\ with\ space
    – ctn
    Jun 12, 2013 at 18:22
  • 3
    cat "file with space" doesn't work!? Good luck.
    – shellter
    Jun 12, 2013 at 18:22
  • 1
    Sure: name your file file_name_with_underscore...
    – H2CO3
    Jun 12, 2013 at 18:27
  • @H2CO3 Why if it works if everythin is implemented well?
    – glglgl
    Jun 12, 2013 at 18:34
  • @glglgl Safe, convenient, cross-platform and idiomatic.
    – H2CO3
    Jun 12, 2013 at 18:35

5 Answers 5


Does putting quotation marks around the name not work?

cat "file name with space"

A third option would be

cat 'file name with space'

where the file name may contain everything but the '.

If it does, such as file n'ame, replace every ' with '\'':

cat 'file n'\''ame'

Use the escape character '\' like this

cat file\ name\ with\ space

Enclosing the file in double quotes should work i.e.

cat "file name with space" 

I have run into this problem on Linux and in Cygwin. The one thing I found that works is to enclose the name in double-quotes and to replace non-traditional characters with asterisks. For example:

tail File.basename.Job With Spaces.log


tail "File.basename.Job*With*Spaces.log"

I tried escaping the spaces with backslashes, whether unprotected, protected with double-quotes, or protected with single-quotes, and in all cases tail parsed the names at the spaces as though unprotected.

  • 1
    This is WRONG.  Three (slightly) different perfectly good (correct) answers have already been given; if you have a problem with them, try again (and make sure you do what they say).  But your answer will not work!! Feb 16, 2017 at 22:26
  • This IS a good answer. When you have filenames in a file and want to cp them in a for loop, you use the backquote and cat the files.(e.g. for i in cat bakuplocations; do cp -u "$i" .; done) Then, if the filenames have spaces it will not work any of the other suggestions except this one.
    – user890332
    May 15, 2019 at 19:20

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.