Why two different views from the same ls command?

Post here if you are a new Porteus member and you're looking for some help.
User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Why two different views from the same ls command?

Post#1 by Ed_P » 14 Oct 2014, 23:43

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?
Ed

User avatar
Slaxmax
Contributor
Contributor
Posts: 408
Joined: 03 Jan 2013, 09:51
Distribution: KDE4
Location: Campinas Brazil https://goo.gl/yrxwKi

Re: Why two different views from the same ls command?

Post#2 by Slaxmax » 14 Oct 2014, 23:53

change command cp to
cp -p
to preserve attributes
“DNA is like a computer program but far, far more advanced than any software ever created.”
― Bill Gates, The Road Ahead

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Why two different views from the same ls command?

Post#3 by Ed_P » 15 Oct 2014, 04:14

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?
Ed

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Why two different views from the same ls command?

Post#4 by Ed_P » 11 Nov 2014, 05:00

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:~$ 
Ed

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: Why two different views from the same ls command?

Post#5 by brokenman » 12 Nov 2014, 01:56

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.
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Why two different views from the same ls command?

Post#6 by Ed_P » 12 Nov 2014, 02:49

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.
Ed

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: Why two different views from the same ls command?

Post#7 by brokenman » 12 Nov 2014, 09:25

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. :lol:
Perhaps you should follow their advice. You may find a better solution than that command just to show time.
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Why two different views from the same ls command?

Post#8 by Ed_P » 12 Nov 2014, 14:48

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)
:friends: That doesn't mean I don't appreciate it. :beer:
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Why two different views from the same ls command?

Post#9 by Bogomips » 12 Nov 2014, 16:21

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

Code: Select all

man date
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)
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: Why two different views from the same ls command?

Post#10 by brokenman » 12 Nov 2014, 17:49

That doesn't mean I don't appreciate it.
:friends:

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.
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

Re: Why two different views from the same ls command?

Post#11 by Ed_P » 12 Nov 2014, 23:22

At this point I finally have exactly what I want. Select files with their last modified date and times and current ones on top. :good:

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 Image brokenman.
Ed

Post Reply