Sorry, I haven't had time to check my mail.
Quote:
Originally posted by newbie_st
I tried the command below and it gave me a time of day. I tried to remove the r and it gave me the year of the oldest file.
FILENAME=`ls -ltra | tail -1 | awk '{print $8}'`
|
The year of the oldest file. Correct. So the time of day was the last time the NEWEST file in the directory was modified. The different flags on this usage of ls are:
a - all files
l - long listings
t - sort by last modification time
r - reverse order
Piping the list (or anything else) through tail gives the "tail end" of the output. The default is ten lines, and we ask for one line with "-1." Piping THAT through this simple usage of awk (I am not an awk guru) will simply give you a field (in this case the 8th) in the line. Playing around with that number should show you a bit more.
Try eliminating the tail and/or printing more fields. Depending on how many files are in your directory, you should get a long list.
'ls -ltra | awk '{print $5" "$6" "$7}'
Quote:
Originally posted by newbie_st
I am confused because the first thing I am trying to do is to capture the name of the newest file from the
site I am trying to grab a file of.
|
Well, depending on how you connect, this may become far more complicated.
To do it
locally, start simple:
Code:
# ls -latr
(files listed in mod time order, old to new)
# ls -ltra | tail -1
(gives you the newest file)
#ls -1tra <-- note the change from l (L) to 1 (one)
(lists JUST filenames)
#ls -1tra | tail -1
(lists JUST the newest filename)
With the awk stuff, you can see exactly when each file was modified. I suppose you wouldn't need awk
Quote:
Originally posted by newbie_st
On my own directory I am trying to grab the time stamp of a file that I do know the name of.
I tried the other examples but I seem to be getting parts of a date I acutually want the whole date.
thanks very much!!
|
By the way, I strongly agree with Tinkster. SSH is a far better alternative to FTP if you don't have a strong reason to NOT use a secure connection and transfer.
Also, depending on your situation, you might do a bit of research on the rsync command. It will synchronize a remote directory with a local one (using your choice as the master) and can use the ssh protocol as well.
Above all,
playing with stuff is how you learn. Copy a bunch of your important files into a new experimental directory so you know you have duplicates. Move things. Rename them. List them and sort them. Man tar. The more you ask yourself "I wonder what happens if I...?" the more you'll learn about things that will prove useful sooner or later. If you have everything backed up, you can be adventurous knowing you won't break anything that can't be restored.
I initially assumed you wanted to UPload this file. I realize now that I was probably mistaken about that. I was going to clarify a bit more correct spelling, clumsy phrasing, etc), but I just got a call that my son is sick, so I'm stopping now because posting what's here will help more than no reply. I hope this helps.