简体   繁体   中英

Linux move files from dir to dir by name mask

I am trying to move all files with names starts with SML from directory to another. Tried with

find /var/.../Images/ -name SML\\* mv /var/.../Images/Small but doesnt work

尝试find /var/.../Images/ -name SML\\* -exec mv {} /var/.../Images/Small/ \\;

I guess you want something like this:

dir=/path/to/your/Images
mkdir -p "$dir/Small"

find "$dir" -name "SML*" -not -wholename "$dir/Small/*" -exec mv {} "$dir/Small/" \;
  • Since the directory you move the files to is a subdirectory of the one you seach in, you need to exclude the files already moved there. So I added -not -wholename "$dir/Small/*"
  • To execute a command for each found file, you need -exec ... . The alternative would be to pipe your find results to a while read loop.
  • When using -exec , the found name can be referenced by {} .

See man find for a lot more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM