深度阅读

How to Deal With Spaces in Filenames on Linux

作者
作者
2023年08月22日
更新时间
9.12 分钟
阅读时间
0
阅读量

When dealing with filenames that contain spaces on Linux, it is important to properly quote or escape the spaces in order to avoid errors when running commands.

Here are a few ways to deal with spaces in filenames on Linux:

  1. Use double quotes (“”) or single quotes (‘’) to enclose the filename:
cp "my file" /path/to/destination

Or

cp 'my file' /path/to/destination
  1. Use backslashes to escape the spaces:
cp my\ file /path/to/destination
  1. Use tab completion to avoid typing the filename with spaces altogether:
cp my<tab>/file /path/to/destination

This will autocomplete the filename for you, escaping the spaces as necessary.

Keep in mind that different command line tools may require different quoting or escaping methods, so it’s important to consult the documentation when in doubt.

I hope this helps you deal with spaces in filenames on Linux!

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。