You are not logged in.

#1 2008-10-19 04:59:00

colbert
Member
Registered: 2007-12-16
Posts: 809

Shell-- how to move all except

In shell, say I have a folder with 100 files, all very different filenames, and I want to move all of them except a few. How do I accomplish this rather quickly??

Offline

#2 2008-10-19 05:34:06

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Shell-- how to move all except

Copy a list of all the files to a single text file ('ls -1 > somefile.txt' - make sure you unset any aliases for ls, like the default arch .bashrc). Look at the text file and delete any lines with files you don't want to copy. Pass it to xargs ('cat somefile.txt | xargs mv wherever'). Get rid of the text file.

Last edited by fflarex (2008-10-19 05:37:26)

Offline

#3 2008-10-19 06:14:12

pauldonnelly
Member
Registered: 2006-06-19
Posts: 776

Re: Shell-- how to move all except

Use find to pick the ones you want. Check returned list for correctness, then rerun with moving. Or most file managers probably have a way to invert the selection, for example, pressing * in mc.

find . -not \( -name conklin-demo.mp3 -or -name con1.bmp \)

Last edited by pauldonnelly (2008-10-19 06:15:48)

Offline

#4 2008-10-19 06:38:35

tesjo
Member
Registered: 2007-11-30
Posts: 164

Re: Shell-- how to move all except

Why not just mv the whole folder and then mv back the few individual files.

Offline

#5 2008-10-19 07:33:08

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Shell-- how to move all except

tesjo wrote:

Why not just mv the whole folder and then mv back the few individual files.

People like to complicate the hell out of everything smile


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#6 2008-10-19 07:42:16

colbert
Member
Registered: 2007-12-16
Posts: 809

Re: Shell-- how to move all except

Hehe, nah it's just the files are very large and oodles of them, plus they're on crappy old IDE drives.

Thanks for the help dudes smile

Offline

#7 2008-10-19 08:02:31

dav7
Member
From: Australia
Registered: 2008-02-08
Posts: 674

Re: Shell-- how to move all except

What I find helpful is something like this:

cd over-here
mkdir somedir
mv file1 file2 file3 somedir
mv * somewhere-else
cd somewhere-else/somedir
mv * over-here
cd ..
rmdir somedir

A bit involved, but it works tongue

-dav7


Windows was made for looking at success from a distance through a wall of oversimplicity. Linux removes the wall, so you can just walk up to success and make it your own.
--
Reinventing the wheel is fun. You get to redefine pi.

Offline

#8 2008-10-19 08:04:50

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: Shell-- how to move all except

In zsh you'd do something like that:

mv ^(a|b|c) /destination_dir

(that'd move everything from the dir except a, b and c)

Last edited by lucke (2008-10-19 08:06:41)

Offline

#9 2008-10-19 09:22:48

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: Shell-- how to move all except

colbert wrote:

Hehe, nah it's just the files are very large and oodles of them, plus they're on crappy old IDE drives.

Thanks for the help dudes smile

Well, in these situations you can't avoid a dual-pane file manager. Like midnight commander.


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

Board footer

Powered by FluxBB