|
|
|||
FORMATTING THE SYSTEM DATE You can find the current date and time using the date command on Linux's command line. This returns the date in a predefined format such as: # date Thu Jan 3 15:36:21 MST 2002 However, if you want to use the date as a part of something, or if you want to display the date in a particular way, this isn't very useful. You can customize the output more to your liking by specifying that the date command format its output with special characters. For instance, the following is more meaningful and can be used to date directories or files in scripts: # date +%Y-%m-%d 2002-01-03 Additionally, you can use something like the following in a shell script: date=`date +%Y-%m-%d` mv $file $file-$date This moves the file referenced by the $file variable to a new file called $file-$date. If the file were called temp.txt, the new file would be called temp.txt-2002-01-03. You can also have the date command format its output using newline and horizontal tab characters: # date +"Current date:%t%A %B %d, %Y%nCurrent time:%t%r" Current date: Thursday January 03, 2002 Current time: 03:44:26 PM As illustrated, the %t string translates to a tab and %n translates to a newline character. The output of date here is much nicer. To get all of the options and commands you can use with the date command, type "date --help". |
||||