Results 1 to 5 of 5

Thread: Get latest updated file from your Current Working Directory

  1. #1
    Join Date
    Nov 2009
    Posts
    580

    Get latest updated file from your Current Working Directory

    Hi, I am student of BSC.I.T. and wanted to know more about UNIX. So, I am making R&D in unix shell script. So, can anyone explain me how to get the name of the file which is latest updated in that directory? Please give me the command and if possible explain it.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Get latest updated file from your Current Working Directory

    Hi, I am also new to this UNIX programming and not interested in this. But, if you have interest in this then just try to use of internet and download books regarding it. As it may provide you more knowledge and commands regarding it. Or make search for the commands regarding what you want. You can buy book of Orelly to get more advanced knowledge. Just make use of it. So, that you can be able to know more.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Get latest updated file from your Current Working Directory

    Hi, you want to get latest updated file from your current working directory, So if your CWD contains only files and directories. Then you can use following command:

    Code:
    cd <your existing folder>
    filename=$(ls -1t|while read obj
    do
    echo $obj
    break
    done)
    echo $filename

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Get latest updated file from your Current Working Directory

    Hi, I am not having that much information in Unix. But as you want to know the latest updated file from your current working directory you can use just following command which will solve your problem I think. Just try this.

    Code:
    latestfile=`ls -1tr | tail -n 1`
    This would give the latest updated file from the directory in which you are currently and it will store that filename in the variable.

  5. #5
    Join Date
    Jul 2010
    Posts
    1

    Re: Get latest updated file from your Current Working Directory

    hey, buddy the following line gives u latest updated file (it can be directory also)

    LATEST_FILE=`ls -1tr | tail -n 1`

    OR

    LATEST_FILE=`ls -ltr | tail -1 | tr -s '[:space:]' '[\:*]' | cut -d ":" -f 10`

    here the LATEST_FILE is a variable which contains latest updated file
    Last edited by sumy; 10-07-2010 at 02:46 PM.

Similar Threads

  1. Replies: 5
    Last Post: 11-10-2011, 11:20 AM
  2. Retrieving the current directory in batch
    By Jacques25 in forum Software Development
    Replies: 3
    Last Post: 15-07-2009, 11:36 PM
  3. GTA IV latest updated addon
    By Mario2 in forum Video Games
    Replies: 3
    Last Post: 31-03-2009, 10:40 AM
  4. How to make use of VB Script to get Current Directory?
    By BenTen in forum Software Development
    Replies: 2
    Last Post: 12-01-2009, 08:34 PM
  5. How to get current directory
    By Scott2580 in forum Software Development
    Replies: 3
    Last Post: 11-10-2008, 03:40 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,660,313,754.62851 seconds with 17 queries