How to make files invisible from to the shell

bashiconterminal

I have various folders with custom icons (some added by Resilio Sync, and some by other things) which drive me crazy in the terminal. Is there any way to hide them from the shell?

I know how to hide them from the Finder, and that's not what I'm asking about. Deleting them is also not what I'm asking about.

Is there any way to make them invisible to the shell?

Best Answer

Not really. What you seek isn't something shells try to support. Shells are really about open access to a system, not hidden access.

Some shell commands and functions will ignore directories and files that are prefixed with a . by default. For example, ls does this:

IanCsiMac:~/code/tmp
> ls

IanCsiMac:~/code/tmp
> ls -lah
total 16
drwxr-xr-x   3 ian  staff   102B Oct 15 15:06 .
drwxr-xr-x  44 ian  staff   1.5K Oct 10 11:03 ..
-rw-r--r--@  1 ian  staff   6.0K Oct 15 15:06 .DS_Store

But the .-prefixed file in the above example isn't considered "hidden". Just "not displayed in the default view". Any sort of hiding like this would necessitate you rename your files and folders so they're prefixed with a . and then they'd also disappear by default from Finder.

As you can see from answers on other SE sub-sites (1, 2, 3), the prefix-with-a-dot is really the only consistent way to keep a file or folder out of the normal view of most shell functions and commands.