How I can find the last file created and move it to a directory?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How I can find the last file created and move it to a directory?
# 8  
Old 06-19-2015
Quote:
Originally Posted by Bernardo Jarami
This work
Code:
 s -r icgorldi_*.xml | head -n 1

Assuming that you meant ls -r icgorldi_*.xm instead of s -r icgorldi_*.xm, that will give the the name of the file with the highest tag number (i.e., something like icgorldi_2421599.xml).
Quote:
what I am trying to do is to save that file in a variable
something like this
Code:
fn=$(ls -ltr  icgorldi*.xml | tail -1)

And that will set fn to something like:
Code:
-rw-r--r--      1 banjobs  jobsub       125 Jun 17 10:35 icgorldi_2421597.log

either for the same or a different file (this time choosing the file with the most recent modification timestamp instead of the file with the highest tag number).
Quote:
then I need to
rename the file (try this does not work)
Code:
rn $f icgorldi_06191015.xml

And why would invoking a news reading utility (rn) with ten operands be expected to rename a file. Is there some significance to the new name you want to assign to this file? It almost looks like it is named for the day that would be 1000 years ago tomorrow???

Whatever the problem, saying "this does not work" instead of showing us what it does do, what you wanted it to do, and showing us any diagnostic messages it produced when you ran it means that we have absolutely no information about what went wrong other than our wild imaginations.

Help us help you; show is what is going on!
Quote:
and not sure this will work since I haven't been able to rename
Code:
scp icgorldi_06191015.xml jostle:icgorldi_201601.xml

If you would set fn using one of them methods I suggested before:
Code:
fn=$(ls -r icgorldi_*.xml | head -n 1)

if you want the file with highest tag number, or:
Code:
fn=$(ls -t icgorldi_*.xml | head -n 1

if you want the file with the most recent modification timestamp, and then used:
Code:
mv "$fn" icgorldi_06191015.xml

it MIGHT do what you want.

How you would write a program to make up the two seemingly random new local and remote filenames is also hard for us to guess. Are you passing in these names as parameters? Are they somehow created using some transformation of today's or tomorrow's date?

Again, if you would give us a CLEAR, explicit description of your environment and what you are trying to do, we would be happy to help you. If you keep us in the dark, you're either going to get silence or wild guesses that are not likely to lead you in the right direction.
# 9  
Old 06-24-2015
Sorry for the delay but yes, I got my answers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find if create time of last created file in a directory is older than 5 minutes

A process xyz is running and creating file1, file2, file3, .... filen. how do i know if the process has stopped and createtime of the last file (filen) is older than 5 minutes? OS is AIX (3 Replies)
Discussion started by: malaika
3 Replies

2. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

3. UNIX for Dummies Questions & Answers

Find a list of files in directory, move to new, allow duplicates

Greetings. I know enough Unix to be dangerous (!) and know that there is a clever way to do the following and it will save me about a day of agony (this time) and I will use it forever after! (many days of agony saved in the future)! Basically I need to find any image files (JPGs, PSDs etc)... (5 Replies)
Discussion started by: Clyde Lovett
5 Replies

4. Shell Programming and Scripting

Please help list/find files greater 1G move to different directory

I have have 6 empty directory below. I would like write bash scipt if any files less "1000000000" bytes then move to "/export/home/mytmp/final" folder first and any files greater than "1000000000" bytes then move to final1, final2, final3, final4, final4, final5 and that depend see how many files,... (6 Replies)
Discussion started by: dotran
6 Replies

5. Shell Programming and Scripting

How to find files created today in a particular directory?

Dear All, I want a Hp Ux command to find out the files created today in a particular directory or mountpoint. Kindly help. Thanks Bhaskar (10 Replies)
Discussion started by: sudiptabhaskar
10 Replies

6. Shell Programming and Scripting

Commando to find and move mp3 file and directory

Hello, I have a lot of mp3 in a various directory. My goal is a command that find all mp3 file and move the files and directory where is the mp3 file to a destination folder. Is it possible? Thanks in advance (7 Replies)
Discussion started by: giangi007
7 Replies

7. AIX

How to find the date on which a particular directory is created?

how to find the date on which a particular directory is created? Thanks. (4 Replies)
Discussion started by: samsungsamsung
4 Replies

8. Shell Programming and Scripting

How to find the newly created directory

Hi, I need to create new directory by increasing the number by 1 of extracted lastly created directory. e.g. Log\out_log_1\ Log\out_log_2\ Log\out_log_3\ become Log\out_log_1\ Log\out_log_2\ Log\out_log_3\ Log\out_log_4\ Can anyone help how to do it in c-shell... (3 Replies)
Discussion started by: Andre_2008
3 Replies

9. Shell Programming and Scripting

Find the directory modified/created before 4 days

Hi, I have an application which creates some directories while running. I want to delete these directories which are 4 days older. i tried find . type d -mtime +1 -print And it is working fine.. but find . type d -mtime +4 -print is not giving any results which are 4 days... (6 Replies)
Discussion started by: Tuxidow
6 Replies

10. UNIX for Dummies Questions & Answers

Find all files created by a specified user in a directory and its subdirectories

Is there a command or shell script which can be used for Finding all files created by a specified userid in a directory and its subdirectories. Say, I want to find all such files in directory /abc as well as in all the subdirectories such as /abc/xyz or /abc/xyz/pqr aqnd so on which was created... (5 Replies)
Discussion started by: abhilashnair
5 Replies
Login or Register to Ask a Question