Problems with "ls --ignore"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems with "ls --ignore"
# 1  
Old 11-12-2009
Question Problems with "ls --ignore"

I'm running in CentOS Linux, but this is a core unix question:
> ls */a/b/*.*
list hundreds of files with several extensions and I'd like not to lists those with extension ".o", say. So, after checking the man page for ls, I tried
> ls -I "*.o" */a/b/*.*
and
> ls --ignore="*.o" */a/b/*.*
but both still got me the *.o files.
Why weren't they ignored as expected? Shouldn't 'ls -I="*.o"' make ls skip all files that end in '.o' ?
I even tried
> ls --ignore="*/a/b/*.o" */a/b/*.*
but same results: the .o files were listed -uff! Smilie
# 2  
Old 11-12-2009
Another way is to use grep with the -v option to suppress those files:

Code:
ls <whatever> | grep -v '.o$'

# 3  
Old 11-12-2009
Thanks, this works. I'm still interested in knowing why the ignore option of ls doesn't work as indicated in the man page.
# 4  
Old 11-12-2009
Quote:
Originally Posted by c2s
Thanks, this works. I'm still interested in knowing why the ignore option of ls doesn't work as indicated in the man page.
That's a good question.

Code:
ls --ignore=PATTERN

where PATTERN is a REGEX in quotes should work...

but I can't get it to work on Linux regardless of the REGEX I use Smilie

I have never used the --ignore option, as I always use |grep -v, but it is interesting why it does not work.
# 5  
Old 11-12-2009
According to the info pages pattern is not a regex but what is called a "shell pattern" with which I guess they mean globbing. I noticed it does not seem to work when the file list contains a wild card.

So this works:
Code:
ls -l -I '*.o'

But this does not:
Code:
ls -ld -I '*.o' *

So see if this works:
Code:
ls -R --ignore='*.o'

# 6  
Old 11-12-2009
Quote:
Originally Posted by Scrutinizer
According to the info pages pattern is not a regex but what is called a "shell pattern" with which I guess they mean globbing.[/CODE]
According to many man pages "shell pattern" == REGEX Smilie which seems like some of the confusion... because I agree regular expressions do not work.
# 7  
Old 11-12-2009
simply using
Code:
ls -I "*.o"

doesn't help when what you want to list is distributed over many directories, as in the original question
Code:
ls */a/b/*.*

The man ls page in my system shows that for -I PATTERN PATTERN is a Shell PATTERN. But since ls -I *.o works on the current directory, it must be the right pattern. Confusing little issue, indeed.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

3. Shell Programming and Scripting

Problems with "write" and "wall"

Hello, I am using VirtualBox to simulate a small network with two Linux computers, the host is Mac OS X. My problem is that I can't send "write" and "wall" messages from the host to one of those Linux computers. Here is what works: - The virtual Linux computer answers "ping" messages that have... (5 Replies)
Discussion started by: 123_abc
5 Replies

4. Shell Programming and Scripting

how to ignore "," between quotes in awk?

Hi, I have file1 where I have my ids and file2 where I have ids and corresponding texts. I have to match the ids of my file1 to file2 and write in ids and corresponding text to another file. e.g file1 ---- 23 1 4 file2 ---- 23,"test, test2" 1,new awk -F, 'BEGIN{FS=","}NR==FNR{ a;next}... (1 Reply)
Discussion started by: babom
1 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

How to "ignore" deprecates in php?

I have a deprecated thing on my server which I want to "ignore" from start, since if a user on the server uses E_STRICT or something, the site will break if they use the deprecated function: Deprecated: Function set_magic_quotes_runtime() is deprecated in xx The reason is that I've updated to... (0 Replies)
Discussion started by: hjalle
0 Replies

7. Shell Programming and Scripting

Ignore "a line" within /etc/profile only when su'ing

Is there a way to ignore a command within /etc/profile only when su'ing as any particular user. For instance.... As root, if I run "su - oracle -c program" it is running a string in my profile called "echo "^2;$(hostname)-(ABC) @ $(who am i)^G". I don't want the above string to run if I... (9 Replies)
Discussion started by: lwif
9 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. SCO

Plz. don't ignore this mail "Installing Tomcat 4.1.24.zip on Sco Openserver 5.0.2"

Hi Guys, I want ur replies very very Urgently.Plz. don't ignore this mail. I am using Sco openserver 5.0.2 and i have downloaded jdk1.2.2 for that i have installed it.The jdk is working fine. Then i download jakarta-tomcat-4.1.24.zip and i have installed it. In order... (1 Reply)
Discussion started by: ananthu_m
1 Replies
Login or Register to Ask a Question