Author Topic: Problems figuring out how to move files and also keeping the same dir structure  (Read 232 times)

0 Members and 1 Guest are viewing this topic.

Offline pooky2483

  • Hero Member
  • *****
  • Posts: 2092
  • 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'm having problems with the mv command in terminal.
Basically what I want to do is similar to a copy but only a certain file type and keeping the same directory structure.
« Last Edit: November 19, 2018, 12:43:49 pm by pooky2483 »

Kubuntu 16.04LTS 64bit|KDE 5.36.0|QT 5.6.1|Linux 4.15.0-39-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: 18002
  • Karma: 465
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
AFAIK there is no way to directly "move" the files, you'd need to "copy" them, then "delete" them from the source.

So lets say you wanna copy all ".pdf" files:
Code: [Select]
find /path/to/source/directory -name '*.pdf' -xtype f -exec cp -v --parents -t /path/to/destination/directory {} +
then once you're sure you have them all in the target directory, you COULD delete the originals from the source directory
Code: [Select]
find /path/to/source/directory -name '*.pdf' -xtype f -exec rm -v {} +
but instead I'd suggest you install trash-cli
Code: [Select]
sudo apt-get install trash-cli
then instead of DELETING them from the source directory, instead TRASH them:
Code: [Select]
find /path/to/source/directory -name '*.pdf' -xtype f -exec trash {} +
you'll now find them in the trash, so you can recover them if necessary.
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: 2092
  • Karma: 0
  • Gender: Male
  • Slowly getting the hang of it.
    • View Profile
    • Get your FREE Ubuntu stickers here. I'm the UK address
    • Awards
Does that put them in one single directory or nested as I'd prefer it to be nested.

Or another way I could do it would be to make a complete copy and then delete all but what I want, which is the zip & 7z files.

Kubuntu 16.04LTS 64bit|KDE 5.36.0|QT 5.6.1|Linux 4.15.0-39-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: 18002
  • Karma: 465
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
nested .. it preserves directory structure (as requested).
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal