• 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. How to Ignore/Disable Specific auditd Logging Entries
  2. lxterminal: command not found
  3. Linux / UNIX : How to create extended partition using fdisk
  4. How to Set External Network For Containers in Linux Containers (LXC)
  5. How Files/Directories in /tmp gets Removed Automatically in CentOS/RHEL 5,6
  6. git browse: View an upstream repository in the default browser
  7. Maintaining Linux filesystems using “fsck” and “tune2fs”
  8. gitsome Command Examples
  9. goaccess Command Examples in Linux
  10. ack – A search tool like grep, optimized for developers (Command Examples)

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright