• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to run “find” command on current directory only and not on sub-directories

by admin

Question: How to perform find commands on the current directory, without going into the subdirectories.

Example Scenario:
– Remove all the files in the current directory ONLY that are a week old.

The Solution

1. Add the following operations to the desired find commands:

! \( -type d ! -name {DIRECTORY NAME} -prune \)

2. Substituting the directory to be searched for {DIRECTORY NAME}

Example Solution:

# find . ! \( -type d ! -name . -prune \) -mtime 7 -exec rm {} \;

The above command will only search in the current directory (.) and not the sub-directories under it and will remove file that are older than 1 week.

Filed Under: Linux

Some more articles you might also be interested in …

  1. “docker system” Command Examples
  2. How to Change Password Of An LXC Container User Account
  3. locale: command not found
  4. hdparm: command not found
  5. gow Command Examples
  6. “git verify-tag” Command Examples
  7. AdGuardHome – A network-wide software for blocking ads & tracking (Command Examples)
  8. po4a-updatepo: command not found
  9. sesearch: command not found
  10. locate Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright