Shell script to use the last modified filename in a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to use the last modified filename in a variable
# 1  
Old 07-18-2010
Bug Shell script to use the last modified filename in a variable

Forgive me if this is a trivial question, but I haven't been able to find the answer to this.

Basically I've got a list of files in a particular directory that have the general form t_*.dat. (I have other files in the same directory as well).

Essentially what I want to do is obtain the name of the last modified file in this directory that start with t_* and use that name as a variable in my shell script.

I know that the following command will give me the file in a terminal
Code:
ls -altr t_* | tail -1

But how could I use the name of this file in a variable, say $filename.

(Later on, I want to use this filename to plot data using gnuplot.)
Thanks.
# 2  
Old 07-18-2010
Code:
filename=$(ls -t t_* | head -1)

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find file by filename or with newest modified date

Hi, I have a directory that has numerous files in it, and there is two which are named "filerec_ddmmyyHH24MMSS" by the time they are created so "filerec_010615012250" was created at 01:22:50 on 1st June 2015. I need to find the most recently created of those 2 files and get the contents of... (4 Replies)
Discussion started by: finn
4 Replies

2. Shell Programming and Scripting

shell script to alert if a file has been modified

Hi , I want a script who will send alert the moment someone edit any file in a directory in LINUX. Can some one throw some light on this please.!! (4 Replies)
Discussion started by: d8011
4 Replies

3. Shell Programming and Scripting

Send filename as variable in a shell script

I am having some trouble with a shell script I am writing. In the program I pass the path of where certain file names exist. I then want to loop through each file name and pass it as a DATA variable when calling sqlldr for a control file. This is what I have: ls $FILEPATH/${FILENAME}*.csv ... (4 Replies)
Discussion started by: neva
4 Replies

4. Shell Programming and Scripting

How to get a filename modified by attaching modified timestamp

Hi, I want to modify a filename in AIX by attaching the last modified timestamp. I want the timestamp completely in numerical format (eg:200905081210. yr-2009, mnth - 05, date -08, hr - 12, mins - 10). For example if the filename is a.log and it was modified on April 6th 2008 at 21.00. I... (16 Replies)
Discussion started by: Ruks
16 Replies

5. UNIX for Advanced & Expert Users

Send a mail when a shell script is modified

I would like to know, whether is there any command/tool in Linux (something like Oracle Trigger function) to send a mail if a particular shell script has been modified with details like, modification time, modified by, etc. Thanking in advance, (1 Reply)
Discussion started by: apsprabhu
1 Replies

6. Shell Programming and Scripting

how to write a shell script that print the last modified file ?

Hi guys, -could any one help me with this (I'm new to UNIX) how to write a shell script that tell me the last modified file in the current directory? so if I run the script in a diferent directory,will work. and can I write the script by C++ language and run it in the shell ? I tried... (5 Replies)
Discussion started by: FunnyWolF
5 Replies

7. Shell Programming and Scripting

Getting modified time & filename only

Hi, When we use "ls -l" we are getting like below, -rw-r--r-- 1 mdskl mds 4161479 Apr 12 14:57 VTTF2008.20080412145748.cc But i need only modified time and filename only like below, Apr 12 14:57 VTTF3008.20080412145748.cc Thanks-:) Senthil (4 Replies)
Discussion started by: senthil_seera
4 Replies

8. UNIX for Advanced & Expert Users

Find and store files based on FileName and Modified Time

Hi, I am currently using the following command: files=(ls enuCPU??.????.exp ntuCPU??.????.exp) I need to now change the commmand to store the file names of files that have been modified before datetime equal to say '02/16/2008 20:30:00' What could I use? (2 Replies)
Discussion started by: edisonantus
2 Replies

9. Shell Programming and Scripting

Shell script to find out 2 last modified files in a folder..PLZ HELP!!!!!!!!!

hi all, I need to find out the last 2 modified files in a folder.There is some way by which,we can check the timestamp and find out..??please help this is urgent. Thanks in Advance Anju (3 Replies)
Discussion started by: anju
3 Replies

10. Shell Programming and Scripting

How to send filename as variable in a shell script

Can we can pass the filename as variable in the shell script. Sending the filename as a parameter file, the shell script takes the filename, needs to replace the string containing the filename with the variable in the shell script. EX: test1.sh is the shell script and takes file1.csv as... (6 Replies)
Discussion started by: gthokala9
6 Replies
Login or Register to Ask a Question