Linux / UNIX: Deleting Files In Many Subdirectories

How do I delete all files (only files and not subdirs) located in /var/pub/ftp/incoming and its subdirectories under Linux or UNIX operating systems?

You can use any one of the following command:
# find /var/pub/ftp/incoming -type f -delete
Your find command may not support -delete option, so use it as follows:
# find /var/pub/ftp/incoming -type f -print0 | xargs -0 -I file rm -f file
OR
# find /var/pub/ftp/incoming -type f -exec rm -f {} \;
You can also select file types. In this example, delete all *.exe files, enter:
# find /var/pub/ftp/incoming -type f -iname "*.exe" -exec rm -f {} \;

ADVERTISEMENTS

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
3 comments… add one
  • satish dubey Nov 19, 2012 @ 8:58

    find . -name *.* | xargs rm -rf *.*

    • dude May 14, 2013 @ 9:28

      No! That command does not do what you think it does.

      Your version: xargs rm -rf *.*
      is NOT tied to what is found by the find . -name part. If someone took that command as a template but instead of find *.* did something like find myfile123.*, your command would still delete everything, not just myfile123.*.

  • tesla Oct 24, 2013 @ 13:46

    Thanks a lot, that worked out very well.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.