18

I want to hide, most of the folders in root (/) using Nautilus. Probably the only folders in / I want shown are /home and /tmp.

In addition to hiding folders, I also want to hide two files: initrd.img and initrd.img.old.

I find such a setup to be pro-noob, and looks a lot slicker too. How can I hide those folders and files?

3
  • Do you want to hide it in your file manager (e.g. Gnome's Nautilus or KDE's Dolphin) or for the whole system? As far as I know, the latter is not possible (Filesystem Hierarchy Standard).
    – gertvdijk
    Sep 17, 2012 at 14:08
  • 2
    Any file-manager. But i am using nautilus. So if i can hide folders only in nautilus. i am happy! :)
    – blade19899
    Sep 17, 2012 at 14:14
  • @blade19899 Then your own answer is correct. Works here. Please update your question to be Nautilus.
    – gertvdijk
    Sep 17, 2012 at 15:20

3 Answers 3

23

Tested under Nautilus 3.4.2 on Ubuntu 12.04/12.10 (but works in almost all scenarios)

Open gnome-terminal (Ctrl+Alt+T).

Type ls -1 /.

Copy the name(s) of the folder(s) you want hidden.

Press Alt+F2, then type in gedit.

Paste all the names you want hidden like so:

hidden

Image excerpted from Another Way to Hide Files Folders in Ubuntu by Meilin

Save the file (Ctrl+S) in the directory / with the name .hidden (no asterisk, as seen in the image above).

Refresh the page, and they are gone.

hidden-folders

Image from How to hide files and folders - EuroBytes

If you want them unhidden later...

To unhide the folders, you can either:

  • remove there names from the .hidden file, or
  • just press Ctrl+H to view all hidden files and folders.

Reference:

4
  • 2
    Works perfectly in Nautilus. Please mention the filename should be .hidden (without the asterisk as in the screenshot). F5 (refresh) seems enough to make Nautilus aware of it. And it works like opt-out, not opt-in unfortunately.
    – gertvdijk
    Sep 17, 2012 at 15:20
  • "Save the file (Ctrl+S) in the directory /" ... That should be placed in ~ or $HOME, and not /
    – 15 Volts
    Jul 25, 2020 at 20:33
  • @gertvdijk: just to clarify, the asterisk shown in the screenshot is not part of the filename, it's just a Gedit UI indicator that the file has changed and not yet saved.
    – MestreLion
    Dec 31, 2022 at 2:18
  • Seems to work in Thunar as well
    – paradroid
    Jul 19, 2023 at 20:17
1

I doubt you can achieve this easily, this is either all or nothing in the unix model, and there is no permission for "seeing content of directory". Once you have enough access to read a directory, then you can read everything ( ie, the list of folder/files )

chmod o-r / could work for hiding all directories, but I do not recommend to do it without testing first on a vm, and fully understanding what you do.

Using a custom kernel module, you could hide folders, but that's rather complex and error prone.

3
  • Would given a dot in front of the folder help. like so '.media'
    – blade19899
    May 28, 2012 at 15:51
  • That would requires change the path on every program ( ie, /.etc is different from /etc ), so all programs would likely be broken and the system would not boot.
    – Misc
    May 28, 2012 at 15:54
  • ;( to bad i will try some stuff out in virtual-box using 12.04 amd64 i will post later with the results.
    – blade19899
    May 28, 2012 at 15:59
0

This is an extension to @blade19899's answer

Motivation

Putting file names in .hidden file will hide them but nautilus only checks for exact matches. In some scenarios we want to hide files by pattern, not by exact names—for example I don't like to see latex aux files.

Workaround

My workaround is to split the .hidden in two sections separated by a line of at least 5 equal signs (i.e. =====). The patterns should be placed before this separator. Then, an script (see below) completes the file by adding exact filenames after the separator.

In practice, you need to run this script manually to update the file with new matches. Maybe adding this file as a FilemanagerActions would be a good idea.

Script

Run with no arguments:

import glob
from pathspec import PathSpec


def main():
    patterns = find_patterns('.hidden')
    files = ls()
    matches = find_matches(patterns, files)
    update_dothidden(patterns, matches)


def find_patterns(filepath):
    patterns = []
    with open(filepath) as f:
        lines = f.readlines()
    for line in lines:
        if line[0:5] == '=====':
            break
        patterns.append(line)
    return patterns


def ls():
    return glob.iglob('**/**', recursive=True)


def find_matches(patterns, files):
    path_spec = PathSpec.from_lines('gitwildmatch', patterns)
    return filter(path_spec.match_file, files)


def update_dothidden(patterns, matches):
    with open('.hidden', 'w') as f:
        for pattern in patterns:
            f.write(pattern)
        f.write('======================\n\n')
        for match in matches:
            f.write(match + '\n')
        f.write("\n# For usage, see https://github.com/m2-farzan/dothidden-patterns")


if __name__ == '__main__':
    main()

Latest version of the script: https://github.com/m2-farzan/dothidden-patterns/blob/main/refresh_dothidden.py

Example

Put this into .hidden file:

*.aux
*.bbl
*.blg
*.log
*.synctex.gz

Execute:

~/my_scripts/refresh_dothidden.py

Updated .hidden file:

*.aux
*.bbl
*.blg
*.log
*.synctex.gz
======================

dstar_main.aux
main.aux
main.bbl
main.blg
main.log
main.synctex.gz
mrpp_central.aux
tikzhead.aux
0

You must log in to answer this question.

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