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

相关推荐
梦游钓鱼6 分钟前
pyshark安装使用,ubuntu:20.04
linux·运维·ubuntu
火龙谷9 分钟前
CentOS7将yum源更换为国内源教程
linux·centos
战族狼魂33 分钟前
CentOS 上安装各种应用的命令行总结
linux·运维·centos
学Linux的语莫1 小时前
ansible变量
linux·运维·服务器·ansible
北京迅为1 小时前
【北京迅为】iTOP-4412全能版使用手册-第十二章 Linux系统编程简介
linux·嵌入式硬件·4412开发板
清源妙木真菌1 小时前
Linux:进程控制
linux
爱吃喵的鲤鱼1 小时前
Linux——文件系统清尾、动静态库
linux·运维·服务器
最数据2 小时前
Linux或者Docker中时区查询和修改(差8小时问题)
linux·运维·服务器·docker·.net
皓月盈江2 小时前
Linux宝塔部署wordpress网站更换服务器IP后无法访问管理后台和打开网站页面显示错乱
linux·服务器·wordpress·无法访问wordpess后台·打开网站页面错乱·linux宝塔面板·wordpress更换服务器
KeyBordkiller2 小时前
PVE相关名词通俗表述方式———多处细节实验(方便理解)
linux·服务器·网络