H
H
huk66392016-01-05 22:28:07
linux
huk6639, 2016-01-05 22:28:07

How to write a bash script that would only move certain files?

There are a large number of files whose names look like this: 01xxx.vvv 02xxx.vvv ... 999xxx.vvv. With some of the files you need to perform certain actions. There is an array of numbers corresponding to the numbers of the required files. Is it possible to write a bash script that would take only the necessary files (the names of which have numbers from the array) and move them to a folder?
I became attached to the bowl only because I would like to learn how to write in it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Muhammad, 2016-01-05
@muhammad_97

ls <from>| grep <regexp>| xargs mv <to>
Compose a regular expression here and substitute in place of <regex>.

P
pavlinux, 2016-01-06
@pavlinux

find -regex pattern -exec mv {} /dir \;
how is that

V
Victor Taran, 2016-01-11
@shambler81

And even better through xargs - it is many times faster and with the preservation of the directory structure

find . -regex ".*\.\(jpg\|jpeg\|gif\|png\|JPG\|JPEG\|GIF\|PNG\)" -print0 | xargs -0 cp --parents --target-directory 
./tmp/backup

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question