[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

RE: Need scripting or redirection help in BASH



hi ya


On Mon, 7 Jan 2002, Kurc, Marcin A. wrote:

> #!/bin/bash
> for i in $(ls -l ./ |grep "Dec  21" | awk '{print $9}');
>     do
> 	  rm -rf $i
> done			
> 
> btw, check out http://www.linuxdoc.org/HOWTO/Bash-Prog-Intro-HOWTO.html and
> http://www.linuxdoc.org/LDP/abs/html/

if the filename ( $i ) has spaces or  '  in it... you're in trouble ;-)
...
hopefully you dont have windoze people sharing that disk/directory tree

	"Program Files for Tom SW"
	"Backup files from Sam's workstation"
	MyReleasedLinuxSW.CVS
	My_Test_SW
	SW
	CVS

-- use rm -f " filename "  but make sure that "filename" has no double
   quotes and if it does use ' and it the files have ' use some unique
   string for only that filename-with-ticks-n-quotes

-- use rmdir for empty dirs...
	- cd into the dir and remove the files first?? -- too much
	work...but...

	- simpler to just tell people dont use "'" in the filename...
	so there supposedly wont be anything like "bob's files"

have fun
alvin

...
	
> and inspected the lot.  There should be a way to delete these files
> using grep and redirection/piping or a shell script.  My thought is some
> kind of iterative script, in pseudo code:
> 
> for x in ( ls -l | grep "Dec 21" )
>     do 
>         rm x( suitably parsed )
>     done
> exit 
> 



Reply to: