Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
2  
Can you add an example of the text file list to your question. –  L. D. James Jul 27 at 14:34
    
@L.D.James, my file looks like this inside (after my edit taking out the unusefull part) /media/txk/TrimarDieu/1_Zik/0_0zikt/Joseph Jazz/Thelonious Monk/Thelonious Monk The Complete Prestige Recordings - 2 /media/txk/TrimarDieu/1_Zik/0_0zikt/Joseph Jazz/Thelonious Monk/Thelonious Monk The Complete Prestige Recordings - 3 /media/txk/TrimarDieu/1_Zik/0_0zikt/Joseph Jazz/Toni Esposito - Gente Distratta (In the preview looks all togheter, don't know how to copypaste different, but it is one path, one line) –  CaRoXo Jul 27 at 16:28
2  
Caroxo, thanks for your interest to contribute back to the community by having your solved questions marked as solved. This is something that only you can do. It's easy. Just look at the answer you're accepting and click on the check mark. People with similar problems can see this exchange as resolved and have a better time of getting their solution. –  L. D. James Jul 27 at 19:58

3 Answers 3

up vote 1 down vote accepted

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
share|improve this answer
    
Nice, it listed ok, but have same problem when I take out the echo, it Doesn't recognize the spaces in the path. –  CaRoXo Jul 27 at 16:18
    
Are you sure you remembered to put the double-quotes around the "$dir" variable? –  steeldriver Jul 27 at 16:36
    
Ok, sorry. Yes. It have worked. There was saying an error "Don't exist such directory", because it moved the first one and the subdirectories logically were not found. Your solution worked. Thanks a lot, and thanks also the others people suggestion. –  CaRoXo Jul 27 at 16:42

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.

share|improve this answer
    
Problem, the spaces in the paths are not recognized (and i cant edit each line for puting the \ before) –  CaRoXo Jul 27 at 16:16
    
Sorry I just forgot to use quotes, fixed now. –  kraxor Jul 27 at 19:57

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.

share|improve this answer
1  
This solution will not work if you have spaces in the directory names. –  kraxor Jul 27 at 14:55
    
Thanks kraxor. Looks better now? –  mikewhatever Jul 27 at 15:02
    
Not really. The problem is with the for loop itself, it will iterate through each word, not each line. –  kraxor Jul 27 at 15:07
    
You are right indeed, thanks for the tip. –  mikewhatever Jul 27 at 15:18
    
Actually I tryed (becouse i didn't read the comment of kraxor, and it doesn't do anything. Stays just with >, waiting and waiting. The other two options (yours @kraxor and Steeldriver ones) I had this problem with the spaces in the directory name. Thanks to all –  CaRoXo Jul 27 at 16:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.