ssh как суперпользователь

Если Вы используете GNU date, можно использовать в своих интересах, это - способности к управлению датой:

#!/usr/bin/env bash

## Define the age limit
lim=$(date -d "2 months ago" +%s); 

## Find all files in the current directory and
## sub directories
find . -type f | 

## Extract the longest string of numbers (we assume that is the date)
## and change mmdd to ddmm
perl -lne '
    ## skip file names that don't have enough numbers 
    /(\d{1,8})/ || next; $d=$1;
    next unless $d;
    ## Change YYYYmmddHHMMSS to mm/dd/YYY 
    if($d=~/201\d$/){$d=~s|(\d{2})(\d{2})(\d{4})|$2/$1/$3|}

    ## Change  ddmmYYYYHHMMSS or ddmmYYYY to mm/dd/YYY 
    else{$d=~s|(\d{4})(\d{2})(\d{2})|$2/$3/$1|}; 

    ## Print the original file name and the modified date string
    print "$_ $d" if 
' | 

## Read the file name into $f and the date into $d
while read f d; do 
## If this date is older than $lim, delete the file
 if [ "$(date -d "$d" +%s)" -lt "$lim" ]; then 
   rm "$f"; 
 fi
done

Это может быть сжато в "остроту", что Вы можете скопировать/вставить непосредственно в терминал:

lim=$(date -d "2 months ago" +%s); 
find . -type f | perl -lne '
 /(\d{1,8})/ || next; $d=$1; 
 if($d=~/201\d$/){$d=~s|(\d{2})(\d{2})(\d{4})|$2/$1/$3|}
 else{$d=~s|(\d{4})(\d{2})(\d{2})|$2/$3/$1|}; print "$_ $d"' | 
while read f d; do [ "$(date -d "$d" +%s)" -lt "$lim" ] && echo rm "$f";   done

ПРОТЕСТЫ: Это решение предполагает, что Ваши имена файлов не содержат пробелов и что самая длинная строка цифр в имени файла всегда будет датой.

2
22.09.2014, 21:42
1 ответ

Если оно не было явно отключено, вы можете SSH , используя ваш корневой пользователь:

ssh root@hostname.com
3
27.01.2020, 22:05

Теги

Похожие вопросы