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

相关推荐
网硕互联的小客服5 小时前
Windows2008 如何禁用FSO?
运维·服务器·网络·windows·安全
不惑_5 小时前
[特殊字符] 在 Linux 上设置 SQLite
linux·jvm·sqlite
塔能物联运维6 小时前
物联网运维中的多模态数据融合与智能决策优化技术
运维·物联网
xingyue_S6 小时前
LVS负载均衡群集(一) -- NAT模式
运维·负载均衡·lvs
淮北4946 小时前
如何在ubuntu调用exe文件
linux·运维·ubuntu
蒋星熠6 小时前
全栈开发实战指南:从架构设计到部署运维
运维·c++·python·系统架构·node.js·devops·c5全栈
HalvmånEver6 小时前
Linux:基础开发工具(一)
linux·运维·服务器·开发语言·学习·进阶学习
real_haha6 小时前
Fabric 学习资料总结 持续更新
运维·fabric
caijingshiye9 小时前
九科信息企业自动化智能体:打破知行割裂,让AI真正动手干活
运维·人工智能·自动化
HIT_Weston11 小时前
26、【Ubuntu】【远程开发】内网穿透:密钥算法介绍(二)
linux·运维·ubuntu