When I perform ls
in bash, I always see too many *.pyc
files. Is there any way to hide these files?
Asked
Active
Viewed 5,509 times
27

J-Win
- 1,322
- 16
- 35

user2566808
- 291
- 3
- 4
-
Was there a significant reason behind this? I was annoyed/distracted by them myself (for a purpose of a talk with live demo); that's why I've ended up here. It _sounds_ like you were also only _annoyed_. – quapka Apr 16 '18 at 20:48
1 Answers
33
This way lies the dark side, but you could force ls
to never show them by adding something like
alias ls='ls --hide="*.pyc"'
to your .bashrc
. ls
will reveal the hidden files if you use -a
or -A
.
However, I would recommend just ignoring them in your head, or running this version of ls
when you really don't want to see them.

John Kugelman
- 349,597
- 67
- 533
- 578

Matt Bryant
- 4,841
- 4
- 31
- 46
-
3alias ls=`ls --ignore="*.pyc"` did not work for me. but `alias ls="ls --ignore="*.pyc""` did work – Jay Jul 11 '13 at 03:55
-
4`alias ls='ls --hide=*.pyc'` might be better as this is overridden when you use `-a` option or search using wildcards like `ls *.pyc` – Phani Oct 10 '13 at 16:30
-
That's a really good point, thanks. I didn't know about that option. – Matt Bryant Oct 10 '13 at 17:51
-
I went ahead and removed `--ignore` from the answer. `--hide` is definitely preferable. – John Kugelman Jan 13 '14 at 21:40
-
7It is probably a better idea to alias to something a little different.. like `alias lsl='ls --hide="*.pyc"'` so you don't nerf `ls` but have the functionality you want available easily. – Robert Mark Bram Feb 27 '14 at 05:27
-
1To retain default colouring, use this: alias ls='ls --color=auto --hide=*.pyc' – Mayank Jaiswal Dec 13 '15 at 22:29
-
1@TheoBelaire I've found the solution for OSX. (1) `brew install coreutils` (2) Put `alias lsp='gls --hide="*.pyc"'` to your `~/.bash_profile`; Then you can use `lsp` to `ls` without seeing `*.pyc`. (`lsp` is a command name I created which stands for "ls for python") – AnnieFromTaiwan Jan 06 '16 at 09:55