Tag Archives: find

Best way to exclude a folder from your search using the “find” command

I found it to be the fastest and most effective way to use the find command and exclude specific folders. That is using the “prune” option: find /FOLDER_TO_SEARCH_INSIDE -path /FOLDER_TO_EXCLUDE -prune -o -name ‘NAME_OR_PATTERN_TO_SEARCH_FOR’ -print That’s it, Enjoy! Source: https://stackoverflow.com/questions/4210042/how-to-exclude-a-directory-in-find-command

Posted in Linux | Tagged , , , | Leave a comment

Delete files older than X days

find /path/to/folder -mtime +14 -exec rm {} \; This finds all files within that folder that are older than 14 days, then executes rm on them

Posted in Uncategorized | Tagged , , , , | Leave a comment

Bash Script To Find and Delete All Files Except Some When the filesystem reaches a specific size

#!/bin/sh # This script checks if the /siebel filesystem reaches the warning limit of free space# And then delete the old logs except those of last 12 hours warninglimit=1572864    # This number is in KB, it’s equal to 1.5 GB,                        … Continue reading

| Tagged , | Leave a comment

"Find All EXCEPT" using bash script

find . \( ! -name “hobba*” \) The above command invokes the “find” command asking it to search in the current directory (“.”) and return all files except those starting with the string “hobba”. Note: Take care of the spaces … Continue reading

| Tagged , | Leave a comment

Searching for a string inside multiple files and output the name of the files containing that string

find . -name “*” | grep -i ecomm | xargs ls -las | grep “Aug 27” | awk ‘{print $10}’ | xargs grep -i string_to_search_for | grep -i “\.log” | awk ‘{print $1}’ where: “ecomm” is part of the name … Continue reading

| Tagged , | Leave a comment

find files and copy them to a certain folder in bash (draft)

find . -name “*” | grep -i scomm | xargs ls -ltr | grep “Aug 13 10” | awk ‘{print $9}’ to use in the cp command (get the column number 9 which contains the file’s full path cp `find … Continue reading

| Tagged , , | Leave a comment

How to search for a string inside multiple text files

find starting_folder -name “*” | grep -i file_name | xargs grep -i search_string for example: “find . -name “*” | grep -i hobba | xargs grep -i tito” searches for the string “tito” inside all files whose name contains the … Continue reading

| Tagged , , | Leave a comment