From: mop2 on 12 Feb 2010 06:01 On Fri, 12 Feb 2010 03:53:04 -0200, Hongyi Zhao <hongyi.zhao(a)gmail.com> wrote: > On Fri, 12 Feb 2010 16:31:36 +1100, Ben Finney > <ben+unix(a)benfinney.id.au> wrote: > >> As usual, âfind(1)â is your friend. Read about the â-maxdepthâ and >> â-sizeâ options. > > In my case, I want to delete the empty files just in the current > directory among the following names: > > myfile.pdf > myfile.1.pdf > myfile.2.pdf > myfile.3.pdf > ... > > I use the following code: > > find . -maxdepth 1 -name "myfile*".pdf -type f -size 0 -exec rm > {} \; > > This will do the trick, but I still have the following issues: > > 1- The "myfile*".pdf regexp is too loose and may lead to some > files, > say, myfileone.pdf, been deleted accidentally. So, how can I > improve > the match pattern to perform exact search and remove operations? > > 2- The above code is based on someone else's examples on the > internet. > I don't understand the function of the *{} \* part in the end. Any > hints? > > Regards. Are just 4 pdf files? So with bash (I don't know about others) you can try: for f in myfile.pdf myfile.{1..3}.pdf;do [ -e $f ]&&[ ! `head -c1 $f` ]&&rm $f; done
From: Stephane Chazelas on 12 Feb 2010 05:35 On 2010-02-12, Hongyi Zhao <hongyi.zhao(a)gmail.com> wrote: [...] > I want to delete empty files in the current directory but not the ones > in the sub-directories of current directory. Any hints? [...] With zsh: rm myfile*.pdf(.L0) -- Stephane
From: Laurianne Gardeux on 12 Feb 2010 05:19 Hongyi Zhao à écrit : > Hi all, > > I want to delete empty files in the current directory but not the ones > in the sub-directories of current directory. Any hints? > > Regards. With the GNU find: $ find . -maxdepth 1 -type f -empty -delete LG
From: Kaz Kylheku on 12 Feb 2010 11:23 On 2010-02-12, Hongyi Zhao <hongyi.zhao(a)gmail.com> wrote: > In my case, I want to delete the empty files just in the current > directory among the following names: > > myfile.pdf > myfile.1.pdf > myfile.2.pdf > myfile.3.pdf > ... > > I use the following code: > > find . -maxdepth 1 -name "myfile*".pdf -type f -size 0 -exec rm {} \; > > This will do the trick, but I still have the following issues: You can't accurately match the above set with a single file glob, because the glob language lacks disjunction. But find has disunction: the -o (or) operator. -maxdepth 1 \( -name myfile.pdf -o -name "myfile.[0-9].pdf" \) ... Say, do you need a diaper change and burp?
|
Pages: 1 Prev: Wait for a process from a different shell Next: rsync performance |