Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8180967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:22:07+00:00 2026-06-07T00:22:07+00:00

I am writing a shell script in which I have to find the last

  • 0

I am writing a shell script in which I have to find the last modification date of a file.

Stat command is not available in my environment.

So i am using 'ls' as below to get desired result.

ls -l filename | awk '{print $6 $7 $8}'

But I have read in many forums that parsing ls is generally considered bad practise. While it (probably) works fine most of time, it’s not guaranteed to work everytime.

Is there any other way to get file modification date in shell script.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:22:07+00:00Added an answer on June 7, 2026 at 12:22 am

    How about using the find command?

    e.g.,

     $ find filenname -maxdepth 0 -printf "%TY-%Tm-%Td %TH:%TM\n"
    

    This particular format string gives output like this: 2012-06-13 00:05.

    The find man page shows the formatting directives you can use with printf to tailor the output to what you need/want. Section -printf format contains all the details.

    Compare ls output to find:

    $ ls -l uname.txt | awk '{print  $6 , "", $7}'
    2012-06-13  00:05
    
    $ find uname.txt -maxdepth 0 -printf "%TY-%Tm-%Td %TH:%TM\n"
    2012-06-13 00:05
    

    Of course you can write scripts in any number of languages such a Python or Perl etc, to get the same information, however asking for a “unix command” sounded as if you were looking for a “built-in” shell command.

    EDIT:

    You could also inovke Python from the command line like this:

    $ python -c "import os,time; print time.ctime(os.path.getmtime('uname.txt'))"
    

    or if combined with other shell commands:

    $ echo 'uname.txt' | xargs python -c "import os,time,sys; print time.ctime(os.path.getmtime(sys.argv[1]))"
    

    both return: Wed Jun 13 00:05:29 2012

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen some shell scripts in which they pass a file by writing the
I'm writing a shell script and I need to strip FIND ME out of
I am writing a POSIX shell script that may or may not receive input
I've been writing some shell script and I would find it useful if there
I am writing a simple shell script which changes the mac address of the
I have an old shell script which needs to be moved to bash. This
I'm writing a shell script which will rsync files from remote machines, some linux,
I am writing a shell script in which i need to call a binary
I have a shell script which I'd like to trigger from a J2EE web
I have a shell script which asks the user for too many questions. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.