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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. conky: command not found
  2. How to Create Yum Repository For System Packages Installation in CentOS/RHEL
  3. loadkeys: command not found
  4. i3-scrot Command Examples in Linux
  5. CentOS / RHEL : Move a Physical Volume from an existing Volume Group to another Volume Group
  6. auracle Command Examples
  7. find Command Examples in Linux
  8. module: command not found
  9. Log watching using tail or less
  10. pvck Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • powertop Command Examples in Linux
  • powertop: command not found
  • powerstat: command not found
  • powerstat Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright