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


Reply
  Search this Thread
Old 05-17-2009, 04:42 PM   #1
mwkemo
Member
 
Registered: May 2009
Location: Croatia
Distribution: Debian
Posts: 31

Rep: Reputation: 16
list files except iw_


Hello,
I am stuck with one problem and I need help.

I need to list all files that are in one folder, except those files starting with "iw_". Is this posible with ls command?


Code:
find /home/danko/test/maps -not -name iw_* -and -not -name localized* | sed 's/\/home\/danko\/test\/maps\///' | sort -n
This is what works for me, but then i get another problem which list all directorys and subdirectorys. With sed i removed all characters that i do not need but in the end i feel like I am going in wrong direction and ther is a much more elegant solution.

THX

Last edited by mwkemo; 05-17-2009 at 04:47 PM.
 
Old 05-17-2009, 05:22 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
Code:
ls --hide=iw_*
It's right there in the man page. It does say that it doesn't work with the -a or -A options though.

Another option is to use grep with the -v (invert) option.

Code:
ls | grep -v iw_*
 
Old 05-17-2009, 06:23 PM   #3
mwkemo
Member
 
Registered: May 2009
Location: Croatia
Distribution: Debian
Posts: 31

Original Poster
Rep: Reputation: 16
OoO, THX zilion times. Don't know how i missed this in man.
 
Old 05-18-2009, 03:26 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
No problem. We all miss the easy things from time to time.

BTW, you could've limited your find command above with "-type f", to display only regular files, and/or use "-maxdepth 1" to keep it from searching recursively. Just thought I'd point that out.

OTOH, thank you for making me aware of the existence of the "-not" flag. I wasn't aware of that. I'm sure it will come in useful in the future.
 
Old 05-18-2009, 09:06 AM   #5
mwkemo
Member
 
Registered: May 2009
Location: Croatia
Distribution: Debian
Posts: 31

Original Poster
Rep: Reputation: 16
For future readers, here is another example of how to print all files except the mentioned:

Code:
find /home/example/ -not -name iw_* -printf '%f\n'
But ls --hide=* is quite enough
 
Old 05-18-2009, 12:24 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
While we're at it, let's also point out that you can avoid creating "picket fence" strings in sed if you change the delimiter from '/' to something else (sed can use just about any character as the delimiter, as long as it doesn't appear in the expression itself).

Code:
sed 's/\/home\/danko\/test\/maps\///'  #Hard to read.  Let's change it to '|' instead.

sed 's|/home/danko/test/maps/||'       #Much easier to read. :)
 
Old 05-18-2009, 01:16 PM   #7
mwkemo
Member
 
Registered: May 2009
Location: Croatia
Distribution: Debian
Posts: 31

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by David the H. View Post
... sed can use just about any character as the delimiter, as long as it doesn't appear in the expression itself....
Nice option to know. . Dont know wher you pull that one out. I think that this is not stated in man pages of sed, but maybe I'm wrong (Would not be the first time).

Last edited by mwkemo; 05-18-2009 at 01:17 PM.
 
Old 05-18-2009, 03:07 PM   #8
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
Quote:
Originally Posted by mwkemo View Post
Nice option to know. . Dont know wher you pull that one out. I think that this is not stated in man pages of sed, but maybe I'm wrong (Would not be the first time).
It's here:
http://www.grymoire.com/Unix/

Also, for completeness, there is "grep -v"
 
Old 05-18-2009, 03:55 PM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
Quote:
Originally Posted by mwkemo View Post
Nice option to know. . Dont know wher you pull that one out. I think that this is not stated in man pages of sed, but maybe I'm wrong (Would not be the first time).
It's not in the man page, but it is in the texinfo manual (info sed).
Quote:
3.5 The `s' Command
===================

The syntax of the `s' (as in substitute) command is `s/REGEXP/REPLACEMENT/FLAGS'. The `/' characters may be uniformly replaced by any other single character within any given `s' command.
The `/' character (or whatever other character is used in its stead) can appear in the REGEXP or REPLACEMENT only if it is preceded by a `\' character.
The unix grymoire is an easier read for it though. In fact, I just got done working my way through most of the sed page. It can do a lot of really nice things that most people never realize, like running multiple expressions at once and multiline matches.

And Pixellany, I guess you didn't notice, but I mentioned 'grep -v' in my first post.
 
  


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
Downloading a list of files from a remote server using a list ralcocer Programming 2 02-11-2009 01:02 PM
How to list all files recursively, in a non-broken list? nyle Linux - Newbie 1 12-16-2008 10:52 PM
list all files except .xml files babu198649 Linux - Newbie 26 07-20-2008 03:24 PM
lftp does not list files PhillipHuang Red Hat 1 12-28-2006 04:09 AM
list only files and not descend twantrd Solaris / OpenSolaris 2 11-29-2004 04:15 PM


All times are GMT -5. The time now is 02:13 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