Hidden Files&Directories in user's home directory

6,912

Solution 1

As @mikeserv has already said, you are generally allowed to remove any files you want in your home directory. If you have sufficient privileges you can delete files in another user's home directory, but as we will see this may not be a very nice thing to in someone else's home directory. None of these files are necessary for your system to function, you at least have to become root to break the system.

However, the majority of these files contain settings or other data that the program uses when run as that user. Removing these may significantly change the way the program looks/feels for that user and may even cause data loss. Here are some of the things that I have in the hidden files/directories under home:

  • Settings for my desktop environment. If these get removed any customisations made to it, like walllpaper, screensaver, shortcut keys and taskbar/menu changes would all be restored to default next time the user logs in.

  • Web browser related data. Some of this will be bookmarks, browsing history etc which might be important. The bulk of the data will be the cache which contains downloaded web data (images etc). This would just be re-downloaded next time the page is visited, so generally no problem removing.

  • The .wine directory. This is the default location for the entire wine drive. If this removed, so would all software that the user has installed under wine!

  • The .cabal directory, this another example of a hidden directory where user software is stored. These are Haskell source packages installed by cabal.

  • Configuration files for various command line programs that I use, eg .bashrc, inputrc, .vimrc, .tmux.conf. Over the years many users will build up a substantial array of various settings/tweaks that help their workflow. I you removed mine that would be an incitement to violence! (well, not really, I would restore from a backup or just re-add stuff as I needed it).

Many programs will look for one or more of these files when it runs and it will create what it doesn't find. If it is a settings file, the newly created one will just have default settings. Any change made to the program's settings through its own interface will likely be stored in one of these. If cached data is removed, this will generally slow things down somewhere along the line as re-creating will take time (generally the reason for storing it in the first place).

Often it is difficult to find out what files belong to what program. The files will also not be removed when the program is uninstalled, so it is easy to collect ones that you don't need. If you want to remove some you could try to identify one that you don't need (eg if you remove a browser, the locating and removing its cache files could free up a lot of space). Either that or just identify what you want to keep and remove the rest - sometimes a clear out can be a good idea.

What may cause unexpected results is removing files like .bashrc and .profile, even if they have not been changed. The system will copy default versions of these files from /etc/skel when the user is created rather than them created by bash when it is run for the first time. If you accidentally delete one of these you can always restore it from /etc/skel (you can do ls -a /etc/skel to see what is there).

Solution 2

If it's your $HOME directory, you're allowed to do whatever you want with it. In fact, that is the basic premise underlying all Unix filesystem permissions: ownership.

None of the files in your $HOME directory are necessary to the system. This is why they're in your $HOME directory and not elsewhere. That is the only clue you need.

The default file permissions (umask):

Each user has a default set of permissions which apply to all files created by that user, unless the software explicitly sets something else. This is often called the umask, after the command used to change it. It is either inherited from the login process, or set in the .cshrc or .login file which configures an individual account, or it can be run manually. Typically the default configuration is equivalent to typing umask 22 which produces permissions of:

  • -rw-r--r-- for regular files, or
  • drwxr-xr-x for directories.

In other words, user has full access, everyone else (group and other) has read access to files, lookup access to directories.

Solution 3

Which of them I am allowed to remove? Which ones are necessary on my system?

None, and all. Most of these files are created upon installation or when you run a program. Even if you delete them, they will come back.

How can I realize it?

Depending your use, but seriously, most of them use <1kB so it shouldn't bother you that they are there. Just don't type ls -a and you would never see them again.

Share:
6,912

Related videos on Youtube

MLSC
Author by

MLSC

Updated on September 18, 2022

Comments

  • MLSC
    MLSC over 1 year

    I am in my user's home directory, I do:

    ls -a
    

    Then it shows me large number of hidden files and directories in my user's directory. Which of them I am allowed to remove?

    Which ones are necessary on my system?

    How can I realize it?

    • Tom Gibbs
      Tom Gibbs about 10 years
      Why do you want to remove your .files? Each application you use will have a config file. vim might have .vimrc and .gvimrc and so.
    • MLSC
      MLSC about 10 years
      no some of them are stranges. like:rm .lesshst and .gout232342-1234
    • MLSC
      MLSC about 10 years
      some are with no content and empty
    • jlliagre
      jlliagre about 10 years
      What would you save by removing empty files ?
    • MLSC
      MLSC about 10 years
      Sometime we doubt that they may be an exploit, backdoor or something else...Some are directory in directory and strange...some are just binary files
    • MLSC
      MLSC about 10 years
      empties are extra.. aren't they?
    • Alen Milakovic
      Alen Milakovic about 10 years
      If you want to check whether they are being used, you can set things up, perhaps using an audit system, to see if they are being read. Also of course you can check modification times.
    • MLSC
      MLSC about 10 years
      Thanks, but is there a way to realize these are necessary or not for my system?
    • goldilocks
      goldilocks about 10 years
      You would be better off asking about specific files. You should not delete any dot (hidden) files unless you understand what they are for.
  • MLSC
    MLSC about 10 years
    Thank you, As you see the comments, I said I fear about some exploits or something like these...Some are binary files, All directories and files start with . in my home directory are safe you mean?
  • Graeme
    Graeme about 10 years
    Actually I have a total of 2.4 GB worth of hidden files in my home directory. This is significant even if a lot are less than 1 KB.
  • Ludwig Schulze
    Ludwig Schulze about 10 years
    @Graeme most likely those are Firefox/Flash/Chrome cache. I did find . -size +1M to search for all files over 1M and only found chromium, steam, skype, iceweasel, wine, related stuff.
  • Graeme
    Graeme about 10 years
    That's right, I have about 1 GB of wine related stuff and around 400 MB each for chromium and iceweasel. I also have a few hundred MB of cabal stuff. You can do GLOBIGNORE=.:..; du -ch .* | sort -h to get something like an ordered list.
  • Ludwig Schulze
    Ludwig Schulze about 10 years
    @MortezaLSC nothing in your home should be binary, do find . -type f -executable and look for clues. Anything that you don't know can be deleted.
  • MLSC
    MLSC about 10 years
    I think wine should be one of the unsafe apps that permits us using .net framework and may be they could be executed whenever they want :)