Shell script sort files date




















Andreas Wiese Andreas Wiese 9, 1 1 gold badge 29 29 silver badges 37 37 bronze badges. Gilles 'SO- stop being evil' Gilles 'SO- stop being evil' k gold badges silver badges bronze badges. This is the only answer here that works for Solaris 10, thanks! Gilles 'SO- stop being evil' k gold badges silver badges bronze badges. UnX UnX 4 4 silver badges 8 8 bronze badges.

You could use find 's -printf option to avoid invoking a separate process or several, depending on the number of files. See my answer for an example. Knowing that there are other ways to do it, I wanted to give stat a chance and show -exec Sometimes I think, stat deserves more attention I met lots of linux users never having read about stat. So sometimes I just want to direct some attention on stat I think stat deserves it To robustly list the filenames only using recent GNU tools: find.

Graeme Graeme 32k 6 6 gold badges 79 79 silver badges bronze badges. Community Bot 1. Sign up or log in Sign up using Google.

Sign up using Facebook. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?

Collectives on Stack Overflow. Learn more. Sorting by Date in Shell Ask Question. Asked 5 years, 4 months ago. Active 5 years, 3 months ago. Viewed 1k times. Otorrinolaringologista -man. Otorrinolaringologista -man Otorrinolaringologista -man 1 1 gold badge 22 22 silver badges 44 44 bronze badges. Add a comment. Active Oldest Votes. Continuing from your question in the comment, you currently show sort -n -t":" -k3.

David C. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Most popular in Linux-Unix. More related articles in Linux-Unix. We use cookies to ensure you have the best browsing experience on our website. Start Your Coding Journey Now! Login Register. The use of the Sort-Object cmdlet is illustrated here:.

When a script uses command-line parameters, it is a best practice to implement some kind of Help system for the user of the script to know which parameters are available and what sample syntax might look like. It is important to do this, even if you do not intend to share the script with anyone else.

In Windows PowerShell 2. To make your script display Help in a systematic fashion, use the Get-HelpText function. Between the tags, everything is interpreted as text. The first advantage of using a here-string is that it allows you to dispense with typing quotation marks at the beginning and end of each line.

The second advantage is that it allows you to ignore quoting rules and issues with escaping the quotation marks inside a text string. This is seen here:. The Get-HelpText function is called, and the Help text is displayed. The script is then exited by using the exit statement. When the script is run with the —help switched parameter, the Help message is displayed on the Windows PowerShell console.

After checking for the help variable, the script calls the Sort-Files function. The values for the —path and —filter parameters are collected from the Windows PowerShell command line. The results from the Sort-Files function are passed back to the Format-Table cmdlet. The name and the creationtime properties are selected from the System.

NET Framework class, and the —autosize parameter is used to tighten up the data that is displayed on the Windows PowerShell command line.



0コメント

  • 1000 / 1000