reading directory for most recent file?

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers reading directory for most recent file?
# 1  
Old 08-22-2002
reading directory for most recent file?

Dear All,

I'm trying to write a script that searches thru a directory looking for a most recent file and then scp that file.

I have the scp working, but I don't know how to browse the directory and select the most recent file.

The file name includes a date & time stamp (e.g. 20020822112501)

Any ideas?? I'm really stuck with this one, complete novice!
# 2  
Old 08-22-2002
Some questions

Are you looking for the file which has the most resent filename?
-- If so you can use the sort command, like `ls -1 | sort`

Are you looking for the file which is most resent touched (writing in the file)?
-- If so you can use the ls command, like `ls -rt1 | tail -1`

take care

# 3  
Old 08-22-2002
Thanks, how do I assign the lastest file to a variable that I can use in a script??
# 4  
Old 08-22-2002

depends on the shell you use


setenv RESENTFILE `ls -rt1 | tail -1`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Reading a file from a different directory in a Bash script

Hi all, Given here under a section of a script I am using. SIMDIR="/home/Ins/forces" cd $SIMDIR for file in `ls *.forces` do basename=`echo $file | sed 's/\.*$//'` extname=`echo $file | sed 's/*\(*\)\.\(.*\)/\2\1/'` echo "Processing file: "$basename python (4 Replies)
Discussion started by: Theo Score
4 Replies

2. Shell Programming and Scripting

Help with reading directory paths with spaces from a file

Hi I want to know how to handle the spaces in the below scenario. I have a file (CON_zip_path_1.txt) which has some directory paths with spaces in directory names . My requirement is to unzip these zip files to another path. Please see the code below and the error. CON_zip_path_1.txt... (4 Replies)
Discussion started by: paul1234
4 Replies

3. Shell Programming and Scripting

How to recursively copy directory only for recent files?

I love the -newerct flag for the Cygwin find command on windows. Can I use "/usr/bin/find . -newerct '3 hours ago'" to conditionally copy a directory tree so that only the files in the directory tree that are younger than 3 hours are copied to my destination directory such that the directory... (4 Replies)
Discussion started by: siegfried
4 Replies

4. UNIX for Dummies Questions & Answers

' for reading (No such file or directory)

1.1 Solaris 10 8/07 s10s_u4wos_12b SPARC 1.2 Patch: 127714-03 Obsoletes: Requires: 120011-14 Incompatibles: Packages: SUNWsshcu, SUNWsshdu, SUNWsshu Patch: 128253-01 Obsoletes: Requires: Incompatibles: Packages: SUNWsshcu Patch: 126630-01 Obsoletes: Requires: Incompatibles: Packages: SUNWtcsh 1.3... (3 Replies)
Discussion started by: alvinoo
3 Replies

5. Shell Programming and Scripting

How to rename (move) most recent files in directory?

I'm using cygwin32 on Windows. DN is an environment variable pointed at my download directory. This command works to move the single most recent file in my download directory to my current directory: mv "`perl -e '$p = $ARGV; opendir $h, $p or die "cannot opendir $p: $!"; @f = sort { -M $a... (2 Replies)
Discussion started by: siegfried
2 Replies

6. Shell Programming and Scripting

' for reading (No such file or directory) `Solaris_websummary.txt

echo "1.1 Apply latest OS patches;" awk '/1.2 Install/ {P=0} P {print $0} FNR==1{printf("From file %s:\n", FILENAME)} /1.1 Apply/ {P=1}' solarisappsummary.txt solarisdbsummary.txt solaris_websummary.txt echo "1.2 Install TCP Wrappers;" awk '/1.3 Install/ {P=0} P {print $0}... (1 Reply)
Discussion started by: alvinoo
1 Replies

7. UNIX for Dummies Questions & Answers

Find most recent file and copy to another directory.

Very new to shell scripting. Not sure if my title is correct but I will try and explain. Directory has 100+ files with this format, " ". When a new file gets created, the 16-19 characters in the file name gets incremented by 1. Ex...todays most recent file is... (14 Replies)
Discussion started by: askvip
14 Replies

8. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

9. Shell Programming and Scripting

fatal: cannot open file `TNAME' for reading (No such file or directory)

Hi, I am running this command through a shell script and getting the error mentioned in the subject line: testing.awk -f x.txt TNAME My testing.awk file contains something like ++++++++++++++++++ #!/usr/bin/awk -f BEGIN{ TAB_NAME="INSERT_ONE_" ARGV ; } if ( $1=="JAM_ONE" &&... (1 Reply)
Discussion started by: kunwar
1 Replies

10. Shell Programming and Scripting

Getting the most recent file

Hi people, Please some help over here. I have logs in a directory, in which I need to get the most recent file in order to put it within other command. The format of the files are loadfiles20090308094339_41 loadfiles20090308094418_42 loadfiles20090308095457_43... (4 Replies)
Discussion started by: cgkmal
4 Replies
Login or Register to Ask a Question