|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
how can i to give input to rm command ? i would to delete all file of June. to get June file i write: ls -al | grep Jul | awk '{ print $9 }' but now i don't know how redirect this file list to rm command. thanks |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
In article <1185957832.034263.164380@19g2000hsx.googlegroups. com>,
Patrick <patrick.moresi@gmail.com> wrote: >Hi, >how can i to give input to rm command ? >i would to delete all file of June. to get June file i write: June? >ls -al | grep Jul | awk '{ print $9 }' Or July?? >but now i don't know how redirect this file list to rm command. thanks ls -al | awk '/Jul/{ print "rm",$9 }' > /tmp/somefile Next (and this step is very important), check over /tmp/somefile in your editor and make sure it is right. When you are sure, then do: sh /tmp/somefile |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 1 Aug., 13:30, gaze...@xmission.xmission.com (Kenny McCormack)
wrote: > In article <1185957832.034263.164...@19g2000hsx.googlegroups. com>, > > Patrick <patrick.mor...@gmail.com> wrote: > >Hi, > >how can i to give input to rm command ? > >i would to delete all file of June. to get June file i write: > > June? > > >ls -al | grep Jul | awk '{ print $9 }' > > Or July?? > > >but now i don't know how redirect this file list to rm command. thanks > > ls -al | awk '/Jul/{ print "rm",$9 }' > /tmp/somefile > > Next (and this step is very important), check over /tmp/somefile in your > editor and make sure it is right. And if you have spaces in your filenames quote those names. (Or let the awk program print some quotes around $9.) Janis > When you are sure, then do: > > sh /tmp/somefile |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 1 Aug., 13:30, gaze...@xmission.xmission.com (Kenny McCormack)
wrote: > In article <1185957832.034263.164...@19g2000hsx.googlegroups. com>, > > Patrick <patrick.mor...@gmail.com> wrote: > >Hi, > >how can i to give input to rm command ? > >i would to delete all file of June. to get June file i write: > > June? > > >ls -al | grep Jul | awk '{ print $9 }' > > Or July?? > > >but now i don't know how redirect this file list to rm command. thanks > > ls -al | awk '/Jul/{ print "rm",$9 }' > /tmp/somefile > > Next (and this step is very important), check over /tmp/somefile in your > editor and make sure it is right. And if you have spaces in your filenames quote those names. (Or let the awk program print some quotes around $9.) Janis > When you are sure, then do: > > sh /tmp/somefile |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
In article <1185969399.900623.146700@l70g2000hse.googlegroups .com>,
Janis <janis_papanagnou@hotmail.com> wrote: .... >> ls -al | awk '/Jul/{ print "rm",$9 }' > /tmp/somefile >> >> Next (and this step is very important), check over /tmp/somefile in your >> editor and make sure it is right. > >And if you have spaces in your filenames quote those names. >(Or let the awk program print some quotes around $9.) Good point, but note that if the filenames have spaces in them, then $9 isn't going to pick it up anyway. So, you'll have to re-analyze that part of the problem as well. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 1 Ago, 14:07, gaze...@xmission.xmission.com (Kenny McCormack)
wrote: > In article <1185969399.900623.146...@l70g2000hse.googlegroups .com>,Janis <janis_papanag...@hotmail.com> wrote: > > ... > > >> ls -al | awk '/Jul/{ print "rm",$9 }' > /tmp/somefile > > >> Next (and this step is very important), check over /tmp/somefile in your > >> editor and make sure it is right. > > >And if you have spaces in your filenames quote those names. > >(Or let the awk program print some quotes around $9.) > > Good point, but note that if the filenames have spaces in them, then $9 > isn't going to pick it up anyway. So, you'll have to re-analyze that > part of the problem as well. ok. Thanks to all Patrick |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On 1 Ago, 14:07, gaze...@xmission.xmission.com (Kenny McCormack)
wrote: > In article <1185969399.900623.146...@l70g2000hse.googlegroups .com>,Janis <janis_papanag...@hotmail.com> wrote: > > ... > > >> ls -al | awk '/Jul/{ print "rm",$9 }' > /tmp/somefile > > >> Next (and this step is very important), check over /tmp/somefile in your > >> editor and make sure it is right. > > >And if you have spaces in your filenames quote those names. > >(Or let the awk program print some quotes around $9.) > > Good point, but note that if the filenames have spaces in them, then $9 > isn't going to pick it up anyway. So, you'll have to re-analyze that > part of the problem as well. ok. Thanks to all Patrick |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On 1 Aug., 14:07, gaze...@xmission.xmission.com (Kenny McCormack)
wrote: > In article <1185969399.900623.146...@l70g2000hse.googlegroups .com>,Janis <janis_papanag...@hotmail.com> wrote: > > >> ls -al | awk '/Jul/{ print "rm",$9 }' > /tmp/somefile > > >> Next (and this step is very important), check over /tmp/somefile in your > >> editor and make sure it is right. > > >And if you have spaces in your filenames quote those names. > >(Or let the awk program print some quotes around $9.) > > Good point, but note that if the filenames have spaces in them, then $9 > isn't going to pick it up anyway. So, you'll have to re-analyze that > part of the problem as well. Indeed, right you are. Having now a closer look at the OP's task I wonder why there's the -a option; it would be "tricky" to remove . and .. with a rm command. And the pattern /Jul/ should be restricted to the respective date field as to not accidentally remove a file called Julian.txt or any file that has a user or group field containing "Jul". And some systems have a different number of fields in the ls command, depending on whether the file is older than 6 months or not. ....there's still some work to make that command more robust. Janis |
|
![]() |
| Outils de la discussion | |
|
|