Score:1

Move files with extension in diffrent structure

lk flag

I need move every file.tif to dir TIFF inside his parent dir.

    ├── 1
    │   ├── 240_01.tif
    │   ├── 240_02.TIF
    │   └── TEST
    │       └── syg_240_test_1.tif
    ├── 2-3
    │   ├── 2
    │   │   ├── 240_01.tif
    │   │   ├── 240_02.TIF
    │   │   └── TEST
    │   │       └── syg_240_test_1.tif
    │   └── 3
    │       ├── 240_01.tif
    │       ├── 240_02.TIF
    │       └── TEST
    │           └── syg_240_test_1.tif
    └── 4
        ├── 240_01.tif
        ├── 240_02.TIF
        └── TEST
            └── syg_240_test_1.tif

For example it's should be look like this:

├── 1
│   ├── TEST
│   │   └── syg_240_test_1.tif
│   └── TIFF
│       ├── 240_01.tif
│       └── 240_02.TIF
├── 2-3
│   ├── TEST
│   │   └── syg_240_test_1.tif
│   └── TIFF
│       ├── 2
│       │   ├── 240_01.tif
│       │   └── 240_02.TIF
│       └── 3
│           ├── 240_01.tif
│           └── 240_02.TIF
└── 4
    ├── TEST
    │   └── syg_240_test_1.tif
    └── TIFF
        ├── 240_01.tif
        └── 240_02.TIF

I try to use mv /path/*/*.tif/ /path/*/TIFF/*.tif but it doesn't work.

hr flag
The difficulty here is that you appear to want different operations depending on the depth of the file(s) - how should we know **programatically** whether to move files up one level or 2? What should happen to the "other" `TEST/syg_240_test_1.tif` file when you merge `2-3/2/TEST` and `2-3/3/TEST`?
Score:1
cn flag

Again, find may come to the rescue. You can selectively find tiff files in the first level subfolders, then use an -execdir command that moves the found file to a TIFF folder in the current directory.

You could call a little script that tests for the existence of the TIFF folder, or else creates it before moving all tiff files, but for this single time, it is probably easier to work in two steps: 1) make the TIFF folder in any of the folders you need and 2) move the TIFF files there

find . -maxdepth 1 -type d -path '*/*' -exec mkdir {}/TIFF \;

will find the folders "1", "2" etc provided your current directory is the one containing these folders, and create a TIFF directory in each of them. There will be an error message if the folder TIFF already exists.

A second command can then move all tiff files out to the newly created folders:

find . -type f -ipath '*/*/*.tif' -execdir mv {} TIFF \;

Here, we search for files only (-type f) in the folders "1", "2" etc, but not below, because of the file pattern (-ipath). -ipath as opposed to -path indicates that the match is case insensitive. The -execdir action performs the subsequent command, however while the current folder is that of the found file. {} stands for the found file. Because of the -execdir, this is the file's basename only. The file will be moved to the TIFF folder in the current folder.

Spaces in the file name will be properly handled by the {} token. There is no need to insert quotes, although you could.

mechmati avatar
lk flag
After used this command dir `TIFF` is in same level like `1` `2-3` `3`, but he should be inside thems (1,2-3,4). I got 1000 dirs, handmade is not good idea..
Whois_me avatar
us flag
You say 1000 dirs , are they all numbered to 1000?
mechmati avatar
lk flag
Every dir have random name
vanadium avatar
cn flag
You have to start in the right directory of course, because relative pathnames are in use. Or you need to adapt the command. I tested these, so for me, it worked.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.