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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. CentOS / RHEL 6 : How to Save iptables Rules
  2. How to Use the ssh-keygen Command to configure passwordless ssh
  3. Linux OS Service ‘ldap’
  4. CentOS / RHEL : How to delete LUKS encrypted device
  5. Linux OS service ‘auditd’
  6. RHEL 7 – RHCSA Notes – vi/vim editor
  7. Basics of Ethernet Bonding in Linux
  8. How to Use Udev Rules to Create oracleasm Disks in CentOS/RHEL 8
  9. How to enable/disable SELinux Modes in RHEL/CentOS
  10. Understanding DM-multipath deamon (multipathd)

You May Also Like

Primary Sidebar

Recent Posts

  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • How to Capture More Logs in /var/log/dmesg for CentOS/RHEL
  • Unable to Start RDMA Services on CentOS/RHEL 7
  • How to rename a KVM VM with virsh
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary