0

Short version: I want to be able to prevent certain files from appearing in the output of ls, without adding the dot, and thus changing their names.

Long version: Recently, I moved a bunch of scripts and data files to another directory to keep things organized. Many of my older scripts require access to these files, and so I created symlinks for backward compatibility. However, the point of moving the files is to keep the original folder clean, so I don't want to see the symlinks. But how can I hide them, without changing their names (adding the dot), and thus breaking my older scripts?

6
  • 2
    I don't think this is possible. Why don't you batch edit your scripts,something like sed -i '#/old/path/#/new/path#g' scripts/*sh?
    – terdon
    Sep 11, 2013 at 12:11
  • Put the scripts in a directory which you put on your PATH Sep 11, 2013 at 13:18
  • @Tim, in the linked thread, the OP's question is more general, and the answers are not applicable to what I am trying to accomplish. I thought the fact that these files should be hidden on the command line, and that other scripts should still be able to use the old path, provided new information.
    – antass
    Sep 11, 2013 at 13:33
  • @Oliver, unless I am misunderstanding something.. did you mean the scripts that I symlinked? If so, I also moved and symlinked data files, so that wouldn't work :/
    – antass
    Sep 11, 2013 at 13:35
  • In retrospect, the best thing for me to do would have been to save the source and destination paths in a file, and then use that as a dictionary to rewrite my scripts.
    – antass
    Sep 11, 2013 at 13:49

2 Answers 2

1

Unfortunately, this is not possible (without programming your own custom version of ls). The best thing to do is to just edit your scripts.

It is possible to prevent specific filenames from being matched by globs with the $GLOBIGNORE global variable.

$ printf '%s\n' *
foo.txt
bar.txt
baz.txt
$ GLOBIGNORE=foo.txt:baz.txt
$ printf '%s\n' *
bar.txt

If you really want to, you could set an alias in your .bashrc, where you can also set the $GLOBIGNORE variable above.

alias myls='ls -d *'

However, this will probably cause you problems somewhere along the line. It really would be a better idea to just edit your scripts (perhaps using sed to do them in batches, as @terdon suggested).

4
  • Combining this answer with the one from DEFCON1, you could use GLOBIGNORE=$(tr '\n' ':' < .hidden) to hide the files. That said $GLOBIGNORE does not seem to work on my system.
    – Tim
    Sep 11, 2013 at 13:20
  • I agree, editing the script seems to be the easiest (in the long run) and most elegant way to do this.. I am just being lazy and trying to avoid rewriting paths to files that did not all end up in one folder, but a more complex structure of subfolders.
    – antass
    Sep 11, 2013 at 13:43
  • @evilsoup, you are right, aliasing ls may not end well, especially since some of the symlinks I actually do want to see. I only want to hide the symlinks to recently moved files. I'll check out the $GLOBIGNORE business.. Sounds like .gitignore, which is exactly the mechanism I would like to achieve.
    – antass
    Sep 11, 2013 at 13:46
  • @antass the real problem with $GLOBIGNORE is that it's global; if you set GLOBIGNORE=foo.txt, then no foo.txt will be matched by a glob anywhere on the system. This wouldn't be a problem with scripts, but it could cause issues for use on the command line.
    – evilsoup
    Sep 11, 2013 at 14:29
1

If you have nautilus file manager installed in your linux system , you can hide them from file manager (nautilus) without rendering it invisible to CLI and without using the dot.

Create .hidden file containing list of hidden files/folders.

To use this feature, simply create a file with name ".hidden" (dot hidden) located in a folder containing the files/folder you want to hide. Then open it in text editor and then create a list of names of the hidden files/folders that you have to hide in the folder containing ".hidden" file.

you cant hide files from ls without using the "dot" but you may change permissions for directory containing the files for certain users with chmod and render it inaccessible to them.

5
  • AFAIK this works on most graphical file managers, not just Nautilus.
    – evilsoup
    Sep 11, 2013 at 12:27
  • The OP is asking how to do this for the output of ls.
    – terdon
    Sep 11, 2013 at 12:30
  • How can you render files invisible using chmod? You can render an entire directory inaccessible, but cannot affect the way the files are displayed.
    – terdon
    Sep 11, 2013 at 12:45
  • yes that is correct , even if it can't be accessed it will still be visible.
    – Ashildr
    Sep 11, 2013 at 13:13
  • Using a GUI would be the simplest solution, however I am working with a remote linux server, and I mount the drive locally only when I am on my Mac (which makes browsing super slow through Finder anyway, and so CLI is the best bet)
    – antass
    Sep 11, 2013 at 13:40

Not the answer you're looking for? Browse other questions tagged .