How to Read a Filename with Spaces in Linux

4624570-ba2fa753060da7f3.png
Manage file name with spaces in linux

It's not very common in Linux to handle filename with spaces but sometimes files copied or mounted from windows would end up with spaces.

While it is not recommended to have file names with spaces, let discuss how to manage filename with spaces in a Linux system.

We will cover how to create, read and copy a file which has spaces in their filename.

1) Creating file names with spaces

To create files with spaces in file names, run the command as shown

$ touch'firstname secondname'

For example, to create a file called 'linoxide docs' use the syntax below

$ touch 'linoxide docs'

Output

4624570-2fb98538f0648bec.png
create and view files with spaces

If you want to view such a file with space in the file name, use the same principle of enclosing the file names inside the quotation marks.

2) Read a File with spaces in filename

You can use 'cat' command or open the document using your preferred text editor such as vim, nano or gedit.

$  cat 'linoxide docs'

Alternatively, you can use the syntax below

$ cat file\ name\ with\ spaces

Let's add some text to the 'linoxide docs' file

$ echo "Hello guys! Welcome to Linoxide" >> 'linoxide docs'

To view the file execute the command below

$ cat linoxide\ docs

Output

4624570-bf3210e97cb40bad.png
cat file names with spaces

3) Creating directory names with spaces

To create directory names with space in between use the syntax below

$ mkdir firstname\ secondname

Please note the space after the backslash

For example, to create a directory called 'linoxide files' run

$ mkdir linoxide\ files

Output

4624570-241bbc0a68ad16b6.png
create directory names with spaces

4) Navigating to a directory with spaces in the directory name

To navigate to a directory with spaces in its directory name, use the syntax below

$ cd  directory\ name

To navigate to the directory 'linoxide files' execute the command below

$ cd linoxide\ files
4624570-86aa41f07c0c79b5.png
cd into directory with directory name with spaces

5) Copying a directory with spaces in the directory name

To copy a directory with spaces in its directory name to a different location use the syntax below

$ cp -R directory\ name  /destination/path

OR

$ cp -R 'directory name'  /destination/path/

For example to copy 'linoxide files' to /home/james path execute

$ cp -R 'linoxide files'  /home/james/
4624570-c7596057cc144513.png
copy directory with spaces in directory name

or

$ cp -R linoxide\ files /home/james
4624570-869623c6acac10b7.png
copy directory with spaces in directory name-2

Hope this article explained well on how to manage filename with spaces. Thanks for taking the time to read this article and please leave your comments.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值