• Home
  • SEM
    • PPC
    • SEO
    • How To
  • Bangladesh
  • School
    • HTTP
    • REP
    • Bots n’ htaccess
    • Source Code
    • Excel 2010
    • HTML XHTML Entities
    • Gmail Operators
    • HTML & ASCII
  • About
    • Privy
    • About This Blog
  • Contact
  • বাংলা

Saidul Hassan

Digital Marketing Evangelist

Home / How to / How to Search and Delete Files Containing Specific String in Name

How to Search and Delete Files Containing Specific String in Name

27 Nov, 2017 By Saidul Hassan · Filed Under: How to

Open the terminal and go to the folder:
Find results and test if it yields your desired results:
find . -type f -name “*SpecificString*”
And if the find command results desired output, type in the following in the terminal to delete action:
find . -type f -name “*SpecificString*” -delete

Or a shorter version: find /path/to/your/files/ -type f -name “*SpecificString*” -delete

For home folder:

!!! first run a test

find ~ -type f -name “*SpecificString*”

and than

find ~ -type f -name “*SpecificString*” -delete

For the whole filesystem

!!! first run a test !!!

sudo find / -type f -name “*SpecificString*”

and test again and than delete with

sudo find / -type f -name “*SpecificString*” -delete

Or only in the specified directory:

find /path/to/your/files/ -maxdepth 1 -type f -name “*SpecificString*” -delete

How to list files based on matching only part of their filename?
Using find (this only includes files)

find -type f -name “Account*”

Using ls (this might include folder as well)

ls -1 Account*

Using ls and grep (grep, this could include folder as well)

ls -1 | grep -E “^Account”
Recursively Find & Move all files with a certain extension from multiple subdirectories into one directory

Find files:

find . -iname ‘*.mp4’
Syntax: find /source/folder/ -iname “*.FileExtension” [Current directory: . Case Insensitive: -iname]

find src/dir/ -name ‘*.txt’ -exec mv {} target/dir/ \;

Move files:

find . -iname ‘*.gif’ -exec mv {} “/path/to/single/target/directory/GIF” \;

More example usage of find command

Find Size between 50MB – 100MB
find / -size +50M -size -100M
Find all .mp3 files with more than 10MB and delete them
find / -type f -name *.mp3 -size +10M -exec rm {} \;
Find files larger than 10mb
find -size +10M
Find file with specific name (case unsensitive)
find -iname nameofthefile.txt
Find a specific file type
find -type f -name “*.zip”
Find and remove Multiple File
find . -type f -name “*.torrent” -exec rm -f {} \;
Find all Empty Directories
find /tmp -type d -empty
File all Hidden Files
find /tmp -type f -name “.*”
Find Last 50 Days Modified Files
find / -mtime 50
Find Last 50 Days Accessed Files
find / -atime 50
Find Last 50-100 Days Modified Files
find / -mtime +50 –mtime -100
Find Changed Files in Last 1 Hour
find / -cmin -60
Find Modified Files in Last 1 Hour
find / -mmin -60
Find Accessed Files in Last 1 Hour
find / -amin -60

The following two tabs change content below.
  • Bio
  • Latest Posts
My Twitter profileMy Facebook profileMy LinkedIn profileMy Instagram profileMy Pinterest profile

Saidul Hassan

Managing Partner at Up Arrow Consulting
COO at Up Arrow Consulting, MCC manager, & Technical SEO consultant. Certified Google Partners and Microsoft Bing Ads Accredited Professional, Python enthusiast, wannabe SysAdmin. Graduated from School of Management & Business Administration (SOMBA), Khulna University.
My Twitter profileMy Facebook profileMy LinkedIn profileMy Instagram profileMy Pinterest profile

Latest posts by Saidul Hassan (see all)

  • Batch script to create directories & moving fixed number of files to those directories - 30 Apr, 2021
  • How to use PrismJS syntax highlighter on WordPress without plugin - 30 Mar, 2020
  • Download an Entire Website for Offline Viewing - 26 Nov, 2019

Share:

  • Twitter
  • Facebook
  • LinkedIn
  • Pinterest
  • Pocket
  • Email
  • Print

First published on 27 Nov, 2017 · Last updated 27 Nov, 2017 · Tagged With: find, grep, Terminal

Batch script to create directories & moving fixed number of files to those directories

30 Apr, 2021 By Saidul Hassan

How to use PrismJS syntax highlighter on WordPress without plugin

30 Mar, 2020 By Saidul Hassan

Download an Entire Website for Offline Viewing

26 Nov, 2019 By Saidul Hassan

How to color highlight .htaccess files in Xed/Gedit

20 Aug, 2018 By Saidul Hassan

HMA Pro VPN Setup for Multiple Locations without User/Password Every time in Linux CLI

14 May, 2018 By Saidul Hassan

  • ♥ Bangladesh ♥
    Log in · Privacy Policy · Contact
    Copyright © 2011 Saidul Hassan

  • DMCA