Linux scp hidden file issue

The .. pattern in the {.,}* expansion represents the parent directory (one level above the current directory). This causes the error because scp tries to include the parent directory, which is not what you intend.

Solution:

To avoid including .., you can modify the pattern to match hidden files and directories without the .. directory. Here's the corrected command:

bash 复制代码
scp -r fapuser@158.220.199.227:/home/fapuser/{.[!.],}* .
  • {.[!.],}* ensures that . followed by any character except . is included, which prevents .. from being matched.
  • This pattern will still match hidden files and directories like .bashrc and .config.

This should fix the issue with the unexpected .. directory error.

The reason hidden files aren't transferred is because the * wildcard doesn't match files that start with a dot (.) by default. To include those hidden files, you need to use the {.,}* pattern. Here's how it works:

  • * matches all non-hidden files (files that don't start with a dot).
  • {.,}* matches both hidden files (starting with a dot) and regular files. The {.,} part tells the shell to consider both an empty prefix ("") and a dot (".") as valid matches before the filename.

This way, hidden files like .bashrc will be included in the transfer.

In Bash (and most other shells), the * wildcard is expanded by the shell before the actual command (like scp) is executed.

Here's what happens:

  1. Wildcard Expansion : Bash interprets the * wildcard and expands it to match all the filenames in the specified directory that are not hidden (i.e., do not start with a dot .).
  2. Command Execution : Once the shell expands the wildcard, it passes the resulting list of filenames to the command (in your case, scp).

For example:

bash 复制代码
scp -r fapuser@158.220.199.227:/home/fapuser/* .

If /home/fapuser/ contains files file1, file2, and .bashrc, Bash will expand * to file1 file2 and not .bashrc, so only file1 and file2 will be passed to scp.

This is why you need to use {.,}* if you want to match both hidden and non-hidden files; Bash will expand that pattern to include hidden files as well.

🚀 Looking for reliable cloud servers? Check out @Vultr! Great performance, easy setup, and affordable pricing. Use my ref link to get started: https://www.vultr.com/?ref=7922375 🌍💻 #CloudComputing #Vultr

相关推荐
Sleepy MargulisItG29 分钟前
Linux 权限基本理解
linux
_F_y31 分钟前
Linux:自主shell编写
linux
gaize12131 小时前
服务器异常如何解决
运维·服务器
dragoooon341 小时前
仿muduo库实现高并发服务器-面试常见问题
运维·服务器·面试
Empty_7772 小时前
K8S-Job & Cronjob
java·linux·docker·容器·kubernetes
开***能2 小时前
ASI转Profinet网关助力包装全产业自动化
运维·自动化
Molesidy3 小时前
【Linux】【Imx6ull Pro】基于Imx6ull Pro开发板的Linux-C-C++编程记录
linux·嵌入式·嵌入式linux应用层
北京盛世宏博3 小时前
边缘计算赋能!机房机柜微环境温湿度快速响应控制方案
运维·服务器·网络
3DVisionary3 小时前
高精度三维扫描+自动化,新拓三维打造中小型工业零部件数字化检测新方案
运维·自动化·蓝光三维扫描·dic技术·复杂零部件的批量检测·模型试验·自动化和数字化测量
AI云原生3 小时前
在 openEuler 上使用 x86_64 环境编译 ARM64 应用的完整实践
java·运维·开发语言·jvm·开源·开源软件·开源协议