0

In this directory listing below I'm trying to move all 'example*.file' into the 'test' directory.

I've tried doing something like mv * ./test/ but that only moves the folders and not just the files, I've looked in mv --help and couldn't find an option to ignore the folders. I've also tried cp without -r but it didn't work. and is there a way to touch files to multiple directories from the root directory, for example in the tree below, you'd be inside test then do touch to create files in all directories inside of it rather than just the root directory you are in.

$ tree ./test/
./test/
├── 1
│   └── example.file
├── 10
│   └── example (14th copy).file
├── 11
│   └── example (12th copy).file
├── 12
│   └── example (7th copy).file
├── 13
│   └── example (17th copy).file
├── 14
│   └── example (16th copy).file
├── 15
│   ├── example (14th copy).file
│   └── example (15th copy).file
├── 16
│   ├── example (12th copy).file
│   └── example (13th copy).file
├── 17
│   └── example (11th copy).file
├── 18
│   └── example (10th copy).file
├── 19
│   └── example (9th copy).file
├── 2
│   └── example (3rd copy).file
├── 20
│   └── example (8th copy).file
├── 3
│   └── example (5th copy).file
├── 4
│   └── example (4th copy).file
├── 5
│   └── example (8th copy).file
├── 6
│   └── example (11th copy).file
├── 7
│   └── example (13th copy).file
├── 8
│   └── example (another copy).file
└── 9
    └── example (copy).file

20 directories, 22 files
1
  • 2
    The * glob only matches items in the current directory - you'd need something like mv ./test/*/example*.file ./test/ to make * match all the directories directly under ./test Feb 6, 2020 at 22:17

1 Answer 1

1

Since the filenames are unique, and since the filenames contain funny characters (), find and xargs are the way to go, and the man pages to read.

find test -type f -print0 |\
  echo xargs -0 -r mv --target-directory=test

Remove the echo when you're happy with the results, and want to actually do the mv

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .