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

相关推荐
7***q6081 天前
在linux(Centos)中Mysql的端口修改保姆级教程
linux·mysql·centos
云渠道商yunshuguoji1 天前
亚马逊云渠道商:怎么使用Spot实例实现成本降低70%?
运维·架构
2501_921939261 天前
11.25Nginx服务器和Wordpress服务器
运维·服务器·nginx
用户476022022781 天前
机器配置免密切root
linux
dntktop1 天前
搜索+计算+插件…这个“全能管家”让你告别80%的桌面图标
运维·windows·自动化·编辑器
ALex_zry1 天前
Consul全方位入门指南:第二阶段—— 实操。Consul核心功能与项目集成
运维·docker·微服务·云原生·架构
wanhengidc1 天前
云手机中分布式存储的功能
运维·服务器·分布式·游戏·智能手机·云计算
上班日常摸鱼1 天前
防火墙高级配置完整教程:端口映射+访问控制策略+iptables规则编写
运维
翼龙云_cloud1 天前
亚马逊云渠道商:AWS Shield和传统防火墙怎么选?
运维·服务器·云计算·aws
zzzsde1 天前
【Linux】基础开发工具(2):vim补充说明&&gcc/g++编译器
linux·运维·服务器