There are more than 1000 files in my log folder and i want to zip it to relase the space. But my method throwing
syntax error due to the multi part file name, how to overcome in this ?
Thanks everyone for the reply. But am still getting the same error.
for i in `ls -lart | grep "MDB_Kernel11.1_gwlog_TUE 24_09_2013 *" | head -10 | awk '{print $9,$10,$11,$12}' `
> do
> rm "$i"
> done
rm: MDB_Kernel11.1_gwlog_TUE: A file or directory in the path name does not exist.
rm: 24_09_2013: A file or directory in the path name does not exist.
rm: 03_37_06: A file or directory in the path name does not exist.
will set the variable i to the elements in the output from the pipeline split on the spaces and newlines in the output. You need something that will just split on the newlines. If you didn't want to restrict your processing to the oldest ten matching files, you could just use:
for i in "MDB_Kernel11.1_gwlog_SUN 22_09_2013"*
With the restriction, you could try:
ls -rt "MDB_Kernel11.1_gwlog_SUN 22_09_2013"* | head -10 | while IFS='' read -r i
do gzip "$i"
done
but I'm guessing you probably want something like:
ls -rt "MDB_Kernel11.1_gwlog_SUN 22_09_2013"* | grep -v '.gz$' | head -10 | while IFS='' read -r i
do gzip "$i"
done