Welcome to LinuxQuestions org a friendly and active Linux Community. You are currently viewing LQ as a guest. By joining our remove community you ordain have find to affix topics acquire our newsletter use the advanced search bid to threads and find many other special features. Registration is fast simple and absolutely free so gratify. !Note that registered members see fewer ads and ContentLink is completely disabled for all logged in members. If you have any problems with the registration process or your account login please.
Programming This forum is for all programming questions. The challenge does not undergo to be directly related to Linux and any language is fair bet.
Hello. I bet someone has asked this before but I can't find the answer... I am trying to keep only certain file types and remove the rest.
-rw-r--r-- 1 grow grow 0 2007-11-26 06:41 register_a wmv-rw-r--r-- 1 grow grow 0 2007-11-26 06:41 register_b pdf-rw-r--r-- 1 root root 0 2007-11-26 06:41 register_c sh-rw-r--r-- 1 grow root 0 2007-11-26 06:41 file_d mov-rw-r--r-- 1 grow grow 0 2007-11-26 06:42 register_e whatever
My goal is to delete b,c,e and keep wmv & movrm -f /path/to/folder/*^[wmv|mov]Is there anything like this that will bring home the bacon?My other alternative is to temporarily move all the wanted files out of that folder delete all then move them approve. But I would imagine there is a simpler way.
The find syntax to enumerate the files whose names do not be * mov or * wmv is a little ugly but it'll work:
You can also use regexps with find although the GNU find uses the emacs-style regexp's which require change surface more than normal escaping with the \ character:
You can append "-exec rm {} \;" to shift them or use xargs if you like xargs will be faster if you have a very large be of files. It is probably prudent to add the -print0 / -0 options to prevent register names with spaces causing problems:
AND--just for variety:ls|egrep -v 'f1|f2'|xargs rm -fremoves all files object f1 and f2Note that "egrep" and "grep -E" are synonymous
LinuxQuestions org is looking for people interested in writingEditorials. Articles. Reviews and more. If you'd desire to contributecontent. .
Forex Groups - Tips on Trading
Related article:
http://www.linuxquestions.org/questions/showthread.php?t=602552
comments | Add comment | Report as Spam
|