-1

i have a lot of files 30k directories, 21k files inside direrctories and subdirerctories of txt files with the same name

     ├── cases__in_africa
        │   ├── 2020/10/01.txt
        │   ├── 2020/10/02.txt
        │   ├── 2020/10/03.txt
        │   └── 2020/10/04.txt
        ├── death_in_africa
        │   ├── 2020/10/01.txt
        │   ├── 2020/10/02.txt
        │   ├── 2020/10/03.txt
        │   └── 2020/10/04.txt
2926 directories, 21646 files

i want to search for all files inside a lot of subdirerctories and than rename them to other unique name to move them to other directory.

This command not showing the duplicate files

find . -name "*.txt" -exec mv  "{}" ./all \;
ben
  • 25
  • 1
  • 10
  • Use `mv -v` instead of `mv` and consider writing a [Python](http://python.org/) or a [GNU guile](https://www.gnu.org/software/guile/) script. Of course, you'll need to read documentation before doing that. See also [syscalls(2)](https://man7.org/linux/man-pages/man2/syscalls.2.html), [nftw(3)](https://man7.org/linux/man-pages/man3/nftw.3.html) and [inode(7)](https://man7.org/linux/man-pages/man7/inode.7.html) – Basile Starynkevitch Oct 10 '20 at 06:17
  • mv: './all/01.txt' and './all/01.txt' are the same file the same problem – ben Oct 10 '20 at 06:19
  • How do you want to rename `2020/10/01.txt`? – anubhava Oct 10 '20 at 06:25
  • as i describe search and rename theme with unique name the 21646 files from 2926 directories and then move them to another place so i did a search and I can move but when i move it show me only 164 files from 21k files – ben Oct 10 '20 at 06:28
  • That is because all files named, e.g. `2020/10/04.txt` overwrite files of the same name moved to the `./all` directory. You need to append something to each file name that will make them unique, e.g. `cases__in_africa_2020/10/04.txt` of take a hash of the file, use milliseconds since epoch or something. – David C. Rankin Oct 10 '20 at 06:32
  • Please add your desired output (no description) for that sample input to your question (no comment). – Cyrus Oct 10 '20 at 06:42
  • the out that i want is the entire 21k files but ii have only 164 file days [all/0[1...30}txt] and other same files names – ben Oct 10 '20 at 06:47
  • There is a simple solution using `rename` here... https://stackoverflow.com/a/56579912/2836621 – Mark Setchell Oct 12 '20 at 10:17

2 Answers2

0

If you're looking for sequential naming, you can do it like this with the assumption that the target directory all does exist in your current directory.:

for file in $(find ./ -type f -name "*.txt"); do ((count++)) ; mv $file ./all/${count}.txt; done
1218985
  • 7,531
  • 2
  • 25
  • 31
0

i find this helpful https://askubuntu.com/questions/1003554/how-to-rename-all-jpg-files-in-all-subdirs-wich-contains-dash-in-linux

find -name '*.txt' -exec bash -c 'mv  "{}" "$RANDOM.txt"' \;
ben
  • 25
  • 1
  • 10
  • You should bear in mind that RANDOM only gives 32,768 different numbers so you'll almost certainly get collisions with calling it 21,000 times. – Mark Setchell Oct 12 '20 at 08:06