It's a good idea to check what files you'll be deleting first by checking the xargs. linux shell take is as switch for next line of current command. That's not quite how the -r switch of rm works:-r, -R, --recursive remove directories and their contents recursively rm has no file searching functionality, its -r switch does not make it descend into local directories and identify files matching the pattern you give it. In the following script, an empty file is created by using the ‘touch’ command to test ‘rm‘ command. To delete all files and folders newer than (with a file modification time newer than) N days, use -N instead of +N: find /directory/path/ -mindepth 1 -mtime -N -delete Example in which we'll remove all files and folders from ~/Downloads that had their contents modified between now and 10 days ago: find ./ -name "*.orig" | xargs If you notice a file that's been found that you don't want to delete either tweak your initial find or add a grep -v step, which will omit a match, ie You can apply the ‘rm’ command to remove an existing file. The following sed command will remove the lines which match the System pattern in ‘sed-demo.txt’ file . The below will print out the files you've found. How to delete a file named as "\" alone. Next, ‘rm’ command is used to remove the file, test.txt. For example, you only need to delete files with “.log” extension and modified before 30 days. Command Syntax. Please help me even i couldn't find any idea on googling about this. Delete Files with Specific Extension. Here is a sample list of file names: The problem and solution. find /path/to/files* -mtime +5 -exec rm {} \; The basic find command syntax is as follows: find dir-name criteria action Where, dir-name: – Defines the working directory such as look into /tmp/; criteria: Use to select files such as “*.sh”; action: The find action (what-to-do on file) such as delete the file. We’ll use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them. The find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. The rm command deletes files in a Linux. Example-1: Delete the file using `rm` command without the option. You actually need read and write permissions on the directory, not on the file itself since the operation is done considering the permissions effects of directories.. A good documentation can be found on this link, which mentions the below in the section Special Considerations on Directories:. find /opt/backup -type f -mtime +30 -exec rm -f {} \; 2. However, this syntax works only for files. Instead of deleting all files, you can also add more filters to find command. Sample file list. We will try to delete all GIF files from the folder using the following: $ rm *.gif Delete Files with Particular Extension. To delete a single file, entering the following in the command line: The command unlinks the data from the file name, allowing the user to overwrite on that particular storage space. Remove File Using SubString of Filename Remove Files with File Extension in Linux. # sed '/System/d' sed-demo.txt After deletion: 3 RHEL 4 Red Hat 5 Fedora 6 Arch Linux 7 CentOS 8 Debian 9 Ubuntu 10 openSUSE 8) … If all okay, execute below command to delete those files. In this quick tip I am going to show you to delete or copy files with names that contain strange characters on Linux. Your default bash shell considers many of these special characters (also known as meta-characters) as commands. thanks in advance. 7) Removing lines that contain a pattern. It's hard to remove to me becoz if i specify "\" eventhough its a name of file. Find And Remove Files With One Command On Fly. Let’s take another example.