Bash – How to Exclude Certain Files in `ls`

bashls

I would like to run ls and exclude certain files in the output.

When I run the following command, I get all files with each on one line:

$ ls -1
file1
file2
file3
temp

I would like to run this command in a way so it shows

$ ls -1 <insert magic here> temp
file1
file2
file3

Best Answer

ls -I <filename>

-I = Ignore the filename, i.e., don't list the specified file.

To ignore more than one file add an -I before each filename.

ls -I file1 -I file2

To ignore files by their name extensions do the following, for example.

ls -I "*.jpg" -I "*.svg"