Using ‘&’ in a Directory Name – Command Line Tips

bashcommand line

i have a directory name with ISO&Emulator having some Important Files. and this directory is in different partition, and partition not showing in my FileManager(Nautilus). so i mount my partition and access it from terminal, but i can't get into directory because of its name.

when i tried to change directory:

cd ISO&Emulator


[1] 1635
bash: Emulator: command not found
bash: cd: ISO: No such file or directory
[1]+  Exit 1

its taking directory name as a command.
any ways for access this directory from terminal?

how to fix this?

Best Answer

You should quote the file or directory name, that contains special characters, when you using it:

cd 'ISO&Emulator'
cd "ISO&Emulator"

Or escape (or quote) just the special character:

cd ISO\&Emulator    
cd ISO'&'Emulator  
cd ISO"&"Emulator

In most cases you can use the auto-completion function:

cd ISOTab ↹

Unlike the single quote marks the double quote marks are applicable when the name contains a variable:

cd "$HOME/ISO&Emulator"