![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| script to find latest executable in particular directory and start that particular ex | kvineeth | Shell Programming and Scripting | 6 | 09-24-2007 08:19 AM |
| Unix shell scripting to find latest file having timestamp embedded... | kaushik25 | AIX | 2 | 08-06-2007 11:42 PM |
| Find and remove all but the latest file | hyennah | Shell Programming and Scripting | 4 | 03-29-2007 12:09 AM |
| finding latest file in Unix | nick12 | UNIX for Dummies Questions & Answers | 2 | 03-05-2005 02:27 AM |
| how to find a file in UNIX without find command? | bluo | Shell Programming and Scripting | 3 | 09-25-2003 12:47 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Jim, Lazytech:
Thanks very much for your advice. I mean the latest file by timestamp or datestamp. Using head -l or tail -l only list file in the begining or in the end. I don't care the order of the file listing. I want to know how to get or find the latest file based on date or time. Thanks. |
|
||||
|
Well, if you man ls, you'll see what the switches mean. The -t switch sorts the listing by 'time' so the output is displayed from newest to oldest. The -r switch reverses it so the newest file is at the end of the listing instead of the beginning. And -l gives you the long listing. Code:
$ ls -lrt total 178880 -rw-r--r-- 1 carlsche carlsche 2727 13 Jul 2005 badlist -rwxr-xr-x 1 carlsche carlsche 1076 13 Jul 2005 scanlist -rw-r--r-- 1 carlsche carlsche 1428173 22 May 21:25 dirlist.album -rwxr-xr-x 1 carlsche carlsche 429 22 May 21:26 dirout -rw-r--r-- 1 carlsche carlsche 1404661 22 May 21:32 dirlist.song -rw-r--r-- 1 carlsche carlsche 1404035 22 May 21:33 dirlist.artist drwxr-xr-x 6 carlsche carlsche 204 24 Sep 22:18 Previous iTunes Libraries drwxr-xr-x 3 carlsche carlsche 102 24 Sep 22:19 Album Artwork drwxr-xr-x 9 carlsche carlsche 306 24 Sep 22:40 iTunes Music -rw-r--r-- 1 carlsche carlsche 42887486 29 Oct 18:32 iTunes Library -rw-r--r-- 1 carlsche carlsche 44442517 29 Oct 18:32 iTunes Music Library.xml Carl |
|
||||
|
Carl:
Thanks for your explanation. It is clear. Question is: if I want to find the latest file (if reversed, it will be last file) to re-name and move to another directory on Linux. What kind of code should I write? Since using ls -lrt |tail -l, it will show a list of the latest file, not the last file. May I write code like this: ls -lrt |tail -l |mv /directory1/file1 /directory2/file2 Please advise. Thank you so much. |
|
||||
|
Try below
> mv `find ./ -maxdepth 1 -atime 10 | tail -1` new_file_name But this will work for files only in current directory and only if there are files that are accessed in last 10 days(you can change the velue) [I am a newbie . excuse me if there is anything wrong] Any way [ $ mv `ls -t | head -1` /temp/newfile_name ] by BOFH is straight forward |
![]() |
| Bookmarks |
| Tags |
| linux |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|