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

相关推荐
-Harvey36 分钟前
ubuntu为Docker配置代理
linux·ubuntu·docker
thehunters41 分钟前
win10 ubuntu 使用Android ndk 问题:clang-14: Exec format error
android·linux·ubuntu
Ven%2 小时前
如何让后台运行llamafactory-cli webui 即使关掉了ssh远程连接 也在运行
运维·人工智能·chrome·python·ssh·aigc
迷茫的小技术4 小时前
OSPF使能配置
运维·服务器·网络
soragui4 小时前
【Ubuntu】想知道怎么通过命令行查看笔记本电池健康程度吗?
linux·ubuntu·电脑
小学导航员5 小时前
centos服务器 /1ib64/libm.so.6: version “GLIBc 2.27’ not found 异常
linux·服务器·centos
揽星逐月酒微醺5 小时前
find 查找文件grep匹配数据
linux·运维·服务器
银河麒麟操作系统5 小时前
【银河麒麟高级服务器操作系统】服务器异常重启故障分析及处理建议
linux·运维·服务器·安全·电脑
Codeking__5 小时前
Linux初识——基本指令
linux·运维·服务器
CodeJourney.6 小时前
Linux 基础应用指南:从入门到实践
linux