linux - How to tar the n most recent files -


i trying create script foreach directoy in folder folder, n recent files compressed.

however, having trouble multiple word files. need way wrap them in quote marks tar command knows wich each file.

here script far:

#!/bin/bash  if [ ! -d ~/backup ];     mkdir ~/backup fi  cd ~/folder in *;     if [ -d "$i" ];         original=`pwd`         cd $i         echo tar zcf ~/backup/"$i".tar.gz "`ls -t | head -10`"         cd $original     fi done echo "backup copied in $home/backup/" exit 0  

if [ ! -d ~/backup ];     mkdir ~/backup fi 

you can simplify :

[[ ! -d ~/backup ]] && mkdir ~/backup  

now answer question :

$ ls -t|head -10 file spaces file test.txt test test.sh $ lstfiles=""; while read; lstfiles="$lstfiles \"$reply\""; done <<< "$(ls -t|head -10)" $ echo $lstfiles "file spaces" "file" "test.txt" "test" "test.sh" 

see how read command output or file content loop in bash read more details.


Comments

Popular posts from this blog

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -

c# - MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(3243,9): error MSB4094 -