'How to remove files from directory with certain extenions using command line in linux
I'm trying to use a system command in R to remove all files from a directory that have an extension of either .html or .png
I can remove files with one given extension type for example like:
system("rm -f ~/folder_path/*.html")
But I can't figure out how to remove files with one extension type or another. I have tried:
system("rm -f ~/folder_path/\\(*.html|*.png\\)")
But this errors with sh: 1: *.png): not found
R session information:
> sessionInfo()
R version 3.2.1 RC (2015-06-10 r68509)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.3 LTS
Solution 1:[1]
There is actually a simple way to do this using the rm command.
system("rm DIRECTORY/*.html;rm DIRECTORY/*.png")
Replace DIRECTORY with the name of your directory. This should remove all htmls and pngs from the directory.
Solution 2:[2]
Use the simple command
rm -rf /directory/*.file type
rm: for the rm gernal command -rf: for the remove all file forcefully *: for all files *.filetype: for all file extension like HTML, png, pdf etc
Real-world example: remove all pdf file from /home use this command:
rm -rf /home/*.pdf
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | alex_jwb90 |
| Solution 2 | Shoaib khan khattak |
