Remove hidden 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’.

Читайте также:  Настройка bind alt linux
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.

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

Related Posts

Источник

Working with Hidden Files in Linux

In Linux, a file that has a “.” (dot) at the beginning of its name is said to be a hidden file. The “.bashrc”, “.bash_profile”, “.bash_history”, and “.bash_aliases” files in the home directory are the representation of the hidden files.

This article will illustrate the explanation of hidden files along with possible examples.

How to Create a Hidden File and Directory in Linux?

To create a hidden file, utilize the “touch” command by specifying the filename as “.sample.txt” in the following script:

Note: Similarly, a hidden directory can be created using the “mkdir” command and the “dot” before the name. as demonstrated below:

How to View Hidden Files in Linux?

Users can utilize the “ls -a” and “find” commands to view hidden files and directories of a current directory.

Use ls -a Command

Users can utilize the “ls -la” command to list all files, including hidden files, in a directory. For this, execute the below script in the desired directory:

The outcome of the above command shows all hidden files and directories in the Linux.

Using find Command

You can view hidden files and directories using the “find” command in the terminal. For this, the “/home/itslinuxfoss” path is specified:

$ find /home/itslinuxfoss -name ".*"

It explores all files and directories starting with a dot(.) in the “/home/itslinuxfoss” path.

Читайте также:  Alt linux установка virtualbox

How to Remove the Hidden Files in Linux?

To remove the hidden file or directory from the terminal, utilize the “rm” command by specifying the file name. For instance, “.sample.txt” is considered to remove the hidden file from the terminal:

After executing the above script, the “.sample.txt” file is deleted from the current directory.

Note: To remove the hidden directories, the “rmdir” command can be followed below:

How to Locate Hidden Files Using File Manager (GUI)?

To locate hidden files using a file manager with a GUI. Open the file manager on the system. Look for an option in the menu bar or toolbar called “View” or “Options.” Within that menu, look for an option to show hidden files or toggle a setting to show hidden files as below:

Once you have enabled this option, the hidden files are visible in the file manager.

Conclusion

The files/directories’ names starting with the “.dot” symbol are referred to as hidden files. Few of these are system defined and serve a specific purpose, i.e., configuration files, while these can also be created and managed by regular users. This post has briefly explained the working of hidden files in a Linux system.

Источник

Arch Linux

Hmm. this isn’t quite what I wanted. Should there be any .log.txt files (for example), I’d like to remove those but not touch . and .. which gives me an annoying error.

#2 2014-06-04 18:10:03

Re: How to remove just the hidden files?

That should still remove all the hidden files. If you want to hide the error, you can do

Читайте также:  Windows client for linux

#3 2014-06-04 18:14:48

drcouzelis Member From: Connecticut, USA Registered: 2009-11-09 Posts: 4,092 Website

Re: How to remove just the hidden files?

No problem! Check out this little trick:

Which will remove all files that begin with a dot and have at least two other characters in their filename. I use that syntax all the time.

. Hmmm, now that I think about it, it won’t catch filenames with only one character, such as «.a». But I’ve never seen a filename like that, so whatever.

Another option: Install «moreutils» and use «vidir». But that wouldn’t be any good in a script.

Last edited by drcouzelis (2014-06-04 18:15:27)

#4 2014-06-04 18:19:58

Re: How to remove just the hidden files?

That should still remove all the hidden files. If you want to hide the error, you can do

Thanks. I’ll keep this in mind. I don’t want to hide the error though.

I have something else cooking at the moment.

#5 2014-06-04 18:21:15

Re: How to remove just the hidden files?

No problem! Check out this little trick:

Which will remove all files that begin with a dot and have at least two other characters in their filename. I use that syntax all the time.

. Hmmm, now that I think about it, it won’t catch filenames with only one character, such as «.a». But I’ve never seen a filename like that, so whatever.

Another option: Install «moreutils» and use «vidir». But that wouldn’t be any good in a script.

#!/bin/sh # copy all information that is in our data directory to the current directory, # afterwards delete it (again, first copy, then delete, same as the pouch # utility.) Do this for the hidden and not hidden files. HIDDEN_FILES=`ls -a1 ~/.pouch/data/` for i in $HIDDEN_FILES do if [ $i != '.' ] && [ $i != '..' ] then cp -r ~/.pouch/data/$i . rm -rf ~/.pouch/data/$i fi done

You’re more than welcome to comment on suggestions and improvements.

Источник

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