15

Usually Linux programs store user's settings in ~/.* directories. But unfortunately some developers (of some applications I need) do not follow this rule and don't start their settings storage folders names with a dot. This results in never-user-used folders cluttering (not the right word perhaps, as there are not many, but they annoy anyway) a home directory. Renaming them is not an option, as the applications won't find them in this case (and will create them again).

Is there a way to hide a folder having no dot starting its name from being displayed in common file system browsers (I actually use Thunar of XFCE, alongside with Midnight Commander and Krusader, but wouldn't mind to know about Nautilus too).

Ivan
  • 55,987
  • 65
  • 150
  • 212

3 Answers3

20

Nautilus (Update: This should also work with Thunar now) will hide any file or folder that is listed in the file .hidden located in the same directory.

There are two ways to hide a folder in Nautilus:

Nautilus script

  1. Save the following code in a new file in your home folder. Name it Hide.

    #!/usr/bin/env python
    
    import commands
    from os.path import join
    
    
    files = commands.getoutput("echo $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS")
    cwd = commands.getoutput("echo $NAUTILUS_SCRIPT_CURRENT_URI")
    cwd = cwd[7:]
    
    for f in files.split(" /"):
    
        f = f.split("/")[-1]
    
        commands.getoutput("echo "+f+" >> "+join(cwd, ".hidden"))
    
  2. Run the following command to install the script:

    cp Hide ~/.local/share/nautilus/scripts/ && chmod u+x ~/.local/share/nautilus/scripts/Hide
    
  3. In Nautilus, select one or more files/folders and right click. Select Hide from the Scripts menu:

    enter image description here

    Reload the current location ( F5 ) and the selected files/folders will be hidden.

Command line

Say you want to hide a folder called "Rick Astley's Greatest Hits", just run the following command:

echo "Rick Astley's Greatest Hits" >> .hidden
muru
  • 193,181
  • 53
  • 473
  • 722
Isaiah
  • 58,486
  • 28
  • 133
  • 145
  • 2
    Exactly a kind of answer I wished to get. But, unfortunately, doesn't work for Thunar. – Ivan Dec 22 '10 at 02:42
  • @Ivan, Hopefully they will add it eventually, see the bug report I linked to in my answer. – Isaiah Dec 22 '10 at 02:50
  • Why double quotes "ObnoxiousFolder"?? – karthick87 Dec 22 '10 at 08:17
  • FYI, the bug report was closed as WONTFIX (rather rudely IMO, since there was a patch for it already, and the project maintainer basically said "I don't care"). We will need another solution... – waldyrious Jan 07 '13 at 17:46
  • 1
    Recent version of Thunar support this as they use GIO to determine hidden directories, and GIO now implements support for the `.hidden` file. – Brian Campbell Jul 11 '14 at 14:59
  • Nice script, though I [prefer](http://askubuntu.com/a/548288/929) using more of Python's [own](http://stackoverflow.com/q/4906977/321973) [IO](http://stackoverflow.com/q/4706499/321973). According to https://help.ubuntu.com/community/NautilusScriptsHowto `NAUTILUS_SCRIPT_SELECTED_FILE_PATHS` is newline-separated, so shouldn't your `for ... split` be with `()` instead of `(" /")? (The slash is irrelevant, since you only take the `basename` anyway, for which you could use [`os.path.basename`](http://stackoverflow.com/q/22272003/321973) btw) – Tobias Kienzler Nov 11 '14 at 12:30
2

Open synaptic and search for "nautilus-hide" install it. Logout and login. Now right click on any file or folder. You will now see a "Hide" option in the Context Menu.

It will not modify the name but hide the folder.

Curious Apprentice
  • 3,397
  • 8
  • 35
  • 54
0

I modified Alvin's good script to be (hopefully) more Pythonic (and potentially faster if many files are added, since .hidden is opened only once):

#!/usr/bin/env python

import os

files = os.environ["NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"].split()
# According to https://help.ubuntu.com/community/NautilusScriptsHowto
# the list is newline-delimited, which is split()'s default separator

# No need for NAUTILUS_SCRIPT_CURRENT_URI
cwd = os.path.dirname(files[0])
# Assuming all selected files are in the same path, I cannot imagine why not

# Instead of relying on "echo ... >> ..." use Python's IO:
with open(os.path.join(cwd, ".hidden"), "a") as hidden:
    hidden.write("\n".join(
        [os.path.basename(f) for f in files.split()]))
Tobias Kienzler
  • 446
  • 1
  • 9
  • 25