Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

command can be used to find files or folders matching a particular search pattern in linux

The find command can be used to find files or folders matching a
particular search pattern. It searches recursively.
Let's learn it by example.
Find all the files under the current tree that have the .js extension and
print the relative path of each file matching:



$ find . -name '*.js'



It's important to use quotes around special characters like * to avoid the
shell interpreting them.
Find directories under the current tree matching the name "src":



$ find . -type d -name src



Use -type f -name to search only files, oris case sensitive.
use -type l -iname to only search symbolic links.
to perform a case-insensitive search.
You can search under multiple root trees:



$ find folder1 folder2 -name filename.txt



Find directories under the current tree matching the name "node_modules"
or 'public':



$ find . -type d -name node_modules -or -name public
You can also exclude a path, using -not -path:



$ find . -type d -name '*.md' -not -path 'node_modules/*'



You can search files that have more than 100 characters (bytes) in them:



$ find . -type f -size +100c



Search files bigger than 100KB but smaller than 1MB:



$ find . -type f -size +100k -size -1M



Search files edited more than 3 days ago



$ find . -type f -mtime +3



Search files edited in the last 24 hours



$ find . -type f -mtime -1



You can delete all the files matching a search by adding the -delete option.
This deletes all the files edited in the last 24 hours:



$ find . -type f -mtime -1 -delete



You can execute a command on each result of the search. In this example we run
cat to print the file content:



$ find . -type f -exec cat {} ;



notice the terminating ;
{} is filled with the file name at execution time.
Comment

PREVIOUS NEXT
Code Example
Shell :: grep something before 
Shell :: docker quickstart terminal windows 
Shell :: git show log after date 
Shell :: find hidden directories and files from a website wfuzz 
Shell :: terminal theme 
Shell :: pip install caffe 
Shell :: My first git commit 
Shell :: git update branch from master 
Shell :: rpi install kodi 
Shell :: crontab edit 
Shell :: uninstall anaconda in ubuntu 
Shell :: linux command find program 
Shell :: enale scp in ubuntu 
Shell :: remote: ! You are trying to install ruby-2.7.0 on heroku-20. 
Shell :: add my current project to an already existing GitHub repository 
Shell :: fold all lines in vim 
Shell :: linux count lines csv files 
Shell :: how to customize zsh 
Shell :: how to restore default apache httpd conf file 
Shell :: run powershell script by clicking 
Shell :: chown recursive 
Shell :: merge two branches in git command 
Shell :: set up vim in zsh 
Shell :: laserjet m1132 mfp driver linux mint download 
Shell :: git pull rebase command 
Shell :: command running processes linux 
Shell :: ubuntu path of saving screenshots 
Shell :: what is echo in a batch file 
Shell :: git initialize 
Shell :: linux apps 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =