Cavad Pashayev
Cavad Pashayev

Reputation: 11

Shell: move files one by one an other directory

I have 2 directory. doc1 and doc2 and I have a lot of files in the directory of doc1.

In the directory doc1, I have the files as:

cp01_01
cp02_01
cp03_01
cp04_01
...

I want move these files one by one from doc1 to doc2, in order to execute other commands between each mv. How can I do that?

Upvotes: 1

Views: 447

Answers (1)

Ronan Boiteau
Ronan Boiteau

Reputation: 10138

You can use for to loop over your file:

for file in doc1/cp*_* ; do
    mv "$file" "doc2/$(basename "$file")"
    echo "$file moved! Executing some other stuff..."
    # some other stuff
done

Upvotes: 1

Related Questions