The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 01-02-2009
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink

answering #1

Code:
ls -ltr | tail -1

will give you all info on the most recent file in the current folder

Code:
ls -ltr | tail -1 | awk '{print $9}'

will give you just the filename

Code:
MYFILE=`ls -ltr | tail -1 | awk '{print $9}'`

will put that filename into $MYFILE

for #2
normally not best to cd then rm, better to

Code:
rm \dir\folder\*

or similar.
Seen too many examples where the cd failed, and then all files were deleted or some other command executed.