Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

when I type ls, I don't want to see .o files because everytime I ls, It see X.cpp X.h X.o, how do I not list .o files?

share|improve this question

OS X's BSD ls does not support the -I argument present in GNU ls to filter file types.

You can run the following expression that returns all files in the current directory that don't have a .o extension, and otherwise prints the same format as ls -l:

find * -maxdepth 0 ! -name '*.o' -print0 | xargs -0 ls -dl

You can create a function for this in your ~/.zprofile so you can run it by typing lso <extension>:

function lso {
    find * -maxdepth 0 ! -name "*.$1" -print0 | xargs -0 ls -dl
}

It's not suitable as a complete ls substitute, as it doesn't support arguments.

Sample output:

$ ls -l
total 8
-rw-r--r--  1 danielbeck  staff    0  2 Sep 12:52 pi.c
-rw-r--r--  1 danielbeck  staff    0  2 Sep 12:52 pi.o
-rw-r--r--  1 danielbeck  staff  278 31 Aug 06:52 pi.py
-rw-r--r--  1 danielbeck  staff    0  2 Sep 12:52 pi.pyc

$ lso
-rw-r--r--  1 danielbeck  staff    0  2 Sep 12:52 pi.c
-rw-r--r--  1 danielbeck  staff  278 31 Aug 06:52 pi.py
-rw-r--r--  1 danielbeck  staff    0  2 Sep 12:52 pi.pyc
share|improve this answer
    
maybe you could try piping it to grep -v? ls | grep -v ".o" – misterjaytee Sep 2 '12 at 8:23
    
Can you please try to parametrize this using bash parameters? IBM tutorial to do this seems very complicated. Sorry. – snihalani Sep 14 '12 at 14:44
    
@snihalani, are we talking about bash or zsh? Not much difference though... – cYrus Sep 14 '12 at 15:53
    
zsh user here. Thanks. – snihalani Sep 14 '12 at 17:16
    
@snihalani, I don't know how does the notifications system work, but... I've edited the function to take a parameter (e.g. lso o). – cYrus Sep 14 '12 at 17:20

If you've setopt extended_glob, you can do something like ls -ld ^*.o and maybe assign that to an alias of your choice.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .