Operating System - HP-UX
1752633 Members
5703 Online
108788 Solutions
New Discussion юеВ

Can "date" be changed system wide?

 
SOLVED
Go to solution
dev44
Regular Advisor

Can "date" be changed system wide?

I have a user who is hoping to setup up his profile so that the date shows up in another format that what is HP-UX(11.23) standard. So he wants to type "date" and it will show up say 2008/04/23 or something to that effect anyway. Same as when he does an "ls" he will see the date of files with that format of date as well. I do not believe it can be done, but figured I would check here before answering him.

Thanks!
whatever
7 REPLIES 7
James R. Ferguson
Acclaimed Contributor
Solution

Re: Can "date" be changed system wide?

Hi:

Suggest to your user that (s)he create an alias for 'date' in the '.profile'. Something like:

# alias date='date "+%Y/%m/%d"'

As for changing the format of the date in 'ls' there are several ways to do this, including the method below (from the ITRC a long time ago):

#!/usr/bin/sh
# cat llsec
# This script checks if a /var/tmp/ls.cat message catalog exists,
# and if not, creates one where the display formats of ls(1) are
# changed to always display time in "%b %2d %H:%M:%S %Y" format,
# like
# "May 23 13:43:56 2002"
#
# It then proceeds to run ll(1) using this modified message catalog.
# Note that if root should run this, a secure locations should be
# used instead of /var/tmp.
# Usage: <script-name>

# e.g.: ./llsec /etc/passwd

if [ ! -s /var/tmp/ls.cat ]; then
echo Creating /var/tmp/ls.cat >&2
dumpmsg /usr/lib/nls/msg/C/ls.cat |
sed -e "s/%b %2d.*$/%b %2d %H:%M:%S %Y/" |
gencat /var/tmp/ls.cat -
fi
export NLSPATH="/var/tmp/%N.cat"
exec ll "$@"

Regards!

...JRF...
Pete Randall
Outstanding Contributor

Re: Can "date" be changed system wide?

Set up an alias for him that formats the date the way he wants.

alias date="date +'%-4.4h %2.1d %H:%M'"

or whatever format he wants.


Pete

Pete
dev44
Regular Advisor

Re: Can "date" be changed system wide?

That would work for when he types date....thanks. But he is also looking for any unix command that outputs anything with dates in it (ie: ls) to be in the same format.
whatever
Pete Randall
Outstanding Contributor

Re: Can "date" be changed system wide?

Well James gave you a script that would change the format shown by ls. You could set up another alias for him so ls would invoke that script. Any other commands that output a date could be handled in a similar fashion.


Pete

Pete
Matti_Kurkela
Honored Contributor

Re: Can "date" be changed system wide?

Sounds like your user is looking for locale settings, specifically LC_TIME.

See "man locale" for more information.
Use "locale -a" to get a listing of available locale settings.
You can test with a command like "LC_TIME=fi_FI.utf8 date" or "LC_TIME=fi_FI.utf8 ll" to see the effects.
This environment variable will change the default time representation in all programs that use the strftime() function, i.e. almost everywhere.

When (or if) you'll find a suitable setting, you can make it permanent by setting & exporting the variable in the user's .profile.

MK
MK
Matti_Kurkela
Honored Contributor

Re: Can "date" be changed system wide?

After thinking a bit further, I experimented with a small script:

#!/bin/sh
locale -a | while read foo
do
echo -ne "$foo: \t"
LC_TIME=$foo date
done

(Warning: this will produce some strange characters that might confuse some terminals/terminal emulators.)

Apparently the HP-UX standard locales won't offer what the user is asking. If the user insists, you might be able to create your own locale definition file. See "man 1m localedef" and "man 4 localedef" if you wish to try this.

MK
MK
dev44
Regular Advisor

Re: Can "date" be changed system wide?

Thanks
whatever