Tag Info

New answers tagged

3

System time You can use date to set the system date. The GNU implementation of date (as found on most non-embedded Linux-based systems) accepts many different formats to set the time, here a few examples: set only the year: date -s 'next year' date -s 'last year' set only the month: date -s 'last month' date -s 'next month' set only the day: date -s ...


0

You change the date with the date command. However, the command expects a full date as the argument: # date -s "20141022 09:45" Wed Oct 22 09:45:00 BST 2014 To change part of the date, output the current date with the date part that you want to change as a string and all others as date formatting variables. Then pass that to the date -s command to set ...


0

Use date -s: date -s '2014-12-25 12:34:56' Run that as root or under sudo. Changing only one of the year/month/day is more of a challenge and will involve repeating bits of the current date. There are also GUI date tools built in to the major desktop environments, usually accessed through the clock. To change only part of the time, you can use command ...


2

If you want to change the timezone for your logged in session,then you can export the TZ variable to your required timezone. For example: export TZ=US/Eastern


0

date -r almost does the job. All you need to do is shift the origin, which is an addition. date -r $((number_of_seconds - epoch)) where epoch is the number of seconds between 1 January 1 and 1 January 1970. The value of epoch depends on your calendar. In the Gregorian calendar, there are 477 leap years between 1 and 1970, so 365 * 1969 + 477 = 719162 ...


0

The problem is that not everyone agrees on what the pre-1923 dates are. We (westerners) are now using the Gregorian calendar. Before 1582, people were using the Julian calendar. In between 1582 and 1923, some people used one or the other. For instance, England switched to the Gregorian calendar in 1752 and that's what the cal command uses as the switching ...


1

You can use this: echo $(( `date +%s` - ` date --date=yesterday +%s ` )) 86400 You can replace 'yesterday' by any date. For example: echo $(( `date +%s` - ` date --date='Tue Aug 9 11:44:34 CEST 2014' +%s ` )) 259209 Tested on GNU/Linux.


0

Bash script to inject a date into a filename: This bash code in file called a.sh #!/bin/bash today=`date '+%Y_%m_%d__%H_%M_%S'`; filename="/home/el/myfile/$today.ponies" echo $filename; When run, prints: eric@dev ~ $ chmod +x a.sh eric@dev ~ $ ./a.sh /home/el/myfile/2014_08_11__15_55_25.ponies Explanation of the code: Interpret the script with the ...


0

I would write: increment_date() { local current=$(grep -oP 'PROCESS DATE =\K.+' file) local next=$(date -d "$current + 1 day" +%F) sed -i "/PROCESS DATE =/s/$current/$next/" file } cat file increment_date cat file increment_date cat file PROCESS DATE =2012-02-28 PROCESS DATE =2012-02-29 PROCESS DATE =2012-03-01 This assumes the PROCESS ...


1

You could use perl: perl -MTime::Piece -pi -e 's/\d{4}-\d\d-\d\d/ (Time::Piece->strptime($&,"%Y-%m-%d")+24*60*60)->date/ge' file would increment every date in the file.


1

It depends on how sophisticated you need this. If all you need is to change the 01 to a 02, you can use something like sed -i 's/01/02/' file or perl -i -pe 's/01/02/' file Or, to be on the safe side, do it only if the 01 is at the end of the line: sed -i 's/01$/02/' file perl -i -pe 's/01$/02/' file Both of the above solutions will modify the ...


2

While you can do this with a loop and stat if you really want, this is something that find is good at and can do in a single line. You can create a special timestamp file each time your script runs and then select all files newer/older than that file with: find -name "*.$filetype" ! -newer timestamp.file That will find all files in the directory tree that ...


1

While it may not be applicable to all operations that can be expressed easily in natural language, FreeBSD's date has the -v operator that allows to set both arbitrary and relative values to separate date fields, and this can be repeated as necessary to produce most effects. For example, to get "last sunday" one can apply "zero out all time fields" followed ...


2

Probably the best way to ensure compatibility is to install GNU date on the FreeBSD system. You can install the coreutils package from the FreeBSD ports collection. This will put the GNU date command into /usr/local/bin/gdate.


5

There are a number of commands on FreeBSD that use the same API as GNU date to input natural language dates from the user. I've just found one that can be tricked into converting that date into Unix epoch time: /usr/sbin/fifolog_reader -B 'last sunday' /dev/null 2>&1 | sed 's/^From[[:blank:]]*\([0-9]*\).*/\1/p' (note that at least on FreeBSD ...


2

There is in general not enough information in that date string to know which timezone it was generated in. The +0200 only tells you that the timezone in question is currently ahead of UTC by two hours. It doesn't tell you whether the offset changes throughout the year or from year to year like knowing the actual time zone would tell you. As for the CEST ...



Top 50 recent answers are included