LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-15-2006, 04:13 PM   #1
surfbass
Member
 
Registered: Dec 2004
Posts: 33

Rep: Reputation: 15
excluding files and 'mv'


What if I have a directory that has half the files .tar.bz2 and the rest would be a mix of directories, and numerous of extensions. How could I move all these 'mixed' files to another directory? I want to move all of them except the .tar.bz2. What would the command string be? I looked in the man pages but I couldn't find anything. Any tips?
 
Old 07-15-2006, 04:28 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
find -not -name "*.tar.bz2" -exec mv {} /path/to/new/home \;



Cheers,
Tink
 
Old 07-15-2006, 04:30 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You could try something like this:

mv `ls | grep -v tar.bz2` /new/location

The part between the backticks (ls | grep -v tar.bz2) is executed first, this should give you all the files/dirs except tar.bz2 file. These are give to mv and moved to /new/location.

Try the ls part first, before feeding the output to mv.

Hope this helps.
 
Old 07-15-2006, 07:59 PM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Tinkster's find will probably work better, but will NOT preserve a directory structure. Druuna's command would also discard any file with 'tar.bz2' ANYWHERE in the filename, not just at the end (admittedly an unlikely occurance). To 'anchor' the pattern to the end, try
Code:
mv `ls | grep -v 'tar.bz2$'` /destination
. The $ requires it to also match the end of each filename. To include hidden files, add -A to the ls.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
remove files excluding those with specified extensions Melsync Linux - General 17 08-14-2015 05:16 AM
Complex cp : only *.jpg files while excluding DIRs LancerNZ Linux - General 3 02-16-2005 03:12 AM
help with the 'mv' command please Lleb_KCir Linux - General 3 07-20-2004 11:21 PM
Excluding directories from zip files jonathanztaub Linux - General 1 05-17-2004 02:17 AM
tar and excluding files murshed Linux - Newbie 7 03-15-2003 02:32 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration