Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Need help with UNIX command to get the latest file from list of files with timestamp Post 303032119 by rakeshp on Tuesday 12th of March 2019 02:37:46 AM
Old 03-12-2019
Need help with UNIX command to get the latest file from list of files with timestamp

Hi All,

I have list of files like below with name abcxyz.timestamp. I need a unix command to pick the latest file from the list of below files. Here in this case the lates file is abcxyz.20190304103200. I have used this unix command "ls abcxyz*|tail -1" but i heard that it is not the appropriate one which may not be successful all the time.I was told to use a command by sorting the files based on the timestamp. Please do the needful.

Code:
abcxyz.20190304103200
abcxyz.20190303131348
abcxyz.20190303115704
abcxyz.20190227153924
abcxyz.20190215171513
abcxyz.20190228123958

Thanks
Rakesh

Last edited by RavinderSingh13; 03-12-2019 at 03:45 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh: How to get latest file from a list of files in a directory

Hi, I need to get the latest file from a list of files in a particular directory. Please could anyone help me out to get the file. Thank you, - Jay. (1 Reply)
Discussion started by: Jayathirtha
1 Replies

2. Shell Programming and Scripting

finding latest file having timestamp on it.....

Hi guys, I have a directory in UNIX having files with the below format, i need to pickup the latest file having recent timestamp embedded on it, then need to rename it to a standard file name. Below is the file format: filename_yyyymmdd.csv, i need to pick the latest and move it with the... (1 Reply)
Discussion started by: kaushik25
1 Replies

3. AIX

Unix shell scripting to find latest file having timestamp embedded...

Hi guys, I have a directory in UNIX having files with the below format, i need to pickup the latest file having recent timestamp embedded on it, then need to rename it to a standard file name. Below is the file format: filename_yyyymmdd.csv, i need to pick the latest and move it with the... (2 Replies)
Discussion started by: kaushik25
2 Replies

4. UNIX for Dummies Questions & Answers

UNIX command: mv - Objective: move files based on timestamp

I was wondering if there was a command to move files from one directory to another subdirectory based on the timestamp, i.e. moving from directory A files that have a timestamp of before the year 2005 into directory B. Directory B is a subdirectory located in directory A. I was advised to... (4 Replies)
Discussion started by: HLee1981
4 Replies

5. UNIX for Dummies Questions & Answers

How to pick only the latest files based on the timestamp?

I have a few log files which get generated on a daily basis..So, I need to pick only the ones which get generated for that particular day. -rw-r--r-- 1 staff 510732676 Apr 7 22:01 test.log040711 -rwxrwxrwx 1 staff 2147482545 Apr 7 21:30 test.log.2 -rwxrwxrwx 1 staff 2147482581 Apr 7 19:26... (43 Replies)
Discussion started by: win4luv
43 Replies

6. Shell Programming and Scripting

Urgent ...pls Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting. Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (1 Reply)
Discussion started by: robertbrown624
1 Replies

7. UNIX for Dummies Questions & Answers

Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (12 Replies)
Discussion started by: robertbrown624
12 Replies

8. Shell Programming and Scripting

Search for latest Timestamp in file

Hi, I have a file which generate Timestamp in this format :- 20121012162354 20121114191610 20121210232808 20121216220002 20130106220002 20130127220001 20130203220001 20121012162354 20121114191610 20121210232808 20121216220002 20130106220002 20130127220001 20130203220001 (2 Replies)
Discussion started by: netdbaind
2 Replies

9. Shell Programming and Scripting

I have this list of files . Now I will have to pick the latest file based on some condition

3679 Jul 21 23:59 belk_rpo_error_**po9324892**_07212014.log 0 Jul 22 23:59 belk_rpo_error_**po9324892**_07222014.log 3679 Jul 23 23:59 belk_rpo_error_**po9324892**_07232014.log 22 Jul 22 06:30 belk_rpo_error_**po9324267**_07012014.log 0 Jul 20 05:50... (5 Replies)
Discussion started by: LoneRanger
5 Replies

10. Shell Programming and Scripting

UNIX command to get the latest file and also matching pattern

we want to fetch the latest file in a given directory and also the file name should match the below pattern Example file name ->hrdata-2015-10-13-16-45-26.xml(2015-10-13-16-45-26- it is not current timestamp, we just need to check for the pattern) We expect the file will have the... (3 Replies)
Discussion started by: vishwanath001
3 Replies
Glib::BookmarkFile(3pm) 				User Contributed Perl Documentation				   Glib::BookmarkFile(3pm)

