Page 1 of 1
Why two different views from the same ls command?
Posted: 14 Oct 2014, 23:43
by Ed_P
Code: Select all
guest@porteus:~$ sh /mnt/sda3/porteus/Guest/savedat2xzm.sh
total 256M
-rwxrwxrwx 2 root root 256M Oct 14 2014 porteussave.dat
Pls wait, copying in progress
total 256M
-rwxrwxrwx 2 root root 256M Oct 14 19:24 porteussave.dat.xzm
guest@porteus:~$ cat /mnt/sda3/porteus/Guest/savedat2xzm.sh
#!/bin/sh
if [ -d "/mnt/loop/home" ]; then
uloop
fi
ls -lth /mnt/sda3/porteus/changes/
echo Pls wait, copying in progress
cp /mnt/sda3/porteus/changes/porteussave.dat /mnt/sda3/porteus/modsavedat/porteussave.dat.xzm
ls -lth /mnt/sda3/porteus/modsavedat/
The 1st execution of the "ls -lth" command shows the file's month, day and year created. The 2nd "ls -lth" command shows the file's month, day and
time created!! Yes the folder referenced is different but that shouldn't matter. Should it?
Re: Why two different views from the same ls command?
Posted: 14 Oct 2014, 23:53
by Slaxmax
change command cp to
cp -p
to preserve attributes
Re: Why two different views from the same ls command?
Posted: 15 Oct 2014, 04:14
by Ed_P
Slaxmax wrote:change command cp to
cp -p
to preserve attributes
Thanks
Slaxmax. I suspect that will result in the year showing in the output of the 2nd "ls -lth" command. I would prefer to see the time in the 1st "ls -lth" command. Is that possible?
Re: Why two different views from the same ls command?
Posted: 11 Nov 2014, 05:00
by Ed_P
Ok, something is not right. Even with the -p option added to the cp command.
According to what I have found doing a
Google search an "ls -lt" command should have output like this:
Code: Select all
$ ls -lt
total 4
drwxr-xr-x 2 user user 120 2011-08-17 18:14 Pictures
-rw-r--r-- 1 user user 131 2011-08-17 18:07 todo.txt
drwxr-xr-x 2 user user 80 2011-08-17 16:52 Desktop
drwxr-xr-x 2 user user 40 2011-08-17 16:52 Documents
yyyy-mm-dd hh:mm
This is what I am getting:
Code: Select all
guest@porteus:~$ ls -lt /mnt/sda5/porteus/changes/
total 851968
-rwxrwxrwx 1 root root 335544320 Nov 10 19:07 porteussave.dat*
-rwxrwxrwx 1 root root 536870912 Oct 13 08:20 porteussave-1.dat*
guest@porteus:~$
mmm dd hh:mm No year!! And I question the validity of the hh:mm values for the files listed.
-edit-
Always Fresh mode isn't much better.
Code: Select all
guest@porteus:~$ ls -lt /mnt/sda5/porteus/changes/
total 851968
-rwxrwxrwx 1 root root 335544320 Nov 11 2014 porteussave.dat*
-rwxrwxrwx 1 root root 536870912 Oct 13 12:20 porteussave-1.dat*
guest@porteus:~$
And note the different "time" value for the bottom file.
-edit 2-
Same result in
rc1's Always Fresh mode.
Code: Select all
guest@porteus:~$ ls -lt /mnt/sda5/porteus/changes/
total 851968
-rwxrwxrwx 1 root root 335544320 Nov 11 2014 porteussave.dat*
-rwxrwxrwx 1 root root 536870912 Oct 13 12:20 porteussave-1.dat*
guest@porteus:~$
Re: Why two different views from the same ls command?
Posted: 12 Nov 2014, 01:56
by brokenman
Don't trust google. Get it from the horse's mouth. Read the help file on the 'ls' command. In particular what the switch -l and -t mean. The output looks as expected to me.
I am not sure why the time stamp isn't accessed on some of your outputs but usually when the file is older than a certain time (or the time stamp is not read) just the year is shown.
Re: Why two different views from the same ls command?
Posted: 12 Nov 2014, 02:49
by Ed_P
This works (
thanks to google):
Code: Select all
guest@porteus:~$ ls -lts --full-time /mnt/sda5/porteus/changes/
total 851968
327680 -rwxrwxrwx 1 root root 335544320 2014-11-11 03:52:15.131061300 -0500 porteussave.dat*
524288 -rwxrwxrwx 1 root root 536870912 2014-10-13 08:20:56.341142900 -0400 porteussave-1.dat*
Just need to find a way to edit it down to:
Code: Select all
327680 - 2014-11-11 03:52:15 porteussave.dat*
524288 - 2014-10-13 08:20:56 porteussave-1.dat*
brokenman wrote:I am not sure why the time stamp isn't accessed on some of your outputs but usually when the file is older than a certain time (or the time stamp is not read) just the year is shown.
I read that "ls" only shows the year for files over 6 months old but that is not the case with the "Nov 11 2014 porteussave.dat" file.
-edit-
This ain't bad.
Code: Select all
ls -lts --full-time /mnt/sda5/porteus/changes/ | awk '{print $1 " " $2 " "$7 " " $8 " " $9 " " $10}' | more
total 851968
327680 -rwxrwxrwx 2014-11-11 03:52:15.131061300 -0500 porteussave.dat*
524288 -rwxrwxrwx 2014-10-13 08:20:56.341142900 -0400 porteussave-1.dat*
guest@porteus:~$
Would like to make the extended "ls" command a function but it uses both the " and ' characters.
Re: Why two different views from the same ls command?
Posted: 12 Nov 2014, 09:25
by brokenman
This works (thanks to google)
Wouldn't it just have been easier to follow advice? (I somehow knew you wouldn't)
You took the long way around to find a thread that also suggests reading the ls man page.
Perhaps you should follow
their advice. You may find a better solution than that command just to show time.
Re: Why two different views from the same ls command?
Posted: 12 Nov 2014, 14:48
by Ed_P
brokenman wrote:Wouldn't it just have been easier to follow advice?
No, unfortunately. I do read the --help output of commands including "ls" but the output usually makes little sense to me. For example:
Code: Select all
--time-style=STYLE with -l, show times using style STYLE:
full-iso, long-iso, iso, locale, +FORMAT.
FORMAT is interpreted like 'date'; if FORMAT is
FORMAT1<newline>FORMAT2, FORMAT1 applies to
non-recent files and FORMAT2 to recent files;
if STYLE is prefixed with 'posix-', STYLE
takes effect only outside the POSIX locale
may be clear to you but to me it reads like a legal contract.
I understand examples better.
(I somehow knew you wouldn't)
That doesn't mean I don't appreciate it.
Re: Why two different views from the same ls command?
Posted: 12 Nov 2014, 16:21
by Bogomips
Ed_P wrote:For example:
Code: Select all
--time-style=STYLE with -l, show times using style STYLE:
full-iso, long-iso, iso, locale, +FORMAT.
FORMAT is interpreted like 'date'; if FORMAT is
FORMAT1<newline>FORMAT2, FORMAT1 applies to
non-recent files and FORMAT2 to recent files;
if STYLE is prefixed with 'posix-', STYLE
takes effect only outside the POSIX locale
may be clear to you but to me it reads like a legal contract.
I understand examples better.
Solution here is to do
Then, decoding example, FORMAT1 and FORMAT2 are both of type FORMAT, but 1 is different from 2. However can't see any other solution but to write a script using FORMAT1 and FORMAT2 in order to ascertain what is a recent file, and what is a non-recent file. 8)
Re: Why two different views from the same ls command?
Posted: 12 Nov 2014, 17:49
by brokenman
That doesn't mean I don't appreciate it.
Code: Select all
guest@porteus:/tmp$ ls -la --time atime --time-style long-iso| awk '{print $6,$7,$8}'
2014-11-12 15:31 ./
2014-11-12 15:25 ../
1994-05-04 18:44 .ICE-unix/
2014-11-12 15:25 .X0-lock
1994-05-04 18:44 .X11-unix/
2014-11-12 15:25 .xfsm-ICE-XEEAPX
2014-11-12 15:25 keyring-w3MKKE/
After --time you can use a word. atime for access time. ctime for creation time. Using no --time argument at all tries to access the last modified time.
--time-style refers to the style of time you want. In this case I think it is the long-iso that you want.
Re: Why two different views from the same ls command?
Posted: 12 Nov 2014, 23:22
by Ed_P
At this point I finally have exactly what I want. Select files with their last modified date and times and current ones on top.
Code: Select all
DIR () {
# echo "$1"
# ls -ghlst --full-time $1 | awk '{print $1 " " $2 " "$6 " " $7 " " $8 " " $9}' | more
ls -lght --time-style long-iso $1 | awk '{print $5,$6,$4,$7}'
}
Code: Select all
2014-11-12 10:59 320M porteussave.dat.xzm
2014-11-12 11:02 320M porteussave.dat
2014-10-13 08:20 512M porteussave-1.dat
Thank you
brokenman.