Tag Info

New answers tagged

0

Below python script does the job, days from on which the files should be deleted can be configured with days variable. #!/usr/bin/env python3 import os import re import datetime days=60 delta = datetime.date.today() - datetime.timedelta(days=days) files = [ x for x in os.listdir() if re.search('_\d{8}\.', x)] for file in files: date = ...


2

OK, I have remade this script, and by sorting it backwards it looks like it should work. It compares the year and month to the previous one, and if it is lower it should be the last entry for that month. #!/bin/bash #the tac reverses the listing, so we go from newest to oldest, vital for our logic below FILES=`ls | tac` #create a cutoff date by taking ...


0

You can try this in while loop: #!/bin/bash A=vtm_data_12month_20140301.txt B=`ls vtm_data_12month_20140301.txt | awk -F "_" '{print $4}' | awk -F "." '{print $1}'` C=`date --date="60 days ago" +%Y%m%d` if [ "$B" < "$C" ] then rm -fr $A else echo "$A is not older" fi


0

The following code does not preserve the last file of each month. #! /bin/bash cmp_timestamp=$(date --date="60 days ago" +%Y%m%d) while read filename; do [[ $filename =~ _(20[0-9][0-9][01][0-9][0123][0-9])\. ]] timestamp=${BASH_REMATCH[1]} printf "%-40s : %s\n" "$filename" "${timestamp}" if [ "$timestamp" -lt ...


0

You should select which time you need %y modification %w creation %z change or any combination: stat * --printf="%n\t%y %z\n" | grep -vF $(date -d "last Saturday" +%F) | cut -f1 Also choice what infomation you need and compose --printf= line. Or you can use just find command find -maxdepth 1 -type f -daystart \ ! -mtime $[$(date +%d)-$(date -d ...


1

Simpler: find . -maxdepth 1 -printf '%Ta\t%p\n' | grep -v -i '^sat' ref: This answer.


1

A way to do this : $ LANG=C find . -maxdepth 1 -printf '%p %AA\n' | awk '$NF=="Saturday"{next}{$NF=""}1' I assume we don't print files for all Saturdays. This is or not what you expect.


1

With GNU or FreeBSD find: find . -newermt '2014-11-13 9:09' ! -newermt '2014-11-13 9:10' Note that it will report a file last modified at 9:10:00.000000000 and not one at 9:09:00.000000000 but should otherwise be OK for the other 60,000,000,000 nanoseconds in between. With GNU find, assuming file and directory names don't contain newline characters, you ...


3

Just store the value of date +%Y%m%d%H%M%S in a variable: x=$(date +%Y%m%d%H%M%S) and later on mv file1 file1_$x.txt mv file2 file2_$x.txt ... or in a loop for all *.txt files for file in *.txt; do echo mv "$file" "${file%.txt}"_$x.txt; done (remove echo if you are happy with what you see on the screen)


0

Another safe approach that should work on any GNU system and Busybox: tail -n5 "$(stat -c "%Y %n" ./* | sort -nk1,1 | cut -d ' ' -f 2- | tail -n1)" That will work on most things but if your file names can contain newlines, use this instead (GNU only, still breaks if your files end in newlines): tail -n5 "$(stat --printf "%Y %n\0" ./* | sort ...


7

With the zsh shell: tail -n 5 ./*.aff(D.om[1]) With other shells, it's quite difficult to come up with something reliable if you don't want to make assumptions on what file names may contain. For instance, the bash equivalent, if you're on a recent GNU system would be: find . -maxdepth 1 -name '*.aff' -type f -printf '%T@:%p\0' | sort -rzn | sed -zn ...


5

Assuming file names don't contain newline characters and that all the *.aff files are regular files: ls -t1d -- *.aff | head -n 1 gives you the name of the most recently modified .aff-file. If you want the last 5 lines just do: tail -n 5 -- "$(ls -t1d -- *.aff | head -n 1)"


2

I had a similar problem with tar archives. There the differences were caused by atime and/or ctime entries. My solution was to use tar -c --format=ustar ... so that the timestamps were no longer part of the archive. Furthermore IIRC standard tar (i.e. GNU tar) creates a string describing the archive itself, and this string contains a timestamp. I.e. even ...


5

You need to set the HISTTIMEFORMAT env variable. From help history: If the $HISTTIMEFORMAT variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associated with each displayed history entry. No time stamps are printed otherwise. The format is described in the strftime manpage. See examples here ...


1

When you give a commit ID or tag ID (or branch name, as you've done here) to git archive, the commit time as recorded in the referenced commit object is used as the modification time of each file in the archive. It looks like the latest commit on master was at 2014-10-29 13:09:52, which must have been in the future relative to the moment when you ran git ...



Top 50 recent answers are included