Remove hide file linux

How to recursively delete hidden .directory files on Linux

Hidden files from file managers, thumbnail creation and applications can be very annoying, especially because they stay forever. In most «.gitignore» files at least the «.DS_Store» (MacOS finder) is listed, but what about all the other hidden Linux application files?

In a recent file system clean up, I noticed that a lot of folders are containing a .directory file. They were created by Dolphin, a KDE file manager, that I used almost 10 years ago.

[Dolphin] Sorting=1 Timestamp=2010,12,16,20,25,48

Thankfully, getting rid of hidden files is extremely easy on Linux with find . Open up your terminal, navigate to the folder you want to check and do a search first:

$ find . -name '.directory' -type f ./directory ./subfolder/.directory . 

The find command has a different syntax than most other Linux commands. Written-out expressions just contain one dash and the structure is the following:

You can not only search for files, but use all kind of search criteria, like size, modified date etc. This makes find a really powerful tool and it also has the ability to take actions, like delete, on the result.

Deleting Dolphins «.directory» files

Deleting files with find is really easy, just add the -delete expression to the search.

Warning: Always do a search first and be very careful with the wildcard (*) expression.

$ find . -name '.directory' -type f -delete . 

find can also be used for deleting other files too. Just replace .directory with the file name you want to delete. If you want to delete for example all «.tmp» files use `find . -iname ‘*.tmp’ -type f -delete’.

Preventing Dolphin from creating .directory files

If you are still using Dolphin, you can also disable the .directory file creation, else the .directory file will be created once you navigate to the folder again.

Читайте также:  Линукс разархивировать архив tar gz

In Dolphin, open the configuration («Configure Dolphin») and navigate to «General» > «Behavior» and select «Use common properties for all folders».

Related Posts

Источник

How to remove hidden files in Linux

I am a new Linux sysadmin and Ubuntu Linux user. How can I remove hidden files in Linux? How do I delete hidden files in Linux starting with . (dot) character?

Introduction: Linux and Unix like operating system allow users to hide files. By default, all hidden files not listed by the ls command. Any filename begins with a dot (.) becomes a hidden file. For example ~/.bashrc is a hidden file in Linux. Hidden files are often known as a dot file. All dot files used for storing user preferences on Linux. Please note that hidden or dot files are not a security mechanism. They exist to reduced “clutter” of the contents of a directory listing.

How to display hidden / dot files in Linux

One an display hidden files by passing the -a option to the ls command. For example:
ls -a
ls -la
ls -l /path/to/.filename
Linux display hidden files command
You can add a “/” after directory names in Linux:
ls -F
ls -Fa
One can get a reverse listing:
ls -r
ls -ra
To just display dot/hidden files in Linux use any one of the following command along with grep command/egrep command:
ls -a | egrep ‘^.’
ls -A | egrep ‘^.’
ls -l ~/.[^.]* | less
ls -ld ~/.[^.]*
ls -l ~/. *
ls -ld ~/. *
Just display hidden dot files in Linux with ls
See “Linux / Unix: Find And List All Hidden Files Recursively” for more info.

Command to remove hidden files in Linux

To remove hidden files in Linux, try:
rm .file
rm -i /path/to/.fileName
rm -i /path/to/.dirName
rm -rf /path/to/dir/.*
Of course, you can not delete two individual directories:

  1. . – The current directory indicated by a single dot.
  2. .. – The parent directory indicated by two successive dots.

Delete or remove hidden files in Linux command

Let us try out:
cd /tmp/
mkdir demo
cd demo
mkdir app
>.config
>.vimrc
>.bashrc
ls -a | egrep ‘^.’
ls
rm .vimrc
ls -a | egrep ‘^.’
rm -rfv /tmp/demo/.*

Getting rid of warning message rm: refusing to remove ‘.’ or ‘..’ directory: skipping

Simply add the following 2> /dev/null at the end of the rm command:
rm -rfv /dir/.* 2>/dev/null
rm -rfv /tmp/demo/.* 2>/dev/null
Sample outputs:

removed '/tmp/demo/.bashrc' removed '/tmp/demo/.vimrc'

/dev/null is nothing but a special file that discards all data written to it. See the following for more info:

Читайте также:  Настройка криптопро csp linux

How to delete hidden files in Linux

One can use the find command to list or delete hidden files. The syntax is as follows:

## List all hidden dirs in /etc/ ## find /etc/ -maxdepth 1 -type d -name ".*" ## List all hidden files in /etc/ ## find /etc/ -maxdepth 1 -type f -name ".*" ## Find all hidden files in /tmp/data/ and delete it ## find /tmp/data/ -maxdepth 1 -type f -name ".*" -delete ## Find all hidden files in /tmp/data/ (and it's sub-dirs) and delete it ## find /tmp/data/ -type f -name ".*" -delete

## List all hidden dirs in /etc/ ##
find /etc/ -maxdepth 1 -type d -name “.*” ## List all hidden files in /etc/ ##
find /etc/ -maxdepth 1 -type f -name “.*” ## Find all hidden files in /tmp/data/ and delete it ##
find /tmp/data/ -maxdepth 1 -type f -name “.*” -delete ## Find all hidden files in /tmp/data/ (and it’s sub-dirs) and delete it ##
find /tmp/data/ -type f -name “.*” -delete

A note about the GNOME desktop environment and hidden files

In GNOME’s file manager, the keyboard shortcut Ctrl+H enables or disables the display of hidden files. CTRL+H act as a toggle button to hide or show hidden dot files in the GNOME.

Conclusion

This page explains how to remove hidden files in Linux or Unix-like operating systems. Further, it explained how to redirect output to avoid warning message while using the rm command.

Источник

How to delete .fuse_hidden* files?

I have small Linux server (Debian Squeeze) which runs a Samba server which is configured to share some folders with some windows machines. While trying to delete one of the directories from windows I received the «Cannot delete folder» error. I tried to delete the directory from the linux’s console I got a similar error:

# rm dir-name -rf rm: cannot remove `dir-name': Directory not empty 

