Author Topic: [SOLVED] Is it possible to use mv in terminal to recursivley move a certain...  (Read 2221 times)

0 Members and 1 Guest are viewing this topic.

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 2063
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards
I an trying to move files of a certain filetype from many folders to one folder of a specific filetype, such as MKV, MP3, AVI, PDF etc.. etc..
I am using a file recovery program to recover files and it saves them in batches of around 500 of multiple filetypes.
What I want to do is put each filetype into their own folder.

I am currently doing this manually, which is going to take a lonnnnnng time as there's nearly 1000 folders so far.

How can I do this in terminal using mv recursively (if it can do that).
« Last Edit: August 19, 2018, 10:05:26 pm by pooky2483 »

Kubuntu 16.04LTS 64bit|KDE 4.14.13|QT 4.8.6|Linux 4.15.0-32-generic|M5A78L-M USB3|BIOS 2101|AMD PhenomII X4 965 3400+|P8H77-I Motherboard NIC|32.0GB PC3-10600 1333Mhz CL9 ( 9-9-9-24 ) DDR3

Offline Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 17820
  • Karma: 459
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
I take it they files have extensions (so are searchable by name '*.mp3' etc.) ?

try
Code: [Select]
find /path/to/directory/to/search -type f -iname "*.mp3" -exec mv {} /path/to/director/to/save \;
that's a case insensitive search, so will move all files with .MP3 and .mp3 and .Mp3 and .mP3

if you want it case sensitive
Code: [Select]
find /path/to/directory/to/search -type f -name "*.mp3" -exec mv {} /path/to/director/to/save \;

you might want to test it first with cp (copy) instead of mv (move), so
Code: [Select]
find /path/to/directory/to/search -type f -iname "*.mp3" -exec cp {} /path/to/director/to/save \;



Personally I'd just use something like the GUI gnome-search-tool to search the location by extension .. then copy/paste from the results window.
« Last Edit: May 16, 2018, 12:44:27 am by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 2063
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards
What I've done to move the contents of each folder to one folder so I can handle all the files easily, one extension at a time.
I used;
Code: [Select]
mv /media/pooky2483/INT-02/Recovered_Files/recup_dir.{841..880}/*.* /media/pooky2483/INT-02/Recovered_Files/MOVED
I found for some reason that I can only move the contents in blocks of 30 (why is this?)

I then used;
Code: [Select]
mv /media/pooky2483/INT-02/Recovered_Files/MOVED/*.jpg /media/pooky2483/INT-01/Recovered\ Files/JPG

And just changed the extension and repeated the command.

[EDIT]
Just noticed an error and will edit in a min.
Fixed error.
« Last Edit: May 18, 2018, 04:52:29 pm by pooky2483 »

Kubuntu 16.04LTS 64bit|KDE 4.14.13|QT 4.8.6|Linux 4.15.0-32-generic|M5A78L-M USB3|BIOS 2101|AMD PhenomII X4 965 3400+|P8H77-I Motherboard NIC|32.0GB PC3-10600 1333Mhz CL9 ( 9-9-9-24 ) DDR3

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 2063
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards

Personally I'd just use something like the GUI gnome-search-tool to search the location by extension .. then copy/paste from the results window.

I tried that program but it was taking far too long due to the amount of files... almost 500,000. It was taking over 24 hours and still going.

Kubuntu 16.04LTS 64bit|KDE 4.14.13|QT 4.8.6|Linux 4.15.0-32-generic|M5A78L-M USB3|BIOS 2101|AMD PhenomII X4 965 3400+|P8H77-I Motherboard NIC|32.0GB PC3-10600 1333Mhz CL9 ( 9-9-9-24 ) DDR3

Offline userxbw

  • Jr. Member
  • **
  • Posts: 2
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
I an trying to move files of a certain filetype from many folders to one folder of a specific filetype, such as MKV, MP3, AVI, PDF etc.. etc..
I am using a file recovery program to recover files and it saves them in batches of around 500 of multiple filetypes.
What I want to do is put each filetype into their own folder.

I am currently doing this manually, which is going to take a lonnnnnng time as there's nearly 1000 folders so far.

How can I do this in terminal using mv recursively (if it can do that).
because of the amount of files, write a script that you can get control of your files.
Code: [Select]
#!/bin/bash

working_dir=
move_to=

if [[ -z "$1" ]] ;
then
{
  echo "How many file you want to run this time?"
  exit   
}
fi
count=$1
echo "$working_dir"

while read f ;
do
#echo "$f"
#new dir struct
new_place=${f/$working_dir/$move_to}
echo "NEW: $new_place"
filename=$(basename "$f")     
  extension=${filename##*.}
  filename=${filename%.*}

echo $filename
echo $extension
echo $filename

if [[ "$extension"  == "mp4" ]] ;  then
{
#mkdir here then move it
#mkdir -p "$new_place"
#mv "$f" "$new_place"
echo "$f"
echo "$extension
}
elif [[ "$extension"  == "png" ]] ;  then
{
#mkdir here then move it
echo "$f"
echo "$extension

}
fi
((count++))
[[ "$count" -eq "$1" ]]  && exit
echo "count $count"

done <<<"$(find "$working_dir" -type f )" #-name "*.mkv" -o -name "*.mp4" -o -name "*.jpg")"
modify it to your needs.

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 2063
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards
Did it manually in the end.

Kubuntu 16.04LTS 64bit|KDE 4.14.13|QT 4.8.6|Linux 4.15.0-32-generic|M5A78L-M USB3|BIOS 2101|AMD PhenomII X4 965 3400+|P8H77-I Motherboard NIC|32.0GB PC3-10600 1333Mhz CL9 ( 9-9-9-24 ) DDR3

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal