1

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?

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
  • Hi maybe it will help to you. https://stackoverflow.com/questions/10929453/read-a-file-line-by-line-assigning-the-value-to-a-variable – Mamed Mar 28 '18 at 13:03
  • 1
    Hi in this link, script read .txt file line by line, I want move files one by one ... – Cavad Pashayev Mar 28 '18 at 13:06
  • Is there a specific reason to do this one by one? Do you want to do some other actions before actually moving the file? – Jonathan Mar 28 '18 at 12:43

1 Answers1

1

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
Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56