NAME
Glib::BookmarkFile - Parser for bookmark files SYNOPSIS
use Glib; $date .= $_ while (<DATA>); $b = Glib::BookmarkFile->new; $b->load_from_data($data); $uri = 'file:///some/path/to/a/file.txt'; if ($b->has_item($uri)) { $title = $b->get_title($uri); $desc = $b->get_description($uri); print "Bookmark for `$uri' ($title): "; print " $desc "; } 0; __DATA__ <?xml version="1.0" encoding="UTF-8"?> <xbel version="1.0" xmlns:bookmark="http://www.freedesktop.org/standards/desktop-bookmarks" xmlns:mime="http://www.freedesktop.org/standards/shared-mime-info"> <bookmark href="file:///tmp/test-file.txt" added="2006-03-22T18:54:00Z" modified="2006-03-22T18:54:00Z" visited="2006-03-22T18:54:00Z"> <title>Test File</title> <desc>Some test file</desc> <info> <metadata owner="http://freedesktop.org"> <mime:mime-type type="text/plain"/> <bookmark:applications> <bookmark:application name="Gedit" exec="gedit %u" timestamp="1143053640" count="1"/> </bookmark:applications> </metadata> </info> </bookmark> </xbel> DESCRIPTION
Glib::BookmarkFile lets you parse, edit or create files containing lists of bookmarks to resources pointed to by URIs, with some meta-data bound to them, following the Desktop Bookmark Specification. The recent files support inside GTK+ uses this type of files to store the list of recently used files. The syntax of bookmark files is described in detail in the Desktop Bookmarks Specification, here is a quick summary: bookmark files use a subclass of the XML Bookmark Exchange Language (XBEL) document format, defining meta-data such as the MIME type of the resource pointed by a bookmark, the list of applications that have registered the same URI and the visibility of the bookmark. METHODS
bookmarkfile = Glib::BookmarkFile->new $bookmark_file->add_application ($uri, $name, $exec) o $uri (string) o $name (string or undef) o $exec (string or undef) Adds the application with $name and $exec to the list of applications that have registered a bookmark for $uri into $bookmark_file. Every bookmark inside a "Glib::BookmarkFile" must have at least an application registered. Each application must provide a name, a command line useful for launching the bookmark, the number of times the bookmark has been registered by the application and the last time the application registered this bookmark. If $name is undef, the name of the application will be the same returned by Glib::get_application_name(); if $exec is undef, the command line will be a composition of the program name as returned by Glib::get_prgname() and the "%u" modifier, which will be expanded to the bookmark's URI. This function will automatically take care of updating the registrations count and timestamping in case an application with the same $name had already registered a bookmark for $uri inside the bookmark file. If no bookmark for $uri is found one is created. $bookmark_file->add_group ($uri, $group) o $uri (string) o $group (string) Adds $group to the list of groups to which the bookmark for $uri belongs to. If no bookmark for $uri is found one is created. unix timestamp = $bookmark_file->get_added ($uri) o $uri (string) $bookmark_file->set_added ($uri, $value) o $uri (string) o $value (unix timestamp) Sets the time the bookmark for $uri was added. If no bookmark for $uri is found one is created. ($exec, $count, $stamp) = $bookmark_file->get_app_info ($uri, $name) o $uri (string) o $name (string) Gets the registration information of $name for the bookmark for $uri. See Glib::BookmarkFile::set_app_info() for more information about the returned data. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_app_info ($uri, $name, $exec, $count, $stamp) o $uri (string) o $name (string) o $exec (string) o $count (integer) o $stamp (unix timestamp) Sets the meta-data of application $name inside the list of applications that have registered a bookmark for $uri inside $bookmark_file. You should rarely use this method; use Glib::BookmarkFile::add_application() and Glib::BookmarkFile::remove_application() instead. $name can be any UTF-8 encoded string used to identify an application. $exec can have one of these two modifiers: "%f", which will be expanded as the local file name retrieved from the bookmark's URI; "%u", which will be expanded as the bookmark's URI. The expansion is done automatically when retrieving the stored command line using the Glib::BookmarkFile::get_app_info() method. $count is the number of times the application has registered the bookmark; if it is < 0, the current registration count will be increased by one, if it is 0, the application with $name will be removed from the list of registered applications. $stamp is the Unix time of the last registration, as returned by time(); if it is -1, the current time will be used. If you try to remove an application by setting its registration count to zero, and no bookmark for $uri is found, %FALSE is returned and an exception is fired. May croak with a Glib::Error in $@ on failure. list = $bookmark_file->get_applications ($uri) o $uri (string) Retrieves the names of the applications that have registered the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->get_description ($uri) o $uri (string) Gets the description of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_description ($uri, $description) o $uri (string) o $description (string) Sets the description of the bookmark for $uri. If no bookmark for $uri is found one is created. list = $bookmark_file->get_groups ($uri) o $uri (string) Retrieves the list of group names of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_groups ($uri, ...) o $uri (string) o ... (list) one or more group names Sets a list of group names for the item with URI $uri. Each previously set group name list is removed. If no bookmark for $uri is found one is created. boolean = $bookmark_file->has_application ($uri, $name) o $uri (string) o $name (string) Checks whether the bookmark for $uri inside $bookmark_file has been registered by application $name. May croak with a Glib::Error in $@ on failure. boolean = $bookmark_file->has_group ($uri, $group) o $uri (string) o $group (string) Checks whether $group appears in the list of groups to which the bookmark for $uri belongs to. May croak with a Glib::Error in $@ on failure. boolean = $bookmark_file->has_item ($uri) o $uri (string) Looks whether the bookmark file has a bookmark for $uri. ($href, $mime_type) = $bookmark_file->get_icon ($uri) o $uri (string) Gets the icon of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_icon ($uri, $href, $mime_type) o $uri (string) o $href (string or undef) o $mime_type (string or undef) Sets the icon for the bookmark for $uri. If $href is undef, unsets the currently set icon. boolean = $bookmark_file->get_is_private ($uri) o $uri (string) May croak with a Glib::Error in $@ on failure. $bookmark_file->set_is_private ($uri, $is_private) o $uri (string) o $is_private (boolean) $bookmark_file->load_from_data ($buf) o $buf (scalar) Parses a string containing a bookmark file structure. May croak with a Glib::Error in $@ on failure. ($full_path) = $bookmark_file->load_from_data_dirs ($file) o $file (localized file name) Parses a bookmark file, searching for it inside the data directories. If a file is found, it returns the full path. May croak with a Glib::Error in $@ on failure. $bookmark_file->load_from_file ($file) o $file (localized file name) Parses a bookmark file. May croak with a Glib::Error in $@ on failure. string = $bookmark_file->get_mime_type ($uri) o $uri (string) Gets the MIME type of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_mime_type ($uri, $mime_type) o $uri (string) o $mime_type (string) Sets the MIME type of the bookmark for $uri. If no bookmark for $uri is found one is created. unix timestamp = $bookmark_file->get_modified ($uri) o $uri (string) $bookmark_file->set_modified ($uri, $value) o $uri (string) o $value (unix timestamp) Sets the time the bookmark for $uri was last modified. If no bookmark for $uri is found one is created. $bookmark_file->move_item ($old_uri, $new_uri) o $old_uri (string) o $new_uri (string or undef) Changes the URI of a bookmark item from $old_uri to $new_uri. Any existing bookmark for $new_uri will be overwritten. If $new_uri is undef, then the bookmark is removed. May croak with a Glib::Error in $@ on failure. $bookmark_file->remove_application ($uri, $name) o $uri (string) o $name (string) Removes application registered with $name from the list of applications that have registered a bookmark for $uri inside $bookmark_file. May croak with a Glib::Error in $@ on failure. $bookmark_file->remove_group ($uri, $group) o $uri (string) o $group (string) Removes $group from the list of groups to which the bookmark for $uri belongs to. May croak with a Glib::Error in $@ on failure. $bookmark_file->remove_item ($uri) o $uri (string) Removes the bookmark for $uri from the bookmark file. May croak with a Glib::Error in $@ on failure. integer = $bookmark_file->get_size Gets the number of bookmarks inside the bookmark file. $bookmark_file->get_title ($uri, $title) o $uri (string) Gets the title of the bookmark for $uri. May croak with a Glib::Error in $@ on failure. $bookmark_file->set_title ($uri, $title) o $uri (string) o $title (string) Sets the title of the bookmark for $uri. If no bookmark for $uri is found one is created. string = $bookmark_file->to_data Returns the bookmark file as a string. May croak with a Glib::Error in $@ on failure. $bookmark_file->to_file ($file) o $file (localized file name) Saves the contents of a bookmark file into a file. The write operation is guaranteed to be atomical by writing the contents of the bookmark file to a temporary file and then moving the file to the target file. May croak with a Glib::Error in $@ on failure. list = $bookmark_file->get_uris Returns the URI of all the bookmarks in the bookmark file. unix timestamp = $bookmark_file->get_visited ($uri) o $uri (string) $bookmark_file->set_visited ($uri, $value) o $uri (string) o $value (unix timestamp) Sets the time the bookmark for $uri was last visited. If no bookmark for $uri is found one is created. SEE ALSO
Glib COPYRIGHT
Copyright (C) 2003-2011 by the gtk2-perl team. This software is licensed under the LGPL. See Glib for a full notice. perl v5.14.2 2012-05-24 Glib::BookmarkFile(3pm)
All times are GMT -4. The time now is 08:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy