Move all .txt files into one directory

5,978

find solution:

find all -type f -name "*.txt" ! -path "all/txt/*" -exec echo mv -t all/txt '{}' \;
Share:
5,978

Related videos on Youtube

xRobot
Author by

xRobot

Updated on September 18, 2022

Comments

  • xRobot
    xRobot over 1 year

    I have almost 6000 directories with thousands of files:

    all/recup_dir.1/1.txt
    all/recup_dir.1/2.jpg
    ...
    all/recup_dir.5987/1.txt
    all/recup_dir.5987/2.txt
    ...
    

    and I want to move all .txt files in the all/txt folder. I have used this command:

    mv **/*.txt txt
    

    but I get this error:

    bash /bin/mv arg list too long
    

    How can I do?

    • stefan
      stefan about 6 years
      if you just move all .txt files from your example to a common folder, the ones with the same basenames (e.g., 1.txt) will overwrite each other. How do you want to resolve this conflict?
    • xRobot
      xRobot about 6 years
      @stefan I could rename it with 1-1.txt, 1-2.txt, 1-3.txt, ecc