Ubuntu: How to move directories that were listed in a .txt file?



Question:

I'm using a program to tag music that generates a .txt list of the skipped (untagged) folders that processes.

I just want to be able to take this list (that have the complete path for each folder) and move this listed folder somewhere /media/skipped/

I couldn't find with du command or find how to do it... And my capacities in CLI and in general with linux are very basics.

So thanks if someone can give me direction on my search, or some command to use...

Edit:

Ok... You are really awesome... thanks to all for your fast answers. Yes each line is a path (actually have some line before each importing time, that i erase, and before the path says "skipped folder" that i run a Find and Replace command in mousepad. So, only paths, one per line rests)

Edit2: Solution from @Steeldriver worked. I just need to edit further the .txt. This post can be marked as [Solved], i don't know how to. Thanks to all.


Solution:1

I'd suggest a while loop

while IFS= read -r dir; do    echo mv -t /media/skipped/ "$dir"   done < yourfile.txt  

The echo is there so you can test the command - if it runs OK and lists out the correct sequence of moves, remove the word echo to make it run for real.

Example:

$ ls -l olddir/  total 8  drwxrwxr-x 2 user user 4096 Jul 27 12:32 subdir  drwxrwxr-x 2 user user 4096 Jul 27 12:32 subdir with spaces  

with a list of files like

$ cat dirlist.txt   olddir/subdir with spaces  olddir/subdir  

then

$ while IFS= read -r dir; do mv -vt newdir/ "$dir"; done < dirlist.txt   `olddir/subdir with spaces' -> `newdir/subdir with spaces'  `olddir/subdir' -> `newdir/subdir'  

and verifying

$ ls -l newdir/  total 8  drwxrwxr-x 2 user user 4096 Jul 27 12:32 subdir  drwxrwxr-x 2 user user 4096 Jul 27 12:32 subdir with spaces  


Solution:2

You can use a command like this:

while read line; do mv "$line" /media/skipped/; done < directory_list.txt  

I am assuming that each line of the input file contains one directory entry.


Solution:3

xargs is handy for this:

xargs -d '\n' mv -t /destination/dir < file.txt  


Solution:4

You could use a for loop like so:

for i in `cat file.txt`; do cp -r "$i" /media/skipped/" && rm -r "$i"; done  

file.txt is the generated file, so you need to substitute the correct name.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »