ls -lt listing in Linux

16,929
  1. If there are multiple files and directories in my current folder and if i run ls -lt will it sort in descending order based on time for files and directories together or will it consider files and directories seperately.

Easy to find out, just run the command and see whether it groups them separately or not...

If you use --group-directories-first, ls will group directories separately, otherwise it won't.

  1. What is the time mentioned in ls -lrt output for directories . Does it mean when the directories was created or When the files inside the directories were created or deleted or file inside the directories were updated.

A directory is a list of file names (and their inode numbers). So the directory is 'modified' whenever you create, delete, or rename something within that directory.

  1. When i create a directory in my current directory the size of the empty directory is showing as 4096 what does this mean. Is this not showing actual size of the directory.

A directory is a list of file names (and their inode numbers). You're seeing only the size of this list – not the sum of all file sizes inside.

  1. What does the first line in the output (total 8) of ls -lrt means

It's the sum of all sizes reported in the output. (If you used the -h option, you would see it in kilobytes.)

Note however that it does not include the sizes of everything in subdirectories; you would need to use e.g. ncdu or du -hs to calculate that.

Share:
16,929

Related videos on Youtube

rizwan
Author by

rizwan

Updated on September 18, 2022

Comments

  • rizwan
    rizwan almost 2 years

    How does ls -list listing works in Linux?

    1. If there are multiple files and directories in my current folder and if I run ls -lt will it sort in descending order based on time for files and directories together or will it consider files and directories seperately?

    2. What is the time mentioned in ls -lrt output for directories? Does it mean when the directories was created or when the files inside the directories were created or deleted or file inside the directories were updated?

    3. When I create a directory in my current directory the size of the empty directory is showing as 4096, what does this mean? Is this not showing actual size of the directory.

    4. What does the first line in the output (total 8) of ls -lrt mean?

      -bash-4.2$ ls -rlt
      total 8
      -rw-rw-r-- 1 kony kony    0 Oct 20 09:23 filetest1.txt
      -rw-rw-r-- 1 kony kony    0 Oct 20 09:24 filetest2.txt
      drwxrwxr-x 2 kony kony 4096 Oct 20 09:24 test_1_A
      drwxrwxr-x 2 kony kony 4096 Oct 20 09:25 test_2_A
      -rw-rw-r-- 1 kony kony    0 Oct 20 09:26 filetest3.txt
      -bash-4.2$
      
  • rizwan
    rizwan over 4 years
    Regarding your below statement . "A directory is a list of file names (and their inode numbers). You're seeing only the size of this list – not the sum of all file sizes inside." I noticed if i update any file within a directory using vi than directory timestamp is changed but if i update with command "echo updated >> filename" then directory modification time is not changed . Any idea about this behaviour
  • user1686
    user1686 over 4 years
    @rizwan: Many text editors perform two-step updates – e.g. they might copy the original to a 'backup' before updating, or they might create a new file and then move it on top of the old one. (Vim in particular has at least three different knobs letting you choose between 4–5 different modes, if I recall correctly.)
  • user1686
    user1686 over 4 years
    @rizwan: Take a look with ls -lti – if you see the inode number changing, then the text editor is definitely doing atomic updates using "write to temp file, then rename" method.
  • rizwan
    rizwan over 4 years
    Perfect . inode number is changing when i update through vi , but with echo command it is not changing