This is a discussion on How can I rename a file by its date? within the Linux software forums, part of the Linux Getting Started category; I have here a simple question. I have a file named "log.txt"and the date modified is Mar 29, 2006 16:55 ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
I have here a simple question.
I have a file named "log.txt"and the date modified is Mar 29, 2006 16:55 I am planning to rename/create link of "log.txt" to "Mar 29, 2006 1655.txt" The problem is how can I get that string. Sol. 1 -bash-3.00# stat --format=%y log.txt 2006-03-29 16:55:41.571766000 +0800 But the problem is how can I convert that to string "Mar 29, 2006 1655" Sol 2. -bash-3.00# ls -l --time-style="+%b %e, %Y %k%M" log.txt -rw-rw-rw- 1 root root 0 Mar 29, 2006 1655 log.txt I have that string but the problem is how can I filter that string. Thanks in advance for any help warren |
| Sponsored Links | ||
|
|
|
||||
|
Both stat and ls -l are not suitable for this job. Use date command formatting.
Code:
echo $(date +"%b-%d-%y").log.txt Code:
NOW=$(date +"%b-%d-%y") cp log.txt "$NOW.log.txt" ls *.txt |
|
|||
|
thanks for this great idea.
but sad to say that it might not really fit into what i'm planning the "date" command will get the current time and append it to the filename prior to creating and in my case the files are already created. There is a third party software that will create log1.txt, log2.txt, and so on and so forth and in no way I can change that and if I change that, the application will break. I'm planning to create a link between that log files to another file where its filename equal to its modified date. In this case it much easier to tell which log I want to look. Anyway you have given me a good idea. I'll look into the application if I can put this as an arguement. By the time the application creates the log file at the same time another log file is created but with the date as its prefix. thanks..... |
|
|||
|
You got it! thank you so much.
I should have study awk. After some basic courses of awk, i've arrived to something like this: ln -s log0.txt "`ls -ld --time-style="+%b %e, %Y %k%M%S" log0.txt | awk '{ print $6" "$7" "$8" "$9}'`" the output would be: Mar 30, 2006 122104 thanks.... |
|
||||
|
LOL @ nixcraft, you always miss the bus first time...
Awk and sed both are real nifty tools. In addition, one can only master them by observing code like this PS: nixCraft. Btw your Cyborg rocks
__________________
Rocky Jr. You may have my body & soul, but you will never touch my pride! If you have knowledge, let others light their candles at it. Certified to work on HP-UX / Sun Solaris / RedHat |
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Shell date command for manipulation and formatting date | newbie4 | Shell scripting | 4 | 10-28-2008 08:33 PM |
| How to rename a file in Linux | raj | Linux software | 0 | 04-22-2008 03:00 AM |
| How to calculate date minus 72 hours? | svinopas | Shell scripting | 1 | 10-09-2007 10:37 PM |
| how to rename eth0 to eth1 | deltamails | Networking, Firewalls and Security | 1 | 09-24-2007 08:53 PM |
| script to ping + date | dendi_rm | Shell scripting | 3 | 09-11-2007 11:42 AM |