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 [email protected]:/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 [email protected]:/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

相关推荐
itachi-uchiha14 分钟前
关于dropbear ssh服务
运维·ssh
家庭云计算专家17 分钟前
ONLYOFFICE协作空间3.1.1 企业版 介绍及部署说明:家庭云计算专家
运维·服务器·云计算·onlyoffice·协作空间
Ares-Wang22 分钟前
负载均衡LB》》HAproxy
运维·数据库·负载均衡
张海森-1688201 小时前
windows10搭建nfs服务器
linux
wanhengidc1 小时前
高防服务器能够抵御哪些网络攻击呢?
运维·服务器
Paddy哥2 小时前
linux 安装mysql8.0;支持国产麒麟,统信uos系统
linux·mysql·麒麟·统信uos·统信
G_whang2 小时前
VMware Workstation 与 Hyper-V 不兼容。请先从系统中移除 Hyper-V 角色,然后再运
linux
余辉zmh2 小时前
【Linux网络篇】:从HTTP到HTTPS协议---加密原理升级与安全机制的全面解析
linux·网络·http
凯勒姆3 小时前
6.linux文本内容显示cat,more,less
linux·运维·服务器
SailingCoder3 小时前
grafana-mcp-analyzer:基于 MCP 的轻量 AI 分析监控图表的运维神器!
运维·人工智能·typescript·node.js·grafana