Score:-3

Exclude a directory when using 'plocate'?

lt flag

So after using the locate command on Linux Mint a lot, I ran into the issue of every query returning rows upon rows of results in the /timeshift/ directory - what Linux Mint uses as OS save points.

If I used, say, locate anaconda activate.sh, what I might get is:

/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts
/conda-activate.sh
/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh
/home/user/.anaconda3/pkgs/spyder-5.1.5-py39h06a4308_1/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-01-09_15-00-01/localhost/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-01-09_15-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh
/timeshift/snapshots/2023-01-09_15-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/deactivate.d/deactivate.sh
/timeshift/snapshots/2023-01-09_15-00-01/localhost/home/user/.anaconda3/pkgs/spyder-5.1.5-py39h06a4308_1/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-10_04-00-01/localhost/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-10_04-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh
/timeshift/snapshots/2023-02-14_20-00-01/localhost/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-14_20-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh
/timeshift/snapshots/2023-02-14_20-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/deactivate.d/deactivate.sh
/timeshift/snapshots/2023-02-14_20-00-01/localhost/home/user/.anaconda3/pkgs/spyder-5.1.5-py39h06a4308_1/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-15_21-00-01/localhost/home/user/.anaconda3/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/scripts/conda-activate.sh
/timeshift/snapshots/2023-02-15_21-00-01/localhost/home/user/.anaconda3/pkgs/conda-4.12.0-py39h06a4308_0/info/test/tests/test-recipes/activate_deactivate_package/src/etc/conda/activate.d/activate.sh

Only the top three results are relevant, so how would one exclude a directory?

Voxel avatar
lt flag
Tried posting this one to StackOverflow already, but it was closed because it's apparently unrelated to "software tools primarily used by programmers" *shrug*
Pilot6 avatar
cn flag
This is off-topic here too and will also be deleted.
guiverc avatar
cn flag
Only Ubuntu and [official flavors of Ubuntu](https://ubuntu.com/download/flavours) are on-topic here, refer https://askubuntu.com/help/on-topic where you'll find other SE sites where you question will be welcome if you don't want to use a Linux Mint forum. (*One advantage of Ubuntu is it's many support options, you opted for Linux Mint so take advantage of its support options, or SE Unix & Linux* found in the on-topic link)
andrew.46 avatar
in flag
@Voxel It is a great question and answer; could you perhaps test your question and answer with an Ubuntu VM (where doubtless the results will be the same) and alter these details in your question? I will then undertake to reopen and clear away the comments.
NotTheDr01ds avatar
vn flag
@Voxel Alternatively, it really should be on-topic on either the [Unix & Linux Stack](https://unix.stackexchange.com) or [Super User](https://superuser.com). I'd lean towards U&L.
Score:5
lt flag

Manually exclude a directory with grep

You can use the -v option to get grep to output all the elements that don't match the supplied Regex, like so:

locate anaconda activate.sh | grep -v "/timeshift/"

This will print only paths which don't contain the string /timeshift/


Permanently exclude a directory

Since the issue with the timeshift directory is a frequently re-occuring one, you might want to permanently exclude it from all plocate queries.

As per the updatedb documentation, you may add /timeshift to PRUNEPATHS= in /etc/updatedb.conf. Once updatedb has been run, all plocatequeries should now exclude the /timeshift directory.

guiverc avatar
cn flag
Thank you for attempting to share your discovery/solution, it would have been useful if on-topic for this site (or placed on SE *Unix & Linux* where it is on-topic)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.