Automatically Rename Last Generated File


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automatically Rename Last Generated File
# 1  
Old 05-25-2005
Automatically Rename Last Generated File

I'm trying to rename the last generated file in a given directory using a makefile.

If I type 'make build' the 'build' target produces a file (ie: text_001.txt). It automatically generates them sequentially, so I don't have control over the name. I can't say that it will always be text_001.txt. Otherwise it would be easy:
mv text_001.txt build.txt

I would like to take the last generated .txt file and rename it ... something like: build.txt. Since I'm setting this up for other users however, I want to script this behavior. I know how to get the latest file by doing an ls -t *.txt, but I don't know how to (a) automatically find the latest file and (b) then rename that file.

I could do this using a perl script, but I would think it can be done much faster. Something like:

find . -name *.txt exec mv {} ...

Can anyone help?
# 2  
Old 05-25-2005
Code:
mv `ls -1 -t *.txt | head -1` build.txt

# 3  
Old 05-25-2005
thank you jim!

why didn't i think of this?

that was much easier than i anticipated ...
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to analyze sosreport file that I generated.?

Hello Team, Could You give me some hints how I should review the sosreport that I generated? I know how to analysis the SAR files however sosreport is my last hope - python script has hunged and I would like to know the root cause - for this is not performance issue. Thanks in advance! ... (3 Replies)
Discussion started by: nsmcny
3 Replies

2. UNIX for Advanced & Expert Users

Script to rename file that was generated today and which starts with date

hello, can someone please suggest a script to rename a file that was generated today and filename that being generated daily starts with date, its a xml file. here is example. # find . -type f -mtime -1 ./20130529_4995733057260357019.xml # this finename should be renamed to this format.... (6 Replies)
Discussion started by: bobby320
6 Replies

3. Shell Programming and Scripting

Log file being not generated in crontab

My shell script it.sh #!/bin/sh ORACLE_HOME=/var/opt/oracle/product/10g; export ORACLE_HOME PATH=$PATH:$ORACLE_HOME/bin:/bin:/usr/bin; export PATH today=`date "+%m-%d-%Y %H:%M:%S"`; export today CUR_DIR=$1; export CUR_DIR LOG_FILE=error.log; export LOG_FILE # Direct script output to... (4 Replies)
Discussion started by: rafa_fed2
4 Replies

4. Shell Programming and Scripting

Copy latest generated file

Hi, There is csv file generated at /usr/data on server1 on monthly basis. It is in the format reportYYYYDD(e.g 201105). I needed a script which would copy the latest generated file from the location to another server at /usr/loc Please can you help? (2 Replies)
Discussion started by: Alok Ranjan
2 Replies

5. UNIX for Dummies Questions & Answers

Log file not getting generated

Hi , Log file is not getting generated. any suggestion? Thanks date1=$(date '+%m/%d/%y-%H:%M:%S') log="wrapper.log.$date1" echo " somethng" > $log (2 Replies)
Discussion started by: ajincoep
2 Replies

6. Shell Programming and Scripting

Need a command to delete all files apart from last file generated

Hi, I have a directory named (/output). this directory has files in the below format abc.* , xyz*, djj*, iwe*, weewe*, rier*, 3948903ddfgf* these files are generated at random. what i need to do is. delete all the files of all kinds but keep only the last generated file of... (5 Replies)
Discussion started by: dazdseg
5 Replies

7. Linux

Core file not getting generated!!

Some strange behavior. Process is receiving Segmentation Fault. But no core files getting generated. I have checked ulimit. coredumpsize = unlimited. In console, process is printing Segmentation Fault even through gdb also same behavior But No corefile. Any possible reason ? ... (3 Replies)
Discussion started by: ashokd001
3 Replies

8. Shell Programming and Scripting

get the last generated log file

Hi I need to get the last generated file in a directory using ls -ltr. I need to store the output of ls -ltr in a variable. it will like this $xyz = -rw-rw-r-- 1 sblp003 siebel 1060 Dec 18 13:33 from this output, I need to do a substring to get this value alone "Dec 18... (8 Replies)
Discussion started by: ragha81
8 Replies

9. Programming

Core File Not Being Generated in AIX

I have created an executable using my login session in an AIX Version 5 Unix system. After to which I have change the file mode to set uid and rwsrwx--x and ownership to root:system by using the following Standard C Library functions. chmod (name, S_ISUID|S_IRWXU|S_IRWXG|S_IXOTH|S_IROTH) chown... (6 Replies)
Discussion started by: S.P.Prasad
6 Replies
Login or Register to Ask a Question