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

相关推荐
bosins5 分钟前
WSL 迁移指南:如何将 Linux 环境完整复制到另一台电脑
linux·运维·服务器
IT利刃出鞘8 分钟前
Docker Compose--安装WordPress--方法/示例
运维·docker·容器
企鹅的蚂蚁2 小时前
LubanCat RK3588 实时 Linux 开发(六):启用 gs_usb 驱动并完成 USB-CAN 收发
linux·rk3588·linux驱动·socketcan·gs_usb·usb-can
2601_962299882 小时前
Linux执行Python脚本方法
linux·python·脚本·解释器·shebang
snow@li2 小时前
服务器运维:Linux命令速查手册(全景梳理)
linux·服务器·网络
handler012 小时前
【Linux】线程与虚拟内存的底层世界
linux·运维·服务器·c++·线程·虚拟地址空间·共享内存
新时代牛马2 小时前
实时 Linux:PREEMPT_RT、延迟来源与观测
linux·运维·服务器
微露清风3 小时前
# Linux 进程全景:从 PCB 到 O(1) 调度队列
linux·服务器
H_oRIZoN_3 小时前
Linux入门DAY38(手写 HTTP 客户端抓取天气 + 简易 HTTP 服务器实现元器件 Web 系统)
linux·linux应用编程
zhexunnb3 小时前
深挖SAP系统模块价值,助力无锡制造企业打通数字化全链路
运维