Quote filenames so the shell passes the intended path as one argument instead of splitting it at spaces or treating wildcard characters as patterns. In Bash, write a literal name as 'report final.txt' and quote a filename variable as "$file". The quote marks are shell syntax: Bash removes them after they have done their job.
What quoting changes
The shell interprets your command before the program receives its arguments. In Bash, quoting removes the special meaning of enclosed characters during that interpretation. It does not add quote marks to the filename or send them to the command. The Bash manual’s Quoting section describes quoting as a way to remove characters’ special meaning to the shell.
Without quotes, an expanded value containing spaces can undergo word splitting: one intended path may become several arguments. Unquoted wildcard characters such as *, ?, and [ may then undergo pathname expansion, where Bash replaces the pattern with matching filenames. The order and rules are documented in the Bash manual’s Shell Expansions section.
How to quote a filename typed into a command
Use single quotes for a literal name
When the name contains no apostrophe, single quotes are a straightforward way to preserve it literally:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
cat 'report final.txt'
Characters inside single quotes keep their literal meaning to Bash. This also matters when a filename contains pattern characters. For example, to refer to a file literally named draft[1].txt, quote it:
cat 'draft[1].txt'
Without quotes, the brackets can be treated as pattern syntax during pathname expansion rather than as part of the intended filename.
Rank #2
Use double quotes when you need expansion
Double quotes also preserve spaces and most special characters, while still allowing parameter expansion and command substitution. For example:
cat "report final.txt"
Unlike single quotes, double quotes do not make every enclosed character literal: $ and backticks can still introduce expansions, and backslashes retain special meaning in specified cases. For ordinary variable-based paths, double quotes are usually the useful choice.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsHandle apostrophes in literal names
A single quote cannot appear directly inside a single-quoted string. One Bash way to write a literal apostrophe is to close the quoted portion, add an escaped apostrophe, then reopen single quotes:
cat 'owner'''s notes.txt'
Shell completion can also help insert the necessary quoting or escaping for an existing filename.
Rank #4
How to pass a filename stored in a variable
Quote the expansion where it is used as an argument:
file='report final.txt'
cat "$file"
The quotes around the assignment value make the assignment clear; the crucial protection is around $file in the command. Do not put quote characters into the variable’s value expecting them to protect it: quote marks must surround the expansion in the command itself.
Recommended Free Tools
Best Value
In Bash, parameter expansion happens before word splitting and pathname expansion. An unquoted $file can therefore split at spaces, and wildcard characters in its value can be treated as a pattern. The quoted form "$file" keeps the expansion as one argument through those stages. These rules apply to results of particular expansions, not to every unquoted literal word; special constructs such as "$@" also have their own behavior.
Quoting is not the same as protecting every command argument
Quoting protects the boundary between the shell and the program: it helps ensure the program receives a path as one argument. The program then applies its own rules. If a filename begins with -, a command may interpret it as an option even when it was quoted. Where that command supports it, use its -- end-of-options convention, for example command -- "$file". Check the specific command’s documentation; quoting alone does not turn an option-looking argument into a filename for every program.
What happens when an unquoted wildcard matches nothing?
Bash’s default behavior is to leave an unmatched pattern unchanged. Shell options can change that: nullglob removes an unmatched pattern, while failglob reports an error and prevents the command from running. For a filename that literally contains *, ?, or brackets, quoting avoids asking Bash to treat those characters as a pattern in the first place.
When filenames move through scripts or text output
Quoting an expansion is essential when passing a path to a command, but it does not make every way of recording or exchanging filenames safe. Filenames can contain characters that make a simple one-name-per-line format ambiguous. If a script needs to handle arbitrary names, use an interface designed for that purpose rather than assuming line-oriented text is sufficient. GNU Coreutils documents filename display formats, including shell-oriented quoting styles, in its Formatting the file names section; select options according to the specific command and the shell that will consume the output.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




