LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   list all files except .xml files (https://www.linuxquestions.org/questions/linux-newbie-8/list-all-files-except-xml-files-656958/)

babu198649 07-20-2008 05:01 AM

list all files except .xml files
 
hi
i want to list all files except .xml files.

Nylex 07-20-2008 05:05 AM

ls | grep -v *.xml?

babu198649 07-20-2008 05:08 AM

Quote:

Originally Posted by Nylex (Post 3220490)
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.

Nylex 07-20-2008 05:11 AM

Quote:

Originally Posted by babu198649 (Post 3220493)
NO it does not work.

Hmm, so it doesn't. I'm not sure why though :/. ls | grep -v xml should do it.

colucix 07-20-2008 05:14 AM

Code:

ls --hide=*.xml

babu198649 07-20-2008 05:16 AM

could u please tell me how grep could be used in finding files.

Nylex 07-20-2008 05:17 AM

You don't use grep to find files, you use it to find patterns.

colucix 07-20-2008 05:17 AM

Quote:

Originally Posted by Nylex (Post 3220495)
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.

babu198649 07-20-2008 05:18 AM

Quote:

Originally Posted by colucix (Post 3220500)
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.


Nylex 07-20-2008 05:18 AM

Ahh, that makes sense!

colucix 07-20-2008 05:19 AM

Quote:

Originally Posted by babu198649 (Post 3220505)
could u please tell me how grep could be used in finding files.

Please, be more specific. What are you trying to do exactly?

colucix 07-20-2008 05:27 AM

Quote:

Originally Posted by babu198649 (Post 3220511)
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'

babu198649 07-20-2008 05:29 AM

i have many files in my directory. i want to display all files except files with .xml extension.i am using RHEL4.

colucix 07-20-2008 05:31 AM

Quote:

Originally Posted by babu198649 (Post 3220524)
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...

colucix 07-20-2008 05:39 AM

Following the suggestion by Nylex, you can try
Code:

ls | grep -v [.]xml$
this will definitively exclude the .xml files from the list.


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