linux - 如何将特定文件复制到特定文件夹 linux bash

标签 linux bash

  1. Create 50 files whose names are from 1 to 50.
  2. Create five folders (0, 10, 20, 30, 40).
  3. Copy those 50 files into folders based on their name (for example, file 21 will go to folder 20).

我已经创建了这些文件和文件夹,但不知道如何将特定文件移动到特定文件夹。我试着写

cp {1..9} /home/user/folder

但这是 Not Acceptable 。是否可以使用 ifelif

最佳答案

cp {1..9} /home/user/folder

这会起作用,除非您应该指定要复制到的正确文件夹。也许您指的是其中之一?

cp {1..9} /home/user/folder/0
cp {1..9} 0

另一种方法是使用通配符。 * 匹配任何字符串,? 匹配任何一个字符。例如,2? 将匹配文件名 2029

关于linux - 如何将特定文件复制到特定文件夹 linux bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41106259/

相关文章:

python - 循环打印

bash - 如何在 bash 中引用 glob 扩展文件名?

bash - Azure函数: Timeout When I Call "func new"

linux - 如何在 bash 中评论参数列表

调用 mktime() 无明显原因返回 -1

c++ - 使用Linux pread可以避免 “unavailability of data for reading written by a different thread”吗?

linux - XARGS、GREP 和 GNU 并行

linux - 如何限制操作系统中的中断次数?

windows - 如何从 Bash for Windows 10 运行 .bat 或 .cmd 文件

bash - 在 unix shell 中更改目录(特殊字符)