Filenames With Spaces In Linux

Back to Linux Tips and Guides page

Firstly, I should point out that Linux doesn't get on particularly well with spaces in file names when it comes to using commands in a Terminal Shell.

A space is more then just a space

When using some commands that specify a file name, such as cp for copying a file about cakes to a USB memory stick; a space is interpreted by cp as a seperator for a list of file names, as cp can copy several files in one go.

Example: ~$ cp baking cakes.pdf /mnt/usb

This above example will try copying two files: baking and also cakes.pdf into directory /mnt/usb - which is clearly not ideal, as neither of these two files exist!


To get around this we can use apostrophies wrapped around the file name, then the command knows that the spaces are part of the file name, rahter than seperators.

Fixed example: ~$ cp 'baking cakes.pdf' /mnt/usb