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

相关推荐
Predestination王瀞潞2 分钟前
JDK安装及环境变量配置
java·linux·开发语言
LF3_19 分钟前
配置ssh免密登录
运维·ssh
再睡一夏就好30 分钟前
深入Linux线程:从轻量级进程到双TCB架构
linux·运维·服务器·c++·学习·架构·线程
小小药36 分钟前
09-vmware配置虚机连接互联网-nat模式
linux·运维·centos
广东大榕树信息科技有限公司40 分钟前
如何通过国产信创动环监控系统优化工厂环境管理?
运维·网络·物联网·国产动环监控系统·动环监控系统
Bright Xu1 小时前
Qemu 安装 LoongArch架构 Fedora Remix F42 Linux系统
linux·loongarch·国产cpu
莫白媛1 小时前
Linux创作笔记综合汇总篇
linux·运维·笔记
studytosky1 小时前
Linux系统编程:深度解析 Linux 进程,从底层架构到内存模型
linux·运维·服务器·开发语言·架构·vim
java_logo2 小时前
Crawl4AI Docker 容器化部署指南
运维·docker·容器·crawl4ai·crawl4ai部署文档·crawl4ai部署教程·crawl4ai部署
wdfk_prog2 小时前
[Linux]学习笔记系列 -- [fs]buffer
linux·笔记·学习