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?
3 Answers
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
-
-
Can you please try to parametrize this using bash parameters? IBM tutorial to do this seems very complicated. Sorry. Sep 14, 2012 at 14:44
-
@snihalani, are we talking about
bash
orzsh
? Not much difference though...– cYrusSep 14, 2012 at 15:53 -
@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
).– cYrusSep 14, 2012 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.
@cYrus is correct that the BSD ls -I ...
filter option is not supported. However here's a quick-and-dirty hack that postprocesses ls -F
output to exclude directories, symbolic links, sockets, whiteouts, FIFOs:
ls -1F | grep -v '[/@=%|]'
(Note: obviously this relies on assuming those special characters don't occur in filenames, which is not 100% reliable like a find
-based approach.)