Search code examples
terminallshidden-files

Exclude files listed in '.hidden' when using 'ls'


In my home folder, I have a file called '.hidden' in which I put the names of a few files and folders that I don't want to see in that directory. I can't change their names, ie: I can't put the dot '.' at the beginning.

When I give 'ls' in a terminal, it lists all files and folders including those listed in '.hidden'. I want 'ls' to exclude them.

Is there a way for doing this?

I have to pass the content of the file '.hidden' to ls. Something like:

ls --ignore= [SOME MAGIC HERE] $(tr '\n' ' ' < .hidden)

Thank you! :)


Solution

  • Here's how I solved this:

    alias ls='exclusion=; while read p ; do exclusion=$exclusion" -I$p"; done < ~/.hidden; ls $exclusion --color=auto --group-directories-first'