Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

re: Displaying the last file for script

Status
Not open for further replies.

thutmose

MIS
Mar 31, 2002
24
US
Hey guys,


I am trying to look for the last file a user worked with in a script. If I use ls -t $HOME | head -1 this works sometimes for some strange reason. What I am trying to accomplish is to get the last file a user worked with in all subdirectories not just one single directory. Any help would be appreciated.
 
Here's the script I use

ls -lt "$@" | sed '/^-/!d;/^.\{1,58\}/{s///;q;}'

sed will filter out directories and messages - then cuts out the first (most recent) filename to stdout.

Cheers,
ND
 
Nice, but it doesn't recurse into subdirectories correctly - for me at least.

For me this is the one:

lr -lRst|head -2 ***************************************
Party on, dudes!
 
Hey,


lr is not a command and the sed script is not working. I think I found something about the history file I am going to use.
 
lr ... let me quote a man page:
lr [ -1AFLabcdfgilmnopqrstux ] [ -Ws | -Wv ] [ directory | file ... ]
lr- list files, recursively listing any subdirectories encountered
lr is a variant of lc, so files are listed in columns by default.

-l Lists in long format, giving mode, number of links, owner, group,
size in bytes, the time that each file was last modified. The -1
option is assumed.
Unless one of the -c or -u options is specified, the modification
time refers only to changes made to the file's data, or the
creation of the file. It does not record the time that changes were
made to the information stored in the inode.
If the file is a symbolic link, the filename is printed followed by
``->'' and the pathname of the referenced file.
If the file is a special file, the size field will contain the major
and minor device numbers, rather than a size. A total count of
blocks in the directory, including indirect blocks, is printed at
the top of long format listings.
A description of the mode listing is given in ``File modes''.

-R Recursively lists arbitrarily deep subdirectories.
-s Gives size in 512-byte blocks, including indirect blocks, for each
entry.
-t Sorts by time modified (latest first) instead of by name. Files with
equivalent modification times are then sorted alphabetically. The
modification time sorted on depends on whether the -c, or -u option
is also specified.
***************************************
Party on, dudes!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top