Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a file name containing spaces as an argument to a command-line program?

Whenever I try to add a file with whitespace in its name to git, it shows an Error as

"fatal: pathspec 'Tic' did not match any files"

Since I was New to git and Linux based terminal I have no idea how to do it.

Screen-shot or my error: enter image description here

like image 679
Ajithkumar_sekar Avatar asked Oct 24 '25 15:10

Ajithkumar_sekar


2 Answers

You should be able to quote the filename (eg. "file name"), or use an escape sequence (eg. file\< space >name).

like image 97
ergonaut Avatar answered Oct 27 '25 05:10

ergonaut


To expand on @ergonaut's correct answer, just for the sake of clarity, this is actually neither a git nor a Linux issue. This is just a general requirement for command lines across the board.

On any command line, each word (or in this case, string of words) is evaluated separately as either a command or a parameter to a command. So, for example, git's add command is expecting a single parameter to come immediately after it (a filename). In this case, the next word it sees is just "Tic". Since it's only looking for a single parameter, it stops evaluating anything else at that point and that's why it's complaining about not being able to find the "Tic" file. When the words are enclosed in quotes, the entire string is evaluated as a single parameter, therefore fixing the issue.

Always wrap filenames that contain spaces with quotes when using them on the command line. Or even better, avoid using spaces in filenames. :-)

like image 35
jeffdill2 Avatar answered Oct 27 '25 05:10

jeffdill2



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!