Best News Network

Linux 101: Why file and directory names lack spaces

Jack Wallen explains why spaces in files and folder names aren’t always the best option in Linux.

linux penguin

Image: Jack Wallen

I cannot tell you how many times I get asked by collaborators, colleagues, friends and family, “Why do you never put spaces in file and folder names?” The answer to that question is generally met with either blank stares or cries of “What?” Way back when, in the mid-1990s, when I was still using Windows, spaces in file and folder names were commonplace for me. 

Then I made the switch to Linux in 1997, and everything changed on every level. That included the names I gave files and folders. Back then, creating a folder name with a space was in very bad form and could cause you all sorts of trouble navigating the directory structure. 

SEE: Linux service control commands (TechRepublic Premium)

For instance, take a directory named TEST DIRECTORY. If you issued the command mkdir TEST DIRECTORY, you wouldn’t be creating a directory named “TEST DIRECTORY” but two directories, TEST and DIRECTORY. To create “TEST DIRECTORY,” you’d have to issue the mkdir command with the name in double-quotes, as in mkdir “TEST DIRECTOR.” To change into that directory, you’d issue the command: 

cd "TEST DIRECTORY"

However, if you created the directory TEST_DIRECTORY, you wouldn’t have to go through the extra steps. Most Linux commands see every separate entry as an option, so mkdir TEST DIRECTORY would be taken as two commands—mkdir TEST and mkdir DIRECTORY

This issue isn’t nearly as problematic in a GUI. In fact, when working with a GUI, you can create files and directories with multiple spaces. If you’ll also be working from within the command line, I suggest you don’t because you won’t want to have to deal with the headache of accidentally deleting both the TEST and the TEST DIRECTORY directories. 

This issue can get a bit convoluted, so just remember to avoid using spaces in your Linux file and folder names and you’ll be okay. Get friendly with either the dash or the underscore and everything will be fine.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Also see

Stay connected with us on social media platform for instant update click here to join our  Twitter, & Facebook

We are now on Telegram. Click here to join our channel (@TechiUpdate) and stay updated with the latest Technology headlines.

For all the latest Technology News Click Here 

 For the latest news and updates, follow us on Google News

Read original article here

Denial of responsibility! NewsAzi is an automatic aggregator around the global media. All the content are available free on Internet. We have just arranged it in one platform for educational purpose only. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials on our website, please contact us by email – [email protected]. The content will be deleted within 24 hours.