I'm trying to make a tar.tgz file using command substitution
There are backups of 17 Aug 2012
-rw-r----- 1 ossec 502 804M Aug 17 2012 BKPMDISINT_i6nir20j.F_bkp
-rw-r----- 1 ossec 502 2.7G Aug 17 2012 BKPSYFINT_i5nir20j.F_bkp
-rw-r----- 1 ossec 502 3.9G Aug 17 2012 BKPMSFFINT_i4nir20j.F_bkp
-rw-r----- 1 ossec 502 28M Aug 17 2012 c-651746692-20120817-00
-rw-r----- 1 ossec 502 2.0G Aug 17 2012 ALG_KLPFINT_ianir576.alg
-rw-r----- 1 ossec 502 1.5G Aug 17 2012 ALG_KLPFINT_i8nir576.alg
-rw-r----- 1 ossec 502 37M Aug 17 2012 ALG_KLPINT_ibnir64h.alg
-rw-r----- 1 ossec 502 2.2G Aug 17 2012 ALG_KLPFINT_i9nir576.alg
-rw-r----- 1 ossec 502 28M Aug 17 2012 c-651746692-20120817-01
-rw-r----- 1 ossec 502 27M Aug 17 2012 ctrl_170803
So i need to tar them. I used this command
tar -zcvf DB-Backup-17082012.tgz $(ls -lrth|grep "Aug 17")
But it gave me this error
tar: You may not specify more than one `-Acdtrux' option
Try `tar --help' or `tar --usage' for more information.
ls -l | grep "Aug 17"
will also match files modified on Aug 17 within the past six months, as well as any file which happens to have "Aug 17" in its name, right? Generally, never parse the output of ls. I suggest looking at usingfind
, and paying particular attention to-daystart
and-mtime
.ls -l
totar
. You need to cut it up with either thecut
command orawk
.