Отлична штука этот awk! Вот сами смотрите!
Renaming within the name:
(although in some cases it will fail, as in file_old_and_old)
remove only files:
or with awk alone:
Be careful when trying this out in your home directory. We remove files!
remove only directories
or
or with awk alone:
Be careful when trying this out in your home directory. We remove things!
killing processes by name (in this example we kill the process called netscape):
or with awk alone:
ps auxww | awk '$0~/netscape/&&$0!~/awk/{print $2}' |xargs kill
It has to be adjusted to fit the ps command on whatever unix system you are on. Basically it is: "If the process is called netscape and it is not called 'grep netscape' (or awk) then print the pid"
Источник: http://www.linuxfocus.org/English/September1999/article103.html
Для познания дао смотри тут
ls -1 *old* | awk '{print "mv "$1" "$1}' | sed s/old/new/2 | sh
(although in some cases it will fail, as in file_old_and_old)
ls -l * | grep -v drwx | awk '{print "rm "$9}' | sh
or with awk alone:
ls -l|awk '$1!~/^drwx/{print $9}'|xargs rm
Be careful when trying this out in your home directory. We remove files!
ls -l | grep '^d' | awk '{print "rm -r "$9}' | sh
or
ls -p | grep /$ | wk '{print "rm -r "$1}'
or with awk alone:
ls -l|awk '$1~/^d.*x/{print $9}'|xargs rm -r
Be careful when trying this out in your home directory. We remove things!
kill `ps auxww | grep netscape | egrep -v grep | awk '{print $2}'`
or with awk alone:
ps auxww | awk '$0~/netscape/&&$0!~/awk/{print $2}' |xargs kill
It has to be adjusted to fit the ps command on whatever unix system you are on. Basically it is: "If the process is called netscape and it is not called 'grep netscape' (or awk) then print the pid"
Источник: http://www.linuxfocus.org/English/September1999/article103.html
Для познания дао смотри тут
Омайгад :) awk, конечно крут, но всё-таки не стоит так делать :)
ОтветитьУдалить1) mv $x `sed 's/old/new/g' <<< $x`
2) find -type f -delete
3) find -type d -delete
4) killall?
Почему не стоит? :)
ОтветитьУдалитьЭто просто примеры для демонстрации возможностей. Чтобы заинтересовать! :)
Тогда ок :)
ОтветитьУдалить