Cannot cat file which has space in name in linux
64,533
Solution 1
Does putting quotation marks around the name not work?
cat "file name with space"
Solution 2
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'
Solution 3
Use the escape character '\' like this
cat file\ name\ with\ space
Solution 4
Enclosing the file in double quotes should work i.e.
cat "file name with space"
Related videos on Youtube
Author by
Maulzey
Updated on September 18, 2022Comments
-
Maulzey over 1 year
I believe there's a simple fix but cannot debug it out.
I have file called "
file name with space
" How do Icat
this file from Linux bash ?-
Admin almost 11 years
cat "file name with space"
orcat file\ name\ with\ space
-
shellter almost 11 years
cat "file with space"
doesn't work!? Good luck. -
H2CO3 almost 11 yearsSure: name your file
file_name_with_underscore
... -
glglgl almost 11 years@H2CO3 Why if it works if everythin is implemented well?
-
H2CO3 almost 11 years@glglgl Safe, convenient, cross-platform and idiomatic.
-
ganesh almost 11 yearsA fourth option would be to change the IFS.
-
-
Scott - Слава Україні over 7 yearsThis 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!!
-
user890332 about 5 yearsThis 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.