LinuxQuestions.org
Help answer threads with 0 replies.
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


Reply
  Search this Thread
Old 07-20-2008, 06:01 AM   #1
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Rep: Reputation: 30
list all files except .xml files


hi
i want to list all files except .xml files.
 
Old 07-20-2008, 06:05 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
ls | grep -v *.xml?
 
Old 07-20-2008, 06:08 AM   #3
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Nylex View Post
ls | grep -v *.xml?
NO it does not work.Why do use grep. i just want to display all files except files which have .xml extension.
 
Old 07-20-2008, 06:11 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by babu198649 View Post
NO it does not work.
Hmm, so it doesn't. I'm not sure why though :/. ls | grep -v xml should do it.
 
Old 07-20-2008, 06:14 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Code:
ls --hide=*.xml
 
Old 07-20-2008, 06:16 AM   #6
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Original Poster
Rep: Reputation: 30
could u please tell me how grep could be used in finding files.
 
Old 07-20-2008, 06:17 AM   #7
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You don't use grep to find files, you use it to find patterns.
 
Old 07-20-2008, 06:17 AM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by Nylex View Post
Hmm, so it doesn't. I'm not sure why though :/. ls | grep -v xml should do it.
It didn't work because the pattern *.xml expands to all the names of the XML files. The resulting command was something like:
Code:
ls | grep -v file1.xml file2.xml file3.xml
where file1.xml is the pattern to search inside file2.xml, file3.xml along with the output of the ls command.
 
Old 07-20-2008, 06:18 AM   #9
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by colucix View Post
Code:
ls --hide=*.xml
i get errors.

Code:
[robert@localhost ~]$ ls --hide=*.xml
ls: option `--hide-control-chars' doesn't allow an argument
Try `ls --help' for more information.
 
Old 07-20-2008, 06:18 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Ahh, that makes sense!
 
Old 07-20-2008, 06:19 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by babu198649 View Post
could u please tell me how grep could be used in finding files.
Please, be more specific. What are you trying to do exactly?
 
Old 07-20-2008, 06:27 AM   #12
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by babu198649 View Post
i get errors.

Code:
[robert@localhost ~]$ ls --hide=*.xml
ls: option `--hide-control-chars' doesn't allow an argument
Try `ls --help' for more information.
Hmmm.... --hide-control-chars is the long form of the -q option. Do you have some strange filename which triggers this error? For example some file containing hypens or other special characters?

Have you tried to use quotes? ls --hide="*.xml" or even
Code:
ls '--hide=*.xml'
 
Old 07-20-2008, 06:29 AM   #13
babu198649
Member
 
Registered: Oct 2007
Posts: 160

Original Poster
Rep: Reputation: 30
i have many files in my directory. i want to display all files except files with .xml extension.i am using RHEL4.
 
Old 07-20-2008, 06:31 AM   #14
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by babu198649 View Post
i have many files in my directory. i want to display all files except files with .xml extension.i am using RHEL4.
Code:
ls --hide=*.xml
PS: I asked to be more specific about the grep question...
 
Old 07-20-2008, 06:39 AM   #15
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Following the suggestion by Nylex, you can try
Code:
ls | grep -v [.]xml$
this will definitively exclude the .xml files from the list.
 
  


Reply


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
Unable to delete the lines in xml FILES ragavendran31 Linux - Newbie 1 01-19-2008 02:24 PM
flat files or xml and css? trscookie Linux - General 1 01-17-2006 10:24 AM
Splitting XML Files Lanmate Linux - Software 0 11-09-2005 05:24 PM
Saving *.doc & *.XML files on old computers Kye Mandriva 3 10-23-2004 10:28 PM
Writing XML files from C++ application Ezeeckiel Programming 1 04-19-2004 04:06 AM


All times are GMT -5. The time now is 01:13 AM.

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