Search code examples
shellmove

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?


Solution

  • 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