bash:files:copy_files_to_different_directory
Differences
This shows you the differences between two versions of the page.
bash:files:copy_files_to_different_directory [2022/06/13 10:15] – created peter | bash:files:copy_files_to_different_directory [2022/06/13 10:16] (current) – peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== BASH - Files - Copy files to different directory ====== | ====== BASH - Files - Copy files to different directory ====== | ||
+ | |||
+ | <code bash> | ||
+ | # | ||
+ | |||
+ | for filename in *; do | ||
+ | if [[ -f " | ||
+ | base=${filename%.*} | ||
+ | ext=${filename# | ||
+ | mkdir -p " | ||
+ | mv " | ||
+ | fi | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Copy all files by extension to single directory ===== | ||
+ | |||
+ | <code bash> | ||
+ | find . -name \*.txt -exec cp {} someDirectory \; | ||
+ | </ | ||
+ | |||
+ | or | ||
+ | |||
+ | <code bash> | ||
+ | find . -name " | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | * Problem with Moving Large Number of Files | ||
+ | * Linux systems have a predefined limit on the maximum number of arguments that can be used with a single command. | ||
+ | * This limit varies from system to system based on the stack size. | ||
+ | * Thus, if a very high number of files are being specified with the wildcard; e.g. over a hundred thousand files, it throws an error: **Argument list too long**. | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
bash/files/copy_files_to_different_directory.1655115352.txt.gz · Last modified: 2022/06/13 10:15 by peter