We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Interview Question

Medium Priority
767 Views
Last Modified: 2013-12-26
Hi all,

This is one of the interview question. Please see the attached output of ls -lrt | grep "^d"

The command shows the directories of the current folder.

In the output what is mean by 512, 1024, 45056

How it differs (in what condition )

thanks
kamaraj.s
drwxrwxrwx   9 ks296a   frame        512 Feb 24 09:44 usrpr9.4
drwxrwxrwx   2 ks296a   frame        512 Feb 25 07:06 UAT
drwxrwxrwx   2 ks296a   frame        512 Mar  6 02:34 awk
drwxrwxrwx   2 ks296a   frame        512 Mar  9 10:07 log
drwxrwxrwx   2 ks296a   frame       1024 Mar 13 13:06 PD148
drwxrwxrwx   2 ks296a   frame        512 Apr 10 04:27 7201
drwxr-xr-x   2 ks296a   frame        512 Jun  5 10:41 prod_cadm_issue
drwxrwxrwx   4 ks296a   frame        512 Jun  6 06:19 june_proj
drwxr-xr-x   9 ks296a   staff        512 Jun 11 03:28 usrpr9.10
drwxr-xr-x   2 ks296a   frame        512 Jun 18 10:25 chg_pvc
drwxrwxrwx   2 ks296a   frame      45056 Jun 30 07:12 public_html
drwxr-xr-x   2 ks296a   frame        512 Jul  1 03:33 oct_proj

Open in new window

Comment
Watch Question

Commented:
The figures refere to the size of the directories in KB
Kamaraj SubramanianApplication Support Analyst

Author

Commented:
I dont think your answer is correct. Sorry
Kamaraj SubramanianApplication Support Analyst

Author

Commented:
I just want the answer for the below quetion

How it differs (in what condition )
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
Size is in BYTES.
The entries differ in regard to permissions (rwx...), number of links ( . , .. and subdirectories), group ownership, size (number of inodes*inode-size), date/time and name.
Kamaraj SubramanianApplication Support Analyst

Author

Commented:
>>>>The entries differ in regard to permissions (rwx...), number of links ( . , .. and subdirectories), group ownership, size (number of inodes*inode-size), date/time and name.


Can i have a example ?

I have created a simple directory in /tmp folder of my AIX machine

and i checked the size it is 512 after that i copied some files to my directory. then now it comes to 2048

It seems it increases like 512, 1024.......

At what basics it exactly changes ?

please suggest.

thanks
kamaraj.s

$ cd /tmp
$ mkdir kamaraj
$ ls -lrt | grep "^d"
drwxr-xr-x   3 training staff        512 Jun  4 12:57 test
drwxr-xr-x   2 IBMUser9 billjoy      512 Jun  9 13:53 munna
drwxr-xr-x   2 training staff        512 Jul  1 12:53 kamaraj
 
$ ls -lrt
-rw-r--r--   1 training staff         49 Jun 18 07:13 immi.sh
-rw-------   1 training staff      41765 Jun 19 06:56 man51246
-rwxrwxrwx   1 training staff         15 Jun 20 10:51 mycmds.sh
-rw-r--r--   1 training staff        129 Jun 20 11:14 script1.sh
-rwxrwxrwx   1 training staff        129 Jun 20 11:16 yscript1.sh
-rw-r--r--   1 training staff        869 Jun 20 11:29 who1
-rw-r--r--   1 training staff        869 Jun 20 11:29 who2
-rwxrwxrwx   1 training staff        158 Jun 20 11:42 yscript2.sh
-rwxrwxrwx   1 training staff         53 Jun 20 11:56 yscript3.sh
-rw-------   1 training staff      12000 Jun 23 08:35 man17294
-rw-------   1 training staff      12000 Jun 23 13:56 man19544
-rw-------   1 training staff       5100 Jun 25 05:18 man50958
-rw-r--r--   1 training staff        190 Jun 25 14:10 df.work
-rw-r--r--   1 training staff         65 Jun 25 14:10 df.outfile
-rw-------   1 training staff       2287 Jun 29 09:12 man41864
-rw-------   1 training staff       5166 Jul  1 05:55 man36400
-rw-------   1 training staff      12994 Jul  1 10:23 man51258
-rw-------   1 training staff      41765 Jul  1 10:25 man50990
drwxr-xr-x   2 training staff        512 Jul  1 12:53 kamaraj
$ cp man50990 kamaraj/
$ ls -lrt | grep "^d"
drwxr-xr-x   3 training staff        512 Jun  4 12:57 test
drwxr-xr-x   2 IBMUser9 billjoy      512 Jun  9 13:53 munna
drwxr-xr-x   2 training staff        512 Jul  1 12:54 kamaraj
$ cp * kamaraj/
cp: kamaraj is a directory (not copied).
cp: man19022: Permission denied
cp: man19052: Permission denied
cp: man19160: Permission denied
cp: man23046: Permission denied
cp: man30688: Permission denied
cp: man45304: Permission denied
cp: man49308: Permission denied
cp: munna is a directory (not copied).
cp: test is a directory (not copied).
$ ls -lrt | grep "^d"
drwxr-xr-x   3 training staff        512 Jun  4 12:57 test
drwxr-xr-x   2 IBMUser9 billjoy      512 Jun  9 13:53 munna
drwxr-xr-x   2 training staff       2048 Jul  1 12:54 kamaraj

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
You're right, directory sizes for AIX's jfs/jfs2 (not NFS) are always evenly divisible by 512.
I think, as directory size grows, the increment grows with it, but I don't know the exact algorithm.
 

