Tuesday, February 17, 2009

How to manage file : when name contains "-" as first character


when name contains "-" as first character
u can use "./"
Error:
#rm -sealert_12012009.log
rm: invalid option -- s
Try `rm ./-sealert_12012009.log' to remove the file `-sealert_12012009.log'.
Try `rm --help' for more information.


Ex.

#ls -l
-rw-rw-r-- 1 root root 0 Jan 12 18:39 -sealert_12012009.log
-rw-rw-r-- 1 root root 0 Jan 13 18:39 -sealert_13012009.log
....

Remove:
#rm ./-*.log

Move:
#mv ./-*.log /tmp/archive

when name contains " "(space) or thai char
if file name contains a space example "rman purge.txt". Add double quotes " to all argument.
Ex.
Remove:
#cd $SOURCE_PATH
#ls|while read line;do rm -i "$line";done

Move:
#cd $SOURCE_PATH
#ls|while read line;do mv -f "$line" /tmp/archive;done


^__^