I listed the contents of the directory and found a file named .fuse_hidden followed by a hex number (000bd8c100000185).

# ls -la dir-name -rwxrwxrwx 1 root root 5120 Feb 13 11:46 .fuse_hidden000bd8c100000185 

I tried to delete the .fuse_hidden file, but a new file was created instantly (note the hex number change).

# rm dir-name/.fuse_hidden000bd8c100000185 # ls -la dir-name -rwxrwxrwx 1 root root 5120 Feb 13 11:46 .fuse_hidden000bd8c100000186 

I also tried using Midnight Commander to delete the file with no success. Other solutions I have found so far involve GUI and I’ve only got console. Any suggestions are appreciated.

Читайте также:  Логи подключенных usb linux

That was my first thought but I couldn’t find a Fuse service to stop, I restarted Samba instead, problem solved, the file is gone. Thanks.

2 Answers 2

This is similar to what happens when you delete a file that another system has open on a NFS mount. The problem is that the file has been removed from the filesystem while its «link count» was >1, meaning that other processes are still holding it open.

  • Log in to the system where the file physically resides. (no network mount)
  • Execute lsof dir-name/.fuse_hidden000bd8c100000185 to find out what processes are holding the file handle open.
  • Terminate those processes if it makes sense to, or figure out what steps you can perform to «gracefully» release the open file handle without terminating the process.

Normally, when you delete a file on your local filesystem that another process has open, the OS complies with your request and removes it from the directory tree, but the inode that tree points to is still considered in use by the operating system. Every time a file is opened, its «link count» increments by one, and the space is only truly released when that link count hits zero.

When you run into a problem of this nature, it means that the OS has for whatever reason decided to not remove that file from the directory tree: usually because it has reason to believe that it still needs to be accessed by things that can’t utilize the direct inode number. It might initially seem to comply, but behind the scenes the OS renames it to have a hidden dot-prefix so that is still accessible with some form of filesystem path addressing. The space will still be freed when the link count hits zero, but that object will will remain in the directory until the links are gone.

Источник

Оцените статью
Adblock
detector