Tips / Linux
addthis
Delete files and directory from an ls excluding specific pattern
Author: Katrame
Visits: 393
Date: 05.02.2008

 

# ls -lah |grep codelime |grep -v 2008-02-05|tr -s ' '|cut -f 8 -d ' '|xargs rm -rf

 Explain:

- ls -lah

    list files/dir

- |grep codelime

    catch specific pattern "codelime"

- |grep -v 2008-02-05

    exclude specific pattern "2008-02-05"

- |tr -s ' '

    uniform space from columns to a single space

- | cut -f 8 -d ' '

    extract a single column (in this case the number 8 that equal to filename/dirname)

- |xargs rm -rf

    execute rm command to the out of the previous commands

 

 




Page 1 of 1


Se vuoi discutere con noi su questo articolo o comunque vuoi porci delle domande usa il nostro Forum

COMMENTI

Aggiungi un commento! +
(I commenti verranno moderati prima della pubblicazione)



Top