I want to read the text file and use the mv command.

Asked 2 years ago, Updated 2 years ago, 62 views


in a text file aaa.JPG
bbb.JPG ccc.JPG
·
·
·
I would like to use this text file to move all the file names listed here from one folder to another.

I think I can do it with the mv command, but how do I write it?

linux ubuntu

2022-09-30 21:35

3 Answers

I don't know the details, so I'll write a general example while complementing it.

/tmp/spam/ is the current directory, and you want to go to /tmp/eggs/ with the text file (test.txt) and aaa.JPG, bbb.JPG, ...At this time,

$pwd
/tmp/spam/
$ cat test.txt | xargs-n 1-I%mv%/tmp/eggs

and allow you to move files in each line of a text file to a destination.


2022-09-30 21:35

In Bash and zsh, $(<filename) allows you to expand the contents of a text file to the command line.

$mv$(<filelist.txt)/path/to/dest_dir


2022-09-30 21:35

It can be combined with the sh/bash for statement.

$for fin'cat filelist.txt`
>do
>mv$f DEST_DIR
> done


2022-09-30 21:35

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.