LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 09-21-2008, 06:06 PM   #1
faizlo
Member
 
Registered: Sep 2008
Location: USA
Distribution: Linux Mint Qiana
Posts: 190

Rep: Reputation: Disabled
getting files except those with certain extension


Peace,

I have a root directory which has a big number of other subdirectories and contains a big number of files. I want to copy all these files and directories to another folder (keeping the same hierarchy) except those files with a certain extension, say .txt, files - how may I do this?

Thanks,

faizlo
 
Old 09-21-2008, 06:20 PM   #2
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 97
Placing an exclamation mark before a find condition reverses its logic -e.g.:

find / ! -name "*.txt" ! -name "*.doc"

... will return the filepaths of all files whose names do not end with .doc or .txt - this provides a list which can then be used in a for loop:

Code:
#note that those are back-ticks round find statement, not single quotes
for file in `find / ! -name "*.txt" ! -name "*.doc"` 
do
    cp $file ${newdir}$file
done

Last edited by Robhogg; 09-21-2008 at 06:36 PM.
 
Old 09-21-2008, 06:37 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,819
Blog Entries: 1

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
find / ! -name '*.txt' ! -name '*.doc'
 
Old 09-21-2008, 06:40 PM   #4
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Please dont double post - especially when your question has already been answered

http://www.linuxquestions.org/questi...f-cert-671383/
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
remove all files with same extension? scratchnz Linux - General 1 11-04-2005 03:40 AM
files with extension rar ankscorek Linux - Software 5 07-25-2005 09:41 PM
Extension files BC1 Linux - Software 5 12-20-2004 03:41 AM
What to do about these files with .new extension? Slovak Slackware 1 11-23-2004 04:50 PM
How program to read files with extension .dat y .cfg files COMTRADE in fedora 1? ivonne Linux - Software 0 11-22-2004 11:42 AM


All times are GMT -5. The time now is 08:24 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration