- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: create a file with date
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 02:24 PM
10-24-2005 02:24 PM
create a file with date
How can I create a file or directory using the date and/or time as the name of this file/directory?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 02:37 PM
10-24-2005 02:37 PM
Re: create a file with date
DATE=$(date +%Y%M%D)
TIME=$(date +%h%m)
FILENAME=THISFILE_${DATE}_${TIME}
touch ${FILENAME}
DIR=DIRNAME_${DATE}_${TIME}
mkdir ${DIR}
Check the date man page for all the options to format the date. I can't recall if the numerical date is a capital D or a lower case d.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 02:47 PM
10-24-2005 02:47 PM
Re: create a file with date
Here is an example that create a file by using date command:
#touch `date +"%y%m%d"`
You can modify it.
This is very usefull when you create a script and auto create a file or directory.
For more see on the manpage!
Hope this helps
Hoang Chi Cong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 05:51 PM
10-24-2005 05:51 PM
Re: create a file with date
# touch filename_$(date +"%X_%d-%m-%Y")
or
# touch filename_`date +"%X_%d-%m-%Y"`
You can store it in a variable and create it as,
# FILE="filename_$(date +'%X_%d-%m-%Y')
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2005 06:06 PM
10-24-2005 06:06 PM
Re: create a file with date
I correct it as:
DATE=$(date +%yy%mm%dd)
TIME=$(date +%h%M)
FILENAME=THISFILE_${DATE}_${TIME}
touch ${FILENAME}
DIR=DIRNAME_${DATE}_${TIME}
mkdir ${DIR}
or
DATE=$(date +%y%m%d)
TIME=$(date +%h%M)
FILENAME=THISFILE_${DATE}_${TIME}
touch ${FILENAME}
DIR=DIRNAME_${DATE}_${TIME}
mkdir ${DIR}
~