Finding any file anywhere

Every day solutions to every day challenges. + Brilliant stuff

Moderators: b1o, jkerr82508

Forum rules
Please feel free to post your tip it does not have to be advanced. Also ask questions directly related to the tip here. But do not start new threads with questions or ask for help here. That is what the help section is for. forum rules: http://bjoernvold.com/forum/viewtopic.php?f=8&t=568
User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Finding any file anywhere

Postby viking60 » 04 Oct 2014, 15:19

To quickly find any file anywhere on your Linux system locate will do the job. I like to search for patterns and when I trace those spying Super cookies; finding extensions with *.sol will reveal them.
So this is what I did:

Code: Select all

locate "*.sol"

And sure enough it revealed all the places those rascals were hiding:

Code: Select all

/home/viking/.config/chromium/Default/Pepper Data/Shockwave Flash/WritableRoot/#SharedObjects/869W26XX/macromedia.com/support/flashplayer/sys/settings.sol
/home/viking/.config/chromium/Default/Pepper Data/Shockwave Flash/WritableRoot/#SharedObjects/869W26XX/macromedia.com/support/flashplayer/sys/#www.flashgames247.com/settings.sol
/home/viking/.config/chromium/Default/Pepper Data/Shockwave Flash/WritableRoot/#SharedObjects/869W26XX/www.flashgames247.com/games/sushi-cat-2.swf/Sushi-Cat-2.sol
/home/viking/.tor-browser-en/INSTALL/.macromedia/Flash_Player/macromedia.com/support/flashplayer/sys/settings.sol


The standard flash player setting has a settings.sol so that is "normal" but sushi-cat-2.swf/Sushi-Cat-2.sol is put there by a flash game.

So I made myself an alias to remove all of them and checked again

Code: Select all

locate "*.sol"

- and they were gone.

Then I used flash again and those files and directories were generated again and filled with *.sol files...but this time

Code: Select all

locate "*.sol" 
did not show them!

So can this command not be trusted to find any file on your system?

Yes it can! But it needs a database to make that quick search so when you change stuff on the fly like this - you need to update the database.

Code: Select all

su
updatedb


After that locate will find anything again....
...or you can use

Code: Select all

find -name "*.sol"

(which is way slower than locate but more precise)
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Finding any file anywhere with "find"

Postby viking60 » 13 Jun 2015, 13:04

Find is a very powerful tool that has a lot of flexibility - that means more complexity too.

To find a all files named *.png on your system you would enter this command:

Code: Select all

find -name / "*.png"

To find all png files in /etc you would enter this:

Code: Select all

find /etc -name "*.png"

If you do not enter a location it will start the search from the directory you are in; usually ~/
(remember to use sudo or be root if you are not searching your Home directory)

To combine the search to find both *.png and *.jpg files; you can do something like this:

Code: Select all

find  -name "*.png" -or -name "*.jpg"

(You do not need to write the full word "-or" a simple "-o" will do :-D )

Now let us say you want to only find Directories then you can add "-type" to the equation:

Code: Select all

find -name "Downloads" -type d

The types are d for Directory f for files and l for Links.

So if you use a multinational computer you might want to check several names for the Download directory:

Code: Select all

find  -name "Nedlastinger" -or -name "Downloads" -type d

Mostly I wonder where I saved that #! :f file that I cannot find again so the type f is much used here:

Code: Select all

find  -name "Document.*" -or -name "document-*" -type f

This will find anything named document or Document with any extension so document icons for your theme etc will also be shown.

Find has a lot more to offer than this - here is a practical example:

We all know that those flash cookies violate your privacy because they will not respect the cookie settings in your browser.
To remove all of those supercookies in your home you can use find to locate them and delete them:

Code: Select all

find ~/ -name "*.sol" -delete

Now they are all gone :jackpot
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
dedanna1029
Sound-Berserk
Posts: 8784
Joined: 14 Mar 2010, 20:29
Contact:

Re: Finding any file anywhere

Postby dedanna1029 » 09 Sep 2015, 23:14

I used to use locate a lot - I think I will again. It really is very powerful, and flexible.
I'd rather be a free person who fears terrorists, than be a "safe" person who fears the government.
No gods, no masters.
"A druid is by nature anarchistic, that is, submits to no one."
http://uk.druidcollege.org/faqs.html


Return to “Tips & Tricks”