Remove jpg and text files at command line

Posted on 2007-10-10
Last Modified: 2013-12-16
I am using the following line to remove jpg files in subdirectories using the sh shell

find dir1 dir2 -name '*jpg' -exec rm -f {} \;

What is the proper way to change this command to include txt files as well?
Question by:pda4me
    LVL 58

    Accepted Solution

    find dir1 dir2 \( -name '*.jpg' -o -name '*.txt' \) -exec rm -f {} \;


    find dir1 dir2 \( -name '*.jpg' -o -name '*.txt' \) -print \;

    before to confirm that the command is working correctly.
    LVL 84

    Assisted Solution

    find dir1 dir2  \( -name '*jpg' -o  -name '*.txt' \)  -exec rm -f {} \;

    Author Comment


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
    SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now