Commented:
Apologies for typo, LS outputs size in bytes not KB.

The ls size is not telling you the total size of all the files and subdirectories inside the directory. It is telling you the the amount of bytes it needs to define the files/subdirectories that it contains. To see the total size of all the files and subdirectories of a directory, you should use use "du -s directory".

Commented:
Just to follow up on my post.

When the ls command lists a size for a directory it allocates size in blocks.  The size of the block varies with distribution and in your distribution it seems to allocate sapce in 512 byte blocks.  Thus a new dirextory will have a size of 512 butes and when this is full it will jump to 1024 byes the 2048 and so on.
Kamaraj SubramanianApplication Support Analyst

Author

Commented:
Hi,

just see the output of the command which i tried now

I have a file called sw.pdf ( more than 2MB) which is present inside the directory called kamaraj.

But eventhough it is showing as 512.

My solution is :  the size grows like 512, 1024.... ( It only grows when the no. of files goes increase (not matter about the size of the file))

thanks
kamaraj.s
$ ls -lrt | grep "^d"
drwxr-xr-x   3 training staff        512 Jun  4 12:57 test
drwxr-xr-x   2 IBMUser9 billjoy      512 Jun  9 13:53 munna
drwxr-xr-x   3 training staff        512 Jul  1 13:34 kamaraj
$ cd kamaraj
$ ls -lrt
total 4952
drwxr-xr-x   2 training staff        512 Jul  1 13:32 inside_dir
-rw-r-----   1 training staff    2528590 Jul  1 13:35 sw.pdf
$ pwd
/tmp/kamaraj
$

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
Yes, that's absolutely correct. The directory only carries a reference to the file, whose size is independent of the actual filesize.
Kamaraj SubramanianApplication Support Analyst

Author

Commented:
but, is that file references are not completely delete once we remove the files in the directory ?

I am confused about this conversion. Now i am using solaris. The solaris machine output gives below

check for the public_html dir
drwxr-xr-x   2 ks296a   frame        512 Jun 18 10:25 chg_pvc
drwxrwxrwx   2 ks296a   frame      45056 Jun 30 07:12 public_html
drwxr-xr-x   2 ks296a   frame        512 Jul  1 03:33 oct_proj
ks296a@/home/moose1/ks296a:>du -s public_html
88      public_html
ks296a@/home/moose1/ks296a:>cd public_html
ks296a@/home/moose1/ks296a/public_html:>ls -lrt
total 0

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
Yes they are, but a directory never shrinks. You'd have to delete and recreate it to reduce its size once it is empty.
And Solaris and AIX seem consistent, don't they?

Commented:
Please see my post.  The figure is the amount of space in bytes needed to define the files/subdirectories that are contained in the directory. This space is allocated when the directory is created and increased as neccesary as files are added.  Therfore an empty directory will show as 512 bytes.  As files are added this space will fill up and more sapce will be added in 512 byte blocks
Kamaraj SubramanianApplication Support Analyst

Author

Commented:
>>>>>>>As files are added this space will fill up and more sapce will be added in 512 byte blocks

In what basics it will increase ?



Commented:
The space is the amount of space used by the operating system to hold the directory information about the files contained in the directory so that the operating system can locate those files.  When a folder is created this space is allocated as 512 bytes.  As the directory fills up it will require more space to hold the directory information so the operating system will allocate more space in 512 byte blocks for this purpose. So the space will grow from 512 to 1024 to 1536 to 2048 and so on as more files are added to the directory.  i.e the space will be always increase by adding 512 bytes to the previous value.
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT
Top Expert 2007
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.