How can I see the size of files and directories in linux?












176















How can I see the size of files and directories in Linux? If use df -m then it shows the size of all the directory at the top level but for the directories and files inside the directory how to check size?










share|improve this question





























    176















    How can I see the size of files and directories in Linux? If use df -m then it shows the size of all the directory at the top level but for the directories and files inside the directory how to check size?










    share|improve this question



























      176












      176








      176


      53






      How can I see the size of files and directories in Linux? If use df -m then it shows the size of all the directory at the top level but for the directories and files inside the directory how to check size?










      share|improve this question
















      How can I see the size of files and directories in Linux? If use df -m then it shows the size of all the directory at the top level but for the directories and files inside the directory how to check size?







      linux file






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 27 '14 at 17:49









      Tshepang

      6,0951772112




      6,0951772112










      asked Jul 30 '12 at 10:57









      AdvaitAdvait

      1,06021016




      1,06021016
























          14 Answers
          14






          active

          oldest

          votes


















          311














          It's simple. Use ls command for files and du command for directories.



          Checking File Sizes



          ls -l filename /* Size of the file*/
          ls -l * /* Size of All the files in the current directory */
          ls -al * /* Size of All the files including hidden files in the current directory */
          ls -al dir/ /* Size of All the files including hidden files in the 'dir' directory */


          ls command will not list the actual size of directories(why?). Therefore, we use du for this purpose.



          Checking Directory sizes



          du -sh directory_name    /* Gives you the summarized(-s) size of the directory in human readable(-h) format*/
          du -bsh * /* Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in human readable(-h) format*/


          Including -h option in any of the above commands (for Ex: ls -lh * or du -sh) will give you size in human readable format (kb, mb,gb, ...)



          For more information see man ls and man du






          share|improve this answer





















          • 2





            ls won't show you the total size of all contents of a directory.

            – Maxim Egorushkin
            Jun 23 '14 at 15:30






          • 1





            @MaximYegorushkin Thank you. Corrected.

            – mk..
            Jun 24 '14 at 9:55






          • 2





            how can I see the size in bytes (Mega, Giga,... ) ?

            – Francisco Corrales Morales
            Jul 22 '14 at 19:14






          • 4





            @FranciscoCorralesMorales ls -lh will show you the size in kb MB GB etc.

            – mk..
            Aug 5 '15 at 3:25






          • 2





            note that the du command shows the disk usage of the file, wich might be larger than the actual size of the file. You can use du -d to get the actual size as ls does. More info: unix.stackexchange.com/a/106278/155224

            – Lucas Alonso
            Apr 19 '17 at 21:04



















          108














          There is du command.



          Size of a directory:



          $ du -sh /tmp


          Size of a file:



          $ du -h /tmp/xyz




          --apparent-size command line switch makes it measure apparent sizes (what ls shows) rather than actual disk usage.






          share|improve this answer





















          • 1





            how can I see the size in bytes (Kilo, Mega, Giga,... ) ?

            – Francisco Corrales Morales
            Jul 22 '14 at 19:17






          • 6





            @FranciscoCorralesMorales -h flag should do what you ask: print sizes in human readable format (e.g., 1K 234M 2G)

            – Maxim Egorushkin
            Jul 22 '14 at 19:56






          • 1





            I don't think this is right. What du does is Summarize disk usage of the set of FILEs , that is if a file is very small (i.e. 2140 bytes) the output of "du" is (in my case) 4KB because that's the size of the cluster

            – mfloris
            Jun 20 '16 at 6:45











          • @mfloris Use --apparent-size then.

            – Maxim Egorushkin
            Jun 20 '16 at 9:26











          • I like du -hs * to see the size of all the files, and directories in the current directory.

            – Jordan Stewart
            Jan 20 '17 at 1:08



















          47














          Use ls -s to list file size, or if you prefer ls -sh for human readable sizes.



          For directories use du, and again, du -h for human readable sizes.






          share|improve this answer





















          • 4





            A tip is to use; 'du -sh *' to list all the directory sizes. :)

            – Entalpi
            Feb 28 '17 at 9:12



















          19














          You can use:



          ls -lh



          Using this command you'll see the apparent space of the directory and true space of the files and in details the names of the files displayed, besides the size and creation date of each.






          share|improve this answer


























          • ls -l will give u file size including the metadata? as it seems to be slightly 4kb bigger for one of file that i tried with

            – Jun711
            Sep 13 '18 at 20:58



















          9














          ls -l --block-size=M will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB.



          If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead.



          If you don't want the M suffix attached to the file size, you can use something like --block-size=1M. Thanks Stéphane Chazelas for suggesting this.



          This is described in the man page for ls; man ls and search for SIZE. It allows for units other than MB/MiB as well, and from the looks of it (I didn't try that) arbitrary block sizes as well (so you could see the file size as number of 412-byte blocks, if you want to).



          Note that the --block-size parameter is a GNU extension on top of the Open Group's ls, so this may not work if you don't have a GNU userland (which most Linux installations do). The ls from GNU coreutils 8.5 does support --block-size as described above.






          share|improve this answer































            8














            File Size in MB



            ls -l --b=M  filename | cut -d " " -f5


            File Size in GB



            ls -l --b=G  filename | cut -d " " -f5





            share|improve this answer

































              6














              There is also a great ncdu utility - it can show directory size with detailed info about subfolders and files.



              Installation



              Ubuntu:



              $ sudo apt-get install ncdu


              Usage



              Just type ncdu [path] in the command line. After a few seconds for analyzing the path, you will see something like this:



              $ ncdu 1.11 ~ Use the arrow keys to navigate, press ? for help
              --- / ---------------------------------------------------------
              . 96,1 GiB [##########] /home
              . 17,7 GiB [# ] /usr
              . 4,5 GiB [ ] /var
              1,1 GiB [ ] /lib
              732,1 MiB [ ] /opt
              . 275,6 MiB [ ] /boot
              198,0 MiB [ ] /storage
              . 153,5 MiB [ ] /run
              . 16,6 MiB [ ] /etc
              13,5 MiB [ ] /bin
              11,3 MiB [ ] /sbin
              . 8,8 MiB [ ] /tmp
              . 2,2 MiB [ ] /dev
              ! 16,0 KiB [ ] /lost+found
              8,0 KiB [ ] /media
              8,0 KiB [ ] /snap
              4,0 KiB [ ] /lib64
              e 4,0 KiB [ ] /srv
              ! 4,0 KiB [ ] /root
              e 4,0 KiB [ ] /mnt
              e 4,0 KiB [ ] /cdrom
              . 0,0 B [ ] /proc
              . 0,0 B [ ] /sys
              @ 0,0 B [ ] initrd.img.old
              @ 0,0 B [ ] initrd.img
              @ 0,0 B [ ] vmlinuz.old
              @ 0,0 B [ ] vmlinuz


              Delete the currently highlighted element with d, exit with CTRL + c






              share|improve this answer

































                5














                I do the following all the time:



                $ du -sh backup-lr-May-02-2017-1493723588.tar.gz


                NB:



                -s, --summarize
                display only a total for each argument
                -h, --human-readable
                print sizes in human readable format (e.g., 1K 234M 2G)





                share|improve this answer































                  5














                  You can use below command to get list of files in easily human readable format.




                  ls -lrtsh







                  share|improve this answer































                    2














                    You have to differenciate between file size and disk usage. The main difference between the two comes from the fact that files are "cut into pieces" and stored in blocks.



                    Modern block size is 4KiB, so files will use disk space multiple of 4KiB, regardless of how small they are.



                    If you use the command stat you can see both figures side by side.



                    stat file.c


                    If you want a more compact view for a directory, you can use ls -ls, which will give you usage in 1KiB units.



                    ls -ls dir


                    Also du will give you real disk usage, in 1KiB units, or dutree with the -u flag.



                    Example: usage of a 1 byte file



                    $ echo "" > file.c

                    $ ls -l file.c
                    -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                    $ ls -ls file.c
                    4 -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                    $ du file.c
                    4 file.c

                    $ dutree file.c
                    [ file.c 1 B ]

                    $ dutree -u file.c
                    [ file.c 4.00 KiB ]

                    $ stat file.c
                    File: file.c
                    Size: 1 Blocks: 8 IO Block: 4096 regular file
                    Device: 2fh/47d Inode: 2185244 Links: 1
                    Access: (0644/-rw-r--r--) Uid: ( 1000/ nacho) Gid: ( 1000/ nacho)
                    Access: 2018-04-30 20:41:58.002124411 +0200
                    Modify: 2018-04-30 20:42:24.835458383 +0200
                    Change: 2018-04-30 20:42:24.835458383 +0200
                    Birth: -


                    In addition, in modern filesystems we can have snapshots, sparse files (files with holes in them) that further complicate the situation.



                    You can see more details in this article: understanding file size in Linux






                    share|improve this answer































                      2














                      I'm a Ubuntu 16.04 user myself and I find that the ll command is by far the easiest way to see a directory's contents. I've noticed that not all Linux distributions support this command, but there's probably a workaround/install for each distro out there.



                      Example:



                      user@user-XPS-15-9560:/$ ll
                      total 188
                      drwxr-xr-x 27 root root 4096 Jan 26 09:13 ./
                      drwxr-xr-x 27 root root 4096 Jan 26 09:13 ../
                      drwxr-xr-x 2 root root 4096 Jan 22 15:13 bin/
                      drwxr-xr-x 4 root root 12288 Jan 29 11:35 boot/
                      drwxr-xr-x 2 root root 4096 Sep 3 18:14 cdrom/
                      drwxr-xr-x 20 root root 4440 Feb 5 08:43 dev/
                      drwxr-xr-x 153 root root 12288 Feb 2 15:17 etc/
                      drwxr-xr-x 4 root root 4096 Sep 3 18:15 home/
                      ...


                      The biggest advantage for me is that it's quick and really intuitive to use.



                      UPDATE: what I didn't know was that on Ubuntu it's a pre-configured alias. You can easily set it yourself by executing alias ll="ls -la" on the command line, or by adding this entry in your .bashrc config file:



                      sudo nano ~/.bashrc
                      ...add line described above and save file by pressing Ctrl+X and Y...
                      source ~/.bashrc





                      share|improve this answer

































                        1














                        you can use ls -sh in linux you can do sort also
                        you need to go to dir where you want to check the size of files






                        share|improve this answer































                          0














                          If you are using it in a script, use stat.



                          stat -c %s filename


                          That will give you size in bytes. See man stat for more output format options.






                          share|improve this answer































                            0














                            go to specific directory then run below command



                            # du -sh * 

                            4.0K 1
                            4.0K anadb.sh --> Shell file
                            4.0K db.sh/ --> shell file
                            24K backup4/ --> Directory
                            8.0K backup6/ --> Directory
                            1.9G backup.sql.gz --> sql file





                            share|improve this answer

























                              Your Answer






                              StackExchange.ifUsing("editor", function () {
                              StackExchange.using("externalEditor", function () {
                              StackExchange.using("snippets", function () {
                              StackExchange.snippets.init();
                              });
                              });
                              }, "code-snippets");

                              StackExchange.ready(function() {
                              var channelOptions = {
                              tags: "".split(" "),
                              id: "1"
                              };
                              initTagRenderer("".split(" "), "".split(" "), channelOptions);

                              StackExchange.using("externalEditor", function() {
                              // Have to fire editor after snippets, if snippets enabled
                              if (StackExchange.settings.snippets.snippetsEnabled) {
                              StackExchange.using("snippets", function() {
                              createEditor();
                              });
                              }
                              else {
                              createEditor();
                              }
                              });

                              function createEditor() {
                              StackExchange.prepareEditor({
                              heartbeatType: 'answer',
                              autoActivateHeartbeat: false,
                              convertImagesToLinks: true,
                              noModals: true,
                              showLowRepImageUploadWarning: true,
                              reputationToPostImages: 10,
                              bindNavPrevention: true,
                              postfix: "",
                              imageUploader: {
                              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                              allowUrls: true
                              },
                              onDemand: true,
                              discardSelector: ".discard-answer"
                              ,immediatelyShowMarkdownHelp:true
                              });


                              }
                              });














                              draft saved

                              draft discarded


















                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11720079%2fhow-can-i-see-the-size-of-files-and-directories-in-linux%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown

























                              14 Answers
                              14






                              active

                              oldest

                              votes








                              14 Answers
                              14






                              active

                              oldest

                              votes









                              active

                              oldest

                              votes






                              active

                              oldest

                              votes









                              311














                              It's simple. Use ls command for files and du command for directories.



                              Checking File Sizes



                              ls -l filename /* Size of the file*/
                              ls -l * /* Size of All the files in the current directory */
                              ls -al * /* Size of All the files including hidden files in the current directory */
                              ls -al dir/ /* Size of All the files including hidden files in the 'dir' directory */


                              ls command will not list the actual size of directories(why?). Therefore, we use du for this purpose.



                              Checking Directory sizes



                              du -sh directory_name    /* Gives you the summarized(-s) size of the directory in human readable(-h) format*/
                              du -bsh * /* Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in human readable(-h) format*/


                              Including -h option in any of the above commands (for Ex: ls -lh * or du -sh) will give you size in human readable format (kb, mb,gb, ...)



                              For more information see man ls and man du






                              share|improve this answer





















                              • 2





                                ls won't show you the total size of all contents of a directory.

                                – Maxim Egorushkin
                                Jun 23 '14 at 15:30






                              • 1





                                @MaximYegorushkin Thank you. Corrected.

                                – mk..
                                Jun 24 '14 at 9:55






                              • 2





                                how can I see the size in bytes (Mega, Giga,... ) ?

                                – Francisco Corrales Morales
                                Jul 22 '14 at 19:14






                              • 4





                                @FranciscoCorralesMorales ls -lh will show you the size in kb MB GB etc.

                                – mk..
                                Aug 5 '15 at 3:25






                              • 2





                                note that the du command shows the disk usage of the file, wich might be larger than the actual size of the file. You can use du -d to get the actual size as ls does. More info: unix.stackexchange.com/a/106278/155224

                                – Lucas Alonso
                                Apr 19 '17 at 21:04
















                              311














                              It's simple. Use ls command for files and du command for directories.



                              Checking File Sizes



                              ls -l filename /* Size of the file*/
                              ls -l * /* Size of All the files in the current directory */
                              ls -al * /* Size of All the files including hidden files in the current directory */
                              ls -al dir/ /* Size of All the files including hidden files in the 'dir' directory */


                              ls command will not list the actual size of directories(why?). Therefore, we use du for this purpose.



                              Checking Directory sizes



                              du -sh directory_name    /* Gives you the summarized(-s) size of the directory in human readable(-h) format*/
                              du -bsh * /* Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in human readable(-h) format*/


                              Including -h option in any of the above commands (for Ex: ls -lh * or du -sh) will give you size in human readable format (kb, mb,gb, ...)



                              For more information see man ls and man du






                              share|improve this answer





















                              • 2





                                ls won't show you the total size of all contents of a directory.

                                – Maxim Egorushkin
                                Jun 23 '14 at 15:30






                              • 1





                                @MaximYegorushkin Thank you. Corrected.

                                – mk..
                                Jun 24 '14 at 9:55






                              • 2





                                how can I see the size in bytes (Mega, Giga,... ) ?

                                – Francisco Corrales Morales
                                Jul 22 '14 at 19:14






                              • 4





                                @FranciscoCorralesMorales ls -lh will show you the size in kb MB GB etc.

                                – mk..
                                Aug 5 '15 at 3:25






                              • 2





                                note that the du command shows the disk usage of the file, wich might be larger than the actual size of the file. You can use du -d to get the actual size as ls does. More info: unix.stackexchange.com/a/106278/155224

                                – Lucas Alonso
                                Apr 19 '17 at 21:04














                              311












                              311








                              311







                              It's simple. Use ls command for files and du command for directories.



                              Checking File Sizes



                              ls -l filename /* Size of the file*/
                              ls -l * /* Size of All the files in the current directory */
                              ls -al * /* Size of All the files including hidden files in the current directory */
                              ls -al dir/ /* Size of All the files including hidden files in the 'dir' directory */


                              ls command will not list the actual size of directories(why?). Therefore, we use du for this purpose.



                              Checking Directory sizes



                              du -sh directory_name    /* Gives you the summarized(-s) size of the directory in human readable(-h) format*/
                              du -bsh * /* Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in human readable(-h) format*/


                              Including -h option in any of the above commands (for Ex: ls -lh * or du -sh) will give you size in human readable format (kb, mb,gb, ...)



                              For more information see man ls and man du






                              share|improve this answer















                              It's simple. Use ls command for files and du command for directories.



                              Checking File Sizes



                              ls -l filename /* Size of the file*/
                              ls -l * /* Size of All the files in the current directory */
                              ls -al * /* Size of All the files including hidden files in the current directory */
                              ls -al dir/ /* Size of All the files including hidden files in the 'dir' directory */


                              ls command will not list the actual size of directories(why?). Therefore, we use du for this purpose.



                              Checking Directory sizes



                              du -sh directory_name    /* Gives you the summarized(-s) size of the directory in human readable(-h) format*/
                              du -bsh * /* Gives you the apparent(-b) summarized(-s) size of all the files and directories in the current directory in human readable(-h) format*/


                              Including -h option in any of the above commands (for Ex: ls -lh * or du -sh) will give you size in human readable format (kb, mb,gb, ...)



                              For more information see man ls and man du







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jun 8 '18 at 0:32

























                              answered Jul 30 '12 at 10:59









                              mk..mk..

                              8,290114778




                              8,290114778








                              • 2





                                ls won't show you the total size of all contents of a directory.

                                – Maxim Egorushkin
                                Jun 23 '14 at 15:30






                              • 1





                                @MaximYegorushkin Thank you. Corrected.

                                – mk..
                                Jun 24 '14 at 9:55






                              • 2





                                how can I see the size in bytes (Mega, Giga,... ) ?

                                – Francisco Corrales Morales
                                Jul 22 '14 at 19:14






                              • 4





                                @FranciscoCorralesMorales ls -lh will show you the size in kb MB GB etc.

                                – mk..
                                Aug 5 '15 at 3:25






                              • 2





                                note that the du command shows the disk usage of the file, wich might be larger than the actual size of the file. You can use du -d to get the actual size as ls does. More info: unix.stackexchange.com/a/106278/155224

                                – Lucas Alonso
                                Apr 19 '17 at 21:04














                              • 2





                                ls won't show you the total size of all contents of a directory.

                                – Maxim Egorushkin
                                Jun 23 '14 at 15:30






                              • 1





                                @MaximYegorushkin Thank you. Corrected.

                                – mk..
                                Jun 24 '14 at 9:55






                              • 2





                                how can I see the size in bytes (Mega, Giga,... ) ?

                                – Francisco Corrales Morales
                                Jul 22 '14 at 19:14






                              • 4





                                @FranciscoCorralesMorales ls -lh will show you the size in kb MB GB etc.

                                – mk..
                                Aug 5 '15 at 3:25






                              • 2





                                note that the du command shows the disk usage of the file, wich might be larger than the actual size of the file. You can use du -d to get the actual size as ls does. More info: unix.stackexchange.com/a/106278/155224

                                – Lucas Alonso
                                Apr 19 '17 at 21:04








                              2




                              2





                              ls won't show you the total size of all contents of a directory.

                              – Maxim Egorushkin
                              Jun 23 '14 at 15:30





                              ls won't show you the total size of all contents of a directory.

                              – Maxim Egorushkin
                              Jun 23 '14 at 15:30




                              1




                              1





                              @MaximYegorushkin Thank you. Corrected.

                              – mk..
                              Jun 24 '14 at 9:55





                              @MaximYegorushkin Thank you. Corrected.

                              – mk..
                              Jun 24 '14 at 9:55




                              2




                              2





                              how can I see the size in bytes (Mega, Giga,... ) ?

                              – Francisco Corrales Morales
                              Jul 22 '14 at 19:14





                              how can I see the size in bytes (Mega, Giga,... ) ?

                              – Francisco Corrales Morales
                              Jul 22 '14 at 19:14




                              4




                              4





                              @FranciscoCorralesMorales ls -lh will show you the size in kb MB GB etc.

                              – mk..
                              Aug 5 '15 at 3:25





                              @FranciscoCorralesMorales ls -lh will show you the size in kb MB GB etc.

                              – mk..
                              Aug 5 '15 at 3:25




                              2




                              2





                              note that the du command shows the disk usage of the file, wich might be larger than the actual size of the file. You can use du -d to get the actual size as ls does. More info: unix.stackexchange.com/a/106278/155224

                              – Lucas Alonso
                              Apr 19 '17 at 21:04





                              note that the du command shows the disk usage of the file, wich might be larger than the actual size of the file. You can use du -d to get the actual size as ls does. More info: unix.stackexchange.com/a/106278/155224

                              – Lucas Alonso
                              Apr 19 '17 at 21:04













                              108














                              There is du command.



                              Size of a directory:



                              $ du -sh /tmp


                              Size of a file:



                              $ du -h /tmp/xyz




                              --apparent-size command line switch makes it measure apparent sizes (what ls shows) rather than actual disk usage.






                              share|improve this answer





















                              • 1





                                how can I see the size in bytes (Kilo, Mega, Giga,... ) ?

                                – Francisco Corrales Morales
                                Jul 22 '14 at 19:17






                              • 6





                                @FranciscoCorralesMorales -h flag should do what you ask: print sizes in human readable format (e.g., 1K 234M 2G)

                                – Maxim Egorushkin
                                Jul 22 '14 at 19:56






                              • 1





                                I don't think this is right. What du does is Summarize disk usage of the set of FILEs , that is if a file is very small (i.e. 2140 bytes) the output of "du" is (in my case) 4KB because that's the size of the cluster

                                – mfloris
                                Jun 20 '16 at 6:45











                              • @mfloris Use --apparent-size then.

                                – Maxim Egorushkin
                                Jun 20 '16 at 9:26











                              • I like du -hs * to see the size of all the files, and directories in the current directory.

                                – Jordan Stewart
                                Jan 20 '17 at 1:08
















                              108














                              There is du command.



                              Size of a directory:



                              $ du -sh /tmp


                              Size of a file:



                              $ du -h /tmp/xyz




                              --apparent-size command line switch makes it measure apparent sizes (what ls shows) rather than actual disk usage.






                              share|improve this answer





















                              • 1





                                how can I see the size in bytes (Kilo, Mega, Giga,... ) ?

                                – Francisco Corrales Morales
                                Jul 22 '14 at 19:17






                              • 6





                                @FranciscoCorralesMorales -h flag should do what you ask: print sizes in human readable format (e.g., 1K 234M 2G)

                                – Maxim Egorushkin
                                Jul 22 '14 at 19:56






                              • 1





                                I don't think this is right. What du does is Summarize disk usage of the set of FILEs , that is if a file is very small (i.e. 2140 bytes) the output of "du" is (in my case) 4KB because that's the size of the cluster

                                – mfloris
                                Jun 20 '16 at 6:45











                              • @mfloris Use --apparent-size then.

                                – Maxim Egorushkin
                                Jun 20 '16 at 9:26











                              • I like du -hs * to see the size of all the files, and directories in the current directory.

                                – Jordan Stewart
                                Jan 20 '17 at 1:08














                              108












                              108








                              108







                              There is du command.



                              Size of a directory:



                              $ du -sh /tmp


                              Size of a file:



                              $ du -h /tmp/xyz




                              --apparent-size command line switch makes it measure apparent sizes (what ls shows) rather than actual disk usage.






                              share|improve this answer















                              There is du command.



                              Size of a directory:



                              $ du -sh /tmp


                              Size of a file:



                              $ du -h /tmp/xyz




                              --apparent-size command line switch makes it measure apparent sizes (what ls shows) rather than actual disk usage.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jun 20 '16 at 9:26

























                              answered Jul 30 '12 at 10:59









                              Maxim EgorushkinMaxim Egorushkin

                              86k1199182




                              86k1199182








                              • 1





                                how can I see the size in bytes (Kilo, Mega, Giga,... ) ?

                                – Francisco Corrales Morales
                                Jul 22 '14 at 19:17






                              • 6





                                @FranciscoCorralesMorales -h flag should do what you ask: print sizes in human readable format (e.g., 1K 234M 2G)

                                – Maxim Egorushkin
                                Jul 22 '14 at 19:56






                              • 1





                                I don't think this is right. What du does is Summarize disk usage of the set of FILEs , that is if a file is very small (i.e. 2140 bytes) the output of "du" is (in my case) 4KB because that's the size of the cluster

                                – mfloris
                                Jun 20 '16 at 6:45











                              • @mfloris Use --apparent-size then.

                                – Maxim Egorushkin
                                Jun 20 '16 at 9:26











                              • I like du -hs * to see the size of all the files, and directories in the current directory.

                                – Jordan Stewart
                                Jan 20 '17 at 1:08














                              • 1





                                how can I see the size in bytes (Kilo, Mega, Giga,... ) ?

                                – Francisco Corrales Morales
                                Jul 22 '14 at 19:17






                              • 6





                                @FranciscoCorralesMorales -h flag should do what you ask: print sizes in human readable format (e.g., 1K 234M 2G)

                                – Maxim Egorushkin
                                Jul 22 '14 at 19:56






                              • 1





                                I don't think this is right. What du does is Summarize disk usage of the set of FILEs , that is if a file is very small (i.e. 2140 bytes) the output of "du" is (in my case) 4KB because that's the size of the cluster

                                – mfloris
                                Jun 20 '16 at 6:45











                              • @mfloris Use --apparent-size then.

                                – Maxim Egorushkin
                                Jun 20 '16 at 9:26











                              • I like du -hs * to see the size of all the files, and directories in the current directory.

                                – Jordan Stewart
                                Jan 20 '17 at 1:08








                              1




                              1





                              how can I see the size in bytes (Kilo, Mega, Giga,... ) ?

                              – Francisco Corrales Morales
                              Jul 22 '14 at 19:17





                              how can I see the size in bytes (Kilo, Mega, Giga,... ) ?

                              – Francisco Corrales Morales
                              Jul 22 '14 at 19:17




                              6




                              6





                              @FranciscoCorralesMorales -h flag should do what you ask: print sizes in human readable format (e.g., 1K 234M 2G)

                              – Maxim Egorushkin
                              Jul 22 '14 at 19:56





                              @FranciscoCorralesMorales -h flag should do what you ask: print sizes in human readable format (e.g., 1K 234M 2G)

                              – Maxim Egorushkin
                              Jul 22 '14 at 19:56




                              1




                              1





                              I don't think this is right. What du does is Summarize disk usage of the set of FILEs , that is if a file is very small (i.e. 2140 bytes) the output of "du" is (in my case) 4KB because that's the size of the cluster

                              – mfloris
                              Jun 20 '16 at 6:45





                              I don't think this is right. What du does is Summarize disk usage of the set of FILEs , that is if a file is very small (i.e. 2140 bytes) the output of "du" is (in my case) 4KB because that's the size of the cluster

                              – mfloris
                              Jun 20 '16 at 6:45













                              @mfloris Use --apparent-size then.

                              – Maxim Egorushkin
                              Jun 20 '16 at 9:26





                              @mfloris Use --apparent-size then.

                              – Maxim Egorushkin
                              Jun 20 '16 at 9:26













                              I like du -hs * to see the size of all the files, and directories in the current directory.

                              – Jordan Stewart
                              Jan 20 '17 at 1:08





                              I like du -hs * to see the size of all the files, and directories in the current directory.

                              – Jordan Stewart
                              Jan 20 '17 at 1:08











                              47














                              Use ls -s to list file size, or if you prefer ls -sh for human readable sizes.



                              For directories use du, and again, du -h for human readable sizes.






                              share|improve this answer





















                              • 4





                                A tip is to use; 'du -sh *' to list all the directory sizes. :)

                                – Entalpi
                                Feb 28 '17 at 9:12
















                              47














                              Use ls -s to list file size, or if you prefer ls -sh for human readable sizes.



                              For directories use du, and again, du -h for human readable sizes.






                              share|improve this answer





















                              • 4





                                A tip is to use; 'du -sh *' to list all the directory sizes. :)

                                – Entalpi
                                Feb 28 '17 at 9:12














                              47












                              47








                              47







                              Use ls -s to list file size, or if you prefer ls -sh for human readable sizes.



                              For directories use du, and again, du -h for human readable sizes.






                              share|improve this answer















                              Use ls -s to list file size, or if you prefer ls -sh for human readable sizes.



                              For directories use du, and again, du -h for human readable sizes.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Aug 30 '12 at 13:31

























                              answered Jul 30 '12 at 11:46









                              ThorThor

                              30.2k67894




                              30.2k67894








                              • 4





                                A tip is to use; 'du -sh *' to list all the directory sizes. :)

                                – Entalpi
                                Feb 28 '17 at 9:12














                              • 4





                                A tip is to use; 'du -sh *' to list all the directory sizes. :)

                                – Entalpi
                                Feb 28 '17 at 9:12








                              4




                              4





                              A tip is to use; 'du -sh *' to list all the directory sizes. :)

                              – Entalpi
                              Feb 28 '17 at 9:12





                              A tip is to use; 'du -sh *' to list all the directory sizes. :)

                              – Entalpi
                              Feb 28 '17 at 9:12











                              19














                              You can use:



                              ls -lh



                              Using this command you'll see the apparent space of the directory and true space of the files and in details the names of the files displayed, besides the size and creation date of each.






                              share|improve this answer


























                              • ls -l will give u file size including the metadata? as it seems to be slightly 4kb bigger for one of file that i tried with

                                – Jun711
                                Sep 13 '18 at 20:58
















                              19














                              You can use:



                              ls -lh



                              Using this command you'll see the apparent space of the directory and true space of the files and in details the names of the files displayed, besides the size and creation date of each.






                              share|improve this answer


























                              • ls -l will give u file size including the metadata? as it seems to be slightly 4kb bigger for one of file that i tried with

                                – Jun711
                                Sep 13 '18 at 20:58














                              19












                              19








                              19







                              You can use:



                              ls -lh



                              Using this command you'll see the apparent space of the directory and true space of the files and in details the names of the files displayed, besides the size and creation date of each.






                              share|improve this answer















                              You can use:



                              ls -lh



                              Using this command you'll see the apparent space of the directory and true space of the files and in details the names of the files displayed, besides the size and creation date of each.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jun 14 '18 at 13:14









                              rimalonfire

                              177217




                              177217










                              answered Feb 16 '16 at 17:58









                              Yenier TorresYenier Torres

                              34638




                              34638













                              • ls -l will give u file size including the metadata? as it seems to be slightly 4kb bigger for one of file that i tried with

                                – Jun711
                                Sep 13 '18 at 20:58



















                              • ls -l will give u file size including the metadata? as it seems to be slightly 4kb bigger for one of file that i tried with

                                – Jun711
                                Sep 13 '18 at 20:58

















                              ls -l will give u file size including the metadata? as it seems to be slightly 4kb bigger for one of file that i tried with

                              – Jun711
                              Sep 13 '18 at 20:58





                              ls -l will give u file size including the metadata? as it seems to be slightly 4kb bigger for one of file that i tried with

                              – Jun711
                              Sep 13 '18 at 20:58











                              9














                              ls -l --block-size=M will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB.



                              If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead.



                              If you don't want the M suffix attached to the file size, you can use something like --block-size=1M. Thanks Stéphane Chazelas for suggesting this.



                              This is described in the man page for ls; man ls and search for SIZE. It allows for units other than MB/MiB as well, and from the looks of it (I didn't try that) arbitrary block sizes as well (so you could see the file size as number of 412-byte blocks, if you want to).



                              Note that the --block-size parameter is a GNU extension on top of the Open Group's ls, so this may not work if you don't have a GNU userland (which most Linux installations do). The ls from GNU coreutils 8.5 does support --block-size as described above.






                              share|improve this answer




























                                9














                                ls -l --block-size=M will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB.



                                If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead.



                                If you don't want the M suffix attached to the file size, you can use something like --block-size=1M. Thanks Stéphane Chazelas for suggesting this.



                                This is described in the man page for ls; man ls and search for SIZE. It allows for units other than MB/MiB as well, and from the looks of it (I didn't try that) arbitrary block sizes as well (so you could see the file size as number of 412-byte blocks, if you want to).



                                Note that the --block-size parameter is a GNU extension on top of the Open Group's ls, so this may not work if you don't have a GNU userland (which most Linux installations do). The ls from GNU coreutils 8.5 does support --block-size as described above.






                                share|improve this answer


























                                  9












                                  9








                                  9







                                  ls -l --block-size=M will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB.



                                  If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead.



                                  If you don't want the M suffix attached to the file size, you can use something like --block-size=1M. Thanks Stéphane Chazelas for suggesting this.



                                  This is described in the man page for ls; man ls and search for SIZE. It allows for units other than MB/MiB as well, and from the looks of it (I didn't try that) arbitrary block sizes as well (so you could see the file size as number of 412-byte blocks, if you want to).



                                  Note that the --block-size parameter is a GNU extension on top of the Open Group's ls, so this may not work if you don't have a GNU userland (which most Linux installations do). The ls from GNU coreutils 8.5 does support --block-size as described above.






                                  share|improve this answer













                                  ls -l --block-size=M will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB.



                                  If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead.



                                  If you don't want the M suffix attached to the file size, you can use something like --block-size=1M. Thanks Stéphane Chazelas for suggesting this.



                                  This is described in the man page for ls; man ls and search for SIZE. It allows for units other than MB/MiB as well, and from the looks of it (I didn't try that) arbitrary block sizes as well (so you could see the file size as number of 412-byte blocks, if you want to).



                                  Note that the --block-size parameter is a GNU extension on top of the Open Group's ls, so this may not work if you don't have a GNU userland (which most Linux installations do). The ls from GNU coreutils 8.5 does support --block-size as described above.







                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Jul 15 '15 at 18:58









                                  AdiAdi

                                  1,3291120




                                  1,3291120























                                      8














                                      File Size in MB



                                      ls -l --b=M  filename | cut -d " " -f5


                                      File Size in GB



                                      ls -l --b=G  filename | cut -d " " -f5





                                      share|improve this answer






























                                        8














                                        File Size in MB



                                        ls -l --b=M  filename | cut -d " " -f5


                                        File Size in GB



                                        ls -l --b=G  filename | cut -d " " -f5





                                        share|improve this answer




























                                          8












                                          8








                                          8







                                          File Size in MB



                                          ls -l --b=M  filename | cut -d " " -f5


                                          File Size in GB



                                          ls -l --b=G  filename | cut -d " " -f5





                                          share|improve this answer















                                          File Size in MB



                                          ls -l --b=M  filename | cut -d " " -f5


                                          File Size in GB



                                          ls -l --b=G  filename | cut -d " " -f5






                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited Nov 29 '17 at 9:24









                                          Rishabh Agrahari

                                          8941917




                                          8941917










                                          answered Sep 16 '15 at 7:22









                                          RavichandraRavichandra

                                          78111321




                                          78111321























                                              6














                                              There is also a great ncdu utility - it can show directory size with detailed info about subfolders and files.



                                              Installation



                                              Ubuntu:



                                              $ sudo apt-get install ncdu


                                              Usage



                                              Just type ncdu [path] in the command line. After a few seconds for analyzing the path, you will see something like this:



                                              $ ncdu 1.11 ~ Use the arrow keys to navigate, press ? for help
                                              --- / ---------------------------------------------------------
                                              . 96,1 GiB [##########] /home
                                              . 17,7 GiB [# ] /usr
                                              . 4,5 GiB [ ] /var
                                              1,1 GiB [ ] /lib
                                              732,1 MiB [ ] /opt
                                              . 275,6 MiB [ ] /boot
                                              198,0 MiB [ ] /storage
                                              . 153,5 MiB [ ] /run
                                              . 16,6 MiB [ ] /etc
                                              13,5 MiB [ ] /bin
                                              11,3 MiB [ ] /sbin
                                              . 8,8 MiB [ ] /tmp
                                              . 2,2 MiB [ ] /dev
                                              ! 16,0 KiB [ ] /lost+found
                                              8,0 KiB [ ] /media
                                              8,0 KiB [ ] /snap
                                              4,0 KiB [ ] /lib64
                                              e 4,0 KiB [ ] /srv
                                              ! 4,0 KiB [ ] /root
                                              e 4,0 KiB [ ] /mnt
                                              e 4,0 KiB [ ] /cdrom
                                              . 0,0 B [ ] /proc
                                              . 0,0 B [ ] /sys
                                              @ 0,0 B [ ] initrd.img.old
                                              @ 0,0 B [ ] initrd.img
                                              @ 0,0 B [ ] vmlinuz.old
                                              @ 0,0 B [ ] vmlinuz


                                              Delete the currently highlighted element with d, exit with CTRL + c






                                              share|improve this answer






























                                                6














                                                There is also a great ncdu utility - it can show directory size with detailed info about subfolders and files.



                                                Installation



                                                Ubuntu:



                                                $ sudo apt-get install ncdu


                                                Usage



                                                Just type ncdu [path] in the command line. After a few seconds for analyzing the path, you will see something like this:



                                                $ ncdu 1.11 ~ Use the arrow keys to navigate, press ? for help
                                                --- / ---------------------------------------------------------
                                                . 96,1 GiB [##########] /home
                                                . 17,7 GiB [# ] /usr
                                                . 4,5 GiB [ ] /var
                                                1,1 GiB [ ] /lib
                                                732,1 MiB [ ] /opt
                                                . 275,6 MiB [ ] /boot
                                                198,0 MiB [ ] /storage
                                                . 153,5 MiB [ ] /run
                                                . 16,6 MiB [ ] /etc
                                                13,5 MiB [ ] /bin
                                                11,3 MiB [ ] /sbin
                                                . 8,8 MiB [ ] /tmp
                                                . 2,2 MiB [ ] /dev
                                                ! 16,0 KiB [ ] /lost+found
                                                8,0 KiB [ ] /media
                                                8,0 KiB [ ] /snap
                                                4,0 KiB [ ] /lib64
                                                e 4,0 KiB [ ] /srv
                                                ! 4,0 KiB [ ] /root
                                                e 4,0 KiB [ ] /mnt
                                                e 4,0 KiB [ ] /cdrom
                                                . 0,0 B [ ] /proc
                                                . 0,0 B [ ] /sys
                                                @ 0,0 B [ ] initrd.img.old
                                                @ 0,0 B [ ] initrd.img
                                                @ 0,0 B [ ] vmlinuz.old
                                                @ 0,0 B [ ] vmlinuz


                                                Delete the currently highlighted element with d, exit with CTRL + c






                                                share|improve this answer




























                                                  6












                                                  6








                                                  6







                                                  There is also a great ncdu utility - it can show directory size with detailed info about subfolders and files.



                                                  Installation



                                                  Ubuntu:



                                                  $ sudo apt-get install ncdu


                                                  Usage



                                                  Just type ncdu [path] in the command line. After a few seconds for analyzing the path, you will see something like this:



                                                  $ ncdu 1.11 ~ Use the arrow keys to navigate, press ? for help
                                                  --- / ---------------------------------------------------------
                                                  . 96,1 GiB [##########] /home
                                                  . 17,7 GiB [# ] /usr
                                                  . 4,5 GiB [ ] /var
                                                  1,1 GiB [ ] /lib
                                                  732,1 MiB [ ] /opt
                                                  . 275,6 MiB [ ] /boot
                                                  198,0 MiB [ ] /storage
                                                  . 153,5 MiB [ ] /run
                                                  . 16,6 MiB [ ] /etc
                                                  13,5 MiB [ ] /bin
                                                  11,3 MiB [ ] /sbin
                                                  . 8,8 MiB [ ] /tmp
                                                  . 2,2 MiB [ ] /dev
                                                  ! 16,0 KiB [ ] /lost+found
                                                  8,0 KiB [ ] /media
                                                  8,0 KiB [ ] /snap
                                                  4,0 KiB [ ] /lib64
                                                  e 4,0 KiB [ ] /srv
                                                  ! 4,0 KiB [ ] /root
                                                  e 4,0 KiB [ ] /mnt
                                                  e 4,0 KiB [ ] /cdrom
                                                  . 0,0 B [ ] /proc
                                                  . 0,0 B [ ] /sys
                                                  @ 0,0 B [ ] initrd.img.old
                                                  @ 0,0 B [ ] initrd.img
                                                  @ 0,0 B [ ] vmlinuz.old
                                                  @ 0,0 B [ ] vmlinuz


                                                  Delete the currently highlighted element with d, exit with CTRL + c






                                                  share|improve this answer















                                                  There is also a great ncdu utility - it can show directory size with detailed info about subfolders and files.



                                                  Installation



                                                  Ubuntu:



                                                  $ sudo apt-get install ncdu


                                                  Usage



                                                  Just type ncdu [path] in the command line. After a few seconds for analyzing the path, you will see something like this:



                                                  $ ncdu 1.11 ~ Use the arrow keys to navigate, press ? for help
                                                  --- / ---------------------------------------------------------
                                                  . 96,1 GiB [##########] /home
                                                  . 17,7 GiB [# ] /usr
                                                  . 4,5 GiB [ ] /var
                                                  1,1 GiB [ ] /lib
                                                  732,1 MiB [ ] /opt
                                                  . 275,6 MiB [ ] /boot
                                                  198,0 MiB [ ] /storage
                                                  . 153,5 MiB [ ] /run
                                                  . 16,6 MiB [ ] /etc
                                                  13,5 MiB [ ] /bin
                                                  11,3 MiB [ ] /sbin
                                                  . 8,8 MiB [ ] /tmp
                                                  . 2,2 MiB [ ] /dev
                                                  ! 16,0 KiB [ ] /lost+found
                                                  8,0 KiB [ ] /media
                                                  8,0 KiB [ ] /snap
                                                  4,0 KiB [ ] /lib64
                                                  e 4,0 KiB [ ] /srv
                                                  ! 4,0 KiB [ ] /root
                                                  e 4,0 KiB [ ] /mnt
                                                  e 4,0 KiB [ ] /cdrom
                                                  . 0,0 B [ ] /proc
                                                  . 0,0 B [ ] /sys
                                                  @ 0,0 B [ ] initrd.img.old
                                                  @ 0,0 B [ ] initrd.img
                                                  @ 0,0 B [ ] vmlinuz.old
                                                  @ 0,0 B [ ] vmlinuz


                                                  Delete the currently highlighted element with d, exit with CTRL + c







                                                  share|improve this answer














                                                  share|improve this answer



                                                  share|improve this answer








                                                  edited Aug 30 '18 at 9:00









                                                  Martin Thoma

                                                  41.2k54295516




                                                  41.2k54295516










                                                  answered Sep 14 '15 at 10:12









                                                  avtomatonavtomaton

                                                  2,9972234




                                                  2,9972234























                                                      5














                                                      I do the following all the time:



                                                      $ du -sh backup-lr-May-02-2017-1493723588.tar.gz


                                                      NB:



                                                      -s, --summarize
                                                      display only a total for each argument
                                                      -h, --human-readable
                                                      print sizes in human readable format (e.g., 1K 234M 2G)





                                                      share|improve this answer




























                                                        5














                                                        I do the following all the time:



                                                        $ du -sh backup-lr-May-02-2017-1493723588.tar.gz


                                                        NB:



                                                        -s, --summarize
                                                        display only a total for each argument
                                                        -h, --human-readable
                                                        print sizes in human readable format (e.g., 1K 234M 2G)





                                                        share|improve this answer


























                                                          5












                                                          5








                                                          5







                                                          I do the following all the time:



                                                          $ du -sh backup-lr-May-02-2017-1493723588.tar.gz


                                                          NB:



                                                          -s, --summarize
                                                          display only a total for each argument
                                                          -h, --human-readable
                                                          print sizes in human readable format (e.g., 1K 234M 2G)





                                                          share|improve this answer













                                                          I do the following all the time:



                                                          $ du -sh backup-lr-May-02-2017-1493723588.tar.gz


                                                          NB:



                                                          -s, --summarize
                                                          display only a total for each argument
                                                          -h, --human-readable
                                                          print sizes in human readable format (e.g., 1K 234M 2G)






                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered May 2 '17 at 11:39









                                                          Fokwa BestFokwa Best

                                                          1,05521532




                                                          1,05521532























                                                              5














                                                              You can use below command to get list of files in easily human readable format.




                                                              ls -lrtsh







                                                              share|improve this answer




























                                                                5














                                                                You can use below command to get list of files in easily human readable format.




                                                                ls -lrtsh







                                                                share|improve this answer


























                                                                  5












                                                                  5








                                                                  5







                                                                  You can use below command to get list of files in easily human readable format.




                                                                  ls -lrtsh







                                                                  share|improve this answer













                                                                  You can use below command to get list of files in easily human readable format.




                                                                  ls -lrtsh








                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Dec 20 '17 at 2:32









                                                                  AmitAmit

                                                                  23143




                                                                  23143























                                                                      2














                                                                      You have to differenciate between file size and disk usage. The main difference between the two comes from the fact that files are "cut into pieces" and stored in blocks.



                                                                      Modern block size is 4KiB, so files will use disk space multiple of 4KiB, regardless of how small they are.



                                                                      If you use the command stat you can see both figures side by side.



                                                                      stat file.c


                                                                      If you want a more compact view for a directory, you can use ls -ls, which will give you usage in 1KiB units.



                                                                      ls -ls dir


                                                                      Also du will give you real disk usage, in 1KiB units, or dutree with the -u flag.



                                                                      Example: usage of a 1 byte file



                                                                      $ echo "" > file.c

                                                                      $ ls -l file.c
                                                                      -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                                                                      $ ls -ls file.c
                                                                      4 -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                                                                      $ du file.c
                                                                      4 file.c

                                                                      $ dutree file.c
                                                                      [ file.c 1 B ]

                                                                      $ dutree -u file.c
                                                                      [ file.c 4.00 KiB ]

                                                                      $ stat file.c
                                                                      File: file.c
                                                                      Size: 1 Blocks: 8 IO Block: 4096 regular file
                                                                      Device: 2fh/47d Inode: 2185244 Links: 1
                                                                      Access: (0644/-rw-r--r--) Uid: ( 1000/ nacho) Gid: ( 1000/ nacho)
                                                                      Access: 2018-04-30 20:41:58.002124411 +0200
                                                                      Modify: 2018-04-30 20:42:24.835458383 +0200
                                                                      Change: 2018-04-30 20:42:24.835458383 +0200
                                                                      Birth: -


                                                                      In addition, in modern filesystems we can have snapshots, sparse files (files with holes in them) that further complicate the situation.



                                                                      You can see more details in this article: understanding file size in Linux






                                                                      share|improve this answer




























                                                                        2














                                                                        You have to differenciate between file size and disk usage. The main difference between the two comes from the fact that files are "cut into pieces" and stored in blocks.



                                                                        Modern block size is 4KiB, so files will use disk space multiple of 4KiB, regardless of how small they are.



                                                                        If you use the command stat you can see both figures side by side.



                                                                        stat file.c


                                                                        If you want a more compact view for a directory, you can use ls -ls, which will give you usage in 1KiB units.



                                                                        ls -ls dir


                                                                        Also du will give you real disk usage, in 1KiB units, or dutree with the -u flag.



                                                                        Example: usage of a 1 byte file



                                                                        $ echo "" > file.c

                                                                        $ ls -l file.c
                                                                        -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                                                                        $ ls -ls file.c
                                                                        4 -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                                                                        $ du file.c
                                                                        4 file.c

                                                                        $ dutree file.c
                                                                        [ file.c 1 B ]

                                                                        $ dutree -u file.c
                                                                        [ file.c 4.00 KiB ]

                                                                        $ stat file.c
                                                                        File: file.c
                                                                        Size: 1 Blocks: 8 IO Block: 4096 regular file
                                                                        Device: 2fh/47d Inode: 2185244 Links: 1
                                                                        Access: (0644/-rw-r--r--) Uid: ( 1000/ nacho) Gid: ( 1000/ nacho)
                                                                        Access: 2018-04-30 20:41:58.002124411 +0200
                                                                        Modify: 2018-04-30 20:42:24.835458383 +0200
                                                                        Change: 2018-04-30 20:42:24.835458383 +0200
                                                                        Birth: -


                                                                        In addition, in modern filesystems we can have snapshots, sparse files (files with holes in them) that further complicate the situation.



                                                                        You can see more details in this article: understanding file size in Linux






                                                                        share|improve this answer


























                                                                          2












                                                                          2








                                                                          2







                                                                          You have to differenciate between file size and disk usage. The main difference between the two comes from the fact that files are "cut into pieces" and stored in blocks.



                                                                          Modern block size is 4KiB, so files will use disk space multiple of 4KiB, regardless of how small they are.



                                                                          If you use the command stat you can see both figures side by side.



                                                                          stat file.c


                                                                          If you want a more compact view for a directory, you can use ls -ls, which will give you usage in 1KiB units.



                                                                          ls -ls dir


                                                                          Also du will give you real disk usage, in 1KiB units, or dutree with the -u flag.



                                                                          Example: usage of a 1 byte file



                                                                          $ echo "" > file.c

                                                                          $ ls -l file.c
                                                                          -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                                                                          $ ls -ls file.c
                                                                          4 -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                                                                          $ du file.c
                                                                          4 file.c

                                                                          $ dutree file.c
                                                                          [ file.c 1 B ]

                                                                          $ dutree -u file.c
                                                                          [ file.c 4.00 KiB ]

                                                                          $ stat file.c
                                                                          File: file.c
                                                                          Size: 1 Blocks: 8 IO Block: 4096 regular file
                                                                          Device: 2fh/47d Inode: 2185244 Links: 1
                                                                          Access: (0644/-rw-r--r--) Uid: ( 1000/ nacho) Gid: ( 1000/ nacho)
                                                                          Access: 2018-04-30 20:41:58.002124411 +0200
                                                                          Modify: 2018-04-30 20:42:24.835458383 +0200
                                                                          Change: 2018-04-30 20:42:24.835458383 +0200
                                                                          Birth: -


                                                                          In addition, in modern filesystems we can have snapshots, sparse files (files with holes in them) that further complicate the situation.



                                                                          You can see more details in this article: understanding file size in Linux






                                                                          share|improve this answer













                                                                          You have to differenciate between file size and disk usage. The main difference between the two comes from the fact that files are "cut into pieces" and stored in blocks.



                                                                          Modern block size is 4KiB, so files will use disk space multiple of 4KiB, regardless of how small they are.



                                                                          If you use the command stat you can see both figures side by side.



                                                                          stat file.c


                                                                          If you want a more compact view for a directory, you can use ls -ls, which will give you usage in 1KiB units.



                                                                          ls -ls dir


                                                                          Also du will give you real disk usage, in 1KiB units, or dutree with the -u flag.



                                                                          Example: usage of a 1 byte file



                                                                          $ echo "" > file.c

                                                                          $ ls -l file.c
                                                                          -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                                                                          $ ls -ls file.c
                                                                          4 -rw-r--r-- 1 nacho nacho 1 Apr 30 20:42 file.c

                                                                          $ du file.c
                                                                          4 file.c

                                                                          $ dutree file.c
                                                                          [ file.c 1 B ]

                                                                          $ dutree -u file.c
                                                                          [ file.c 4.00 KiB ]

                                                                          $ stat file.c
                                                                          File: file.c
                                                                          Size: 1 Blocks: 8 IO Block: 4096 regular file
                                                                          Device: 2fh/47d Inode: 2185244 Links: 1
                                                                          Access: (0644/-rw-r--r--) Uid: ( 1000/ nacho) Gid: ( 1000/ nacho)
                                                                          Access: 2018-04-30 20:41:58.002124411 +0200
                                                                          Modify: 2018-04-30 20:42:24.835458383 +0200
                                                                          Change: 2018-04-30 20:42:24.835458383 +0200
                                                                          Birth: -


                                                                          In addition, in modern filesystems we can have snapshots, sparse files (files with holes in them) that further complicate the situation.



                                                                          You can see more details in this article: understanding file size in Linux







                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered May 3 '18 at 9:27









                                                                          nachoparkernachoparker

                                                                          868710




                                                                          868710























                                                                              2














                                                                              I'm a Ubuntu 16.04 user myself and I find that the ll command is by far the easiest way to see a directory's contents. I've noticed that not all Linux distributions support this command, but there's probably a workaround/install for each distro out there.



                                                                              Example:



                                                                              user@user-XPS-15-9560:/$ ll
                                                                              total 188
                                                                              drwxr-xr-x 27 root root 4096 Jan 26 09:13 ./
                                                                              drwxr-xr-x 27 root root 4096 Jan 26 09:13 ../
                                                                              drwxr-xr-x 2 root root 4096 Jan 22 15:13 bin/
                                                                              drwxr-xr-x 4 root root 12288 Jan 29 11:35 boot/
                                                                              drwxr-xr-x 2 root root 4096 Sep 3 18:14 cdrom/
                                                                              drwxr-xr-x 20 root root 4440 Feb 5 08:43 dev/
                                                                              drwxr-xr-x 153 root root 12288 Feb 2 15:17 etc/
                                                                              drwxr-xr-x 4 root root 4096 Sep 3 18:15 home/
                                                                              ...


                                                                              The biggest advantage for me is that it's quick and really intuitive to use.



                                                                              UPDATE: what I didn't know was that on Ubuntu it's a pre-configured alias. You can easily set it yourself by executing alias ll="ls -la" on the command line, or by adding this entry in your .bashrc config file:



                                                                              sudo nano ~/.bashrc
                                                                              ...add line described above and save file by pressing Ctrl+X and Y...
                                                                              source ~/.bashrc





                                                                              share|improve this answer






























                                                                                2














                                                                                I'm a Ubuntu 16.04 user myself and I find that the ll command is by far the easiest way to see a directory's contents. I've noticed that not all Linux distributions support this command, but there's probably a workaround/install for each distro out there.



                                                                                Example:



                                                                                user@user-XPS-15-9560:/$ ll
                                                                                total 188
                                                                                drwxr-xr-x 27 root root 4096 Jan 26 09:13 ./
                                                                                drwxr-xr-x 27 root root 4096 Jan 26 09:13 ../
                                                                                drwxr-xr-x 2 root root 4096 Jan 22 15:13 bin/
                                                                                drwxr-xr-x 4 root root 12288 Jan 29 11:35 boot/
                                                                                drwxr-xr-x 2 root root 4096 Sep 3 18:14 cdrom/
                                                                                drwxr-xr-x 20 root root 4440 Feb 5 08:43 dev/
                                                                                drwxr-xr-x 153 root root 12288 Feb 2 15:17 etc/
                                                                                drwxr-xr-x 4 root root 4096 Sep 3 18:15 home/
                                                                                ...


                                                                                The biggest advantage for me is that it's quick and really intuitive to use.



                                                                                UPDATE: what I didn't know was that on Ubuntu it's a pre-configured alias. You can easily set it yourself by executing alias ll="ls -la" on the command line, or by adding this entry in your .bashrc config file:



                                                                                sudo nano ~/.bashrc
                                                                                ...add line described above and save file by pressing Ctrl+X and Y...
                                                                                source ~/.bashrc





                                                                                share|improve this answer




























                                                                                  2












                                                                                  2








                                                                                  2







                                                                                  I'm a Ubuntu 16.04 user myself and I find that the ll command is by far the easiest way to see a directory's contents. I've noticed that not all Linux distributions support this command, but there's probably a workaround/install for each distro out there.



                                                                                  Example:



                                                                                  user@user-XPS-15-9560:/$ ll
                                                                                  total 188
                                                                                  drwxr-xr-x 27 root root 4096 Jan 26 09:13 ./
                                                                                  drwxr-xr-x 27 root root 4096 Jan 26 09:13 ../
                                                                                  drwxr-xr-x 2 root root 4096 Jan 22 15:13 bin/
                                                                                  drwxr-xr-x 4 root root 12288 Jan 29 11:35 boot/
                                                                                  drwxr-xr-x 2 root root 4096 Sep 3 18:14 cdrom/
                                                                                  drwxr-xr-x 20 root root 4440 Feb 5 08:43 dev/
                                                                                  drwxr-xr-x 153 root root 12288 Feb 2 15:17 etc/
                                                                                  drwxr-xr-x 4 root root 4096 Sep 3 18:15 home/
                                                                                  ...


                                                                                  The biggest advantage for me is that it's quick and really intuitive to use.



                                                                                  UPDATE: what I didn't know was that on Ubuntu it's a pre-configured alias. You can easily set it yourself by executing alias ll="ls -la" on the command line, or by adding this entry in your .bashrc config file:



                                                                                  sudo nano ~/.bashrc
                                                                                  ...add line described above and save file by pressing Ctrl+X and Y...
                                                                                  source ~/.bashrc





                                                                                  share|improve this answer















                                                                                  I'm a Ubuntu 16.04 user myself and I find that the ll command is by far the easiest way to see a directory's contents. I've noticed that not all Linux distributions support this command, but there's probably a workaround/install for each distro out there.



                                                                                  Example:



                                                                                  user@user-XPS-15-9560:/$ ll
                                                                                  total 188
                                                                                  drwxr-xr-x 27 root root 4096 Jan 26 09:13 ./
                                                                                  drwxr-xr-x 27 root root 4096 Jan 26 09:13 ../
                                                                                  drwxr-xr-x 2 root root 4096 Jan 22 15:13 bin/
                                                                                  drwxr-xr-x 4 root root 12288 Jan 29 11:35 boot/
                                                                                  drwxr-xr-x 2 root root 4096 Sep 3 18:14 cdrom/
                                                                                  drwxr-xr-x 20 root root 4440 Feb 5 08:43 dev/
                                                                                  drwxr-xr-x 153 root root 12288 Feb 2 15:17 etc/
                                                                                  drwxr-xr-x 4 root root 4096 Sep 3 18:15 home/
                                                                                  ...


                                                                                  The biggest advantage for me is that it's quick and really intuitive to use.



                                                                                  UPDATE: what I didn't know was that on Ubuntu it's a pre-configured alias. You can easily set it yourself by executing alias ll="ls -la" on the command line, or by adding this entry in your .bashrc config file:



                                                                                  sudo nano ~/.bashrc
                                                                                  ...add line described above and save file by pressing Ctrl+X and Y...
                                                                                  source ~/.bashrc






                                                                                  share|improve this answer














                                                                                  share|improve this answer



                                                                                  share|improve this answer








                                                                                  edited May 8 '18 at 8:58

























                                                                                  answered Feb 5 '18 at 11:46









                                                                                  MatteusMatteus

                                                                                  578




                                                                                  578























                                                                                      1














                                                                                      you can use ls -sh in linux you can do sort also
                                                                                      you need to go to dir where you want to check the size of files






                                                                                      share|improve this answer




























                                                                                        1














                                                                                        you can use ls -sh in linux you can do sort also
                                                                                        you need to go to dir where you want to check the size of files






                                                                                        share|improve this answer


























                                                                                          1












                                                                                          1








                                                                                          1







                                                                                          you can use ls -sh in linux you can do sort also
                                                                                          you need to go to dir where you want to check the size of files






                                                                                          share|improve this answer













                                                                                          you can use ls -sh in linux you can do sort also
                                                                                          you need to go to dir where you want to check the size of files







                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered Mar 17 '17 at 16:32









                                                                                          Prem SPrem S

                                                                                          18218




                                                                                          18218























                                                                                              0














                                                                                              If you are using it in a script, use stat.



                                                                                              stat -c %s filename


                                                                                              That will give you size in bytes. See man stat for more output format options.






                                                                                              share|improve this answer




























                                                                                                0














                                                                                                If you are using it in a script, use stat.



                                                                                                stat -c %s filename


                                                                                                That will give you size in bytes. See man stat for more output format options.






                                                                                                share|improve this answer


























                                                                                                  0












                                                                                                  0








                                                                                                  0







                                                                                                  If you are using it in a script, use stat.



                                                                                                  stat -c %s filename


                                                                                                  That will give you size in bytes. See man stat for more output format options.






                                                                                                  share|improve this answer













                                                                                                  If you are using it in a script, use stat.



                                                                                                  stat -c %s filename


                                                                                                  That will give you size in bytes. See man stat for more output format options.







                                                                                                  share|improve this answer












                                                                                                  share|improve this answer



                                                                                                  share|improve this answer










                                                                                                  answered Nov 20 '18 at 3:39









                                                                                                  Bruno BronoskyBruno Bronosky

                                                                                                  34k47781




                                                                                                  34k47781























                                                                                                      0














                                                                                                      go to specific directory then run below command



                                                                                                      # du -sh * 

                                                                                                      4.0K 1
                                                                                                      4.0K anadb.sh --> Shell file
                                                                                                      4.0K db.sh/ --> shell file
                                                                                                      24K backup4/ --> Directory
                                                                                                      8.0K backup6/ --> Directory
                                                                                                      1.9G backup.sql.gz --> sql file





                                                                                                      share|improve this answer






























                                                                                                        0














                                                                                                        go to specific directory then run below command



                                                                                                        # du -sh * 

                                                                                                        4.0K 1
                                                                                                        4.0K anadb.sh --> Shell file
                                                                                                        4.0K db.sh/ --> shell file
                                                                                                        24K backup4/ --> Directory
                                                                                                        8.0K backup6/ --> Directory
                                                                                                        1.9G backup.sql.gz --> sql file





                                                                                                        share|improve this answer




























                                                                                                          0












                                                                                                          0








                                                                                                          0







                                                                                                          go to specific directory then run below command



                                                                                                          # du -sh * 

                                                                                                          4.0K 1
                                                                                                          4.0K anadb.sh --> Shell file
                                                                                                          4.0K db.sh/ --> shell file
                                                                                                          24K backup4/ --> Directory
                                                                                                          8.0K backup6/ --> Directory
                                                                                                          1.9G backup.sql.gz --> sql file





                                                                                                          share|improve this answer















                                                                                                          go to specific directory then run below command



                                                                                                          # du -sh * 

                                                                                                          4.0K 1
                                                                                                          4.0K anadb.sh --> Shell file
                                                                                                          4.0K db.sh/ --> shell file
                                                                                                          24K backup4/ --> Directory
                                                                                                          8.0K backup6/ --> Directory
                                                                                                          1.9G backup.sql.gz --> sql file






                                                                                                          share|improve this answer














                                                                                                          share|improve this answer



                                                                                                          share|improve this answer








                                                                                                          edited Jan 7 at 7:28

























                                                                                                          answered Jan 7 at 7:23









                                                                                                          sachin_ursachin_ur

                                                                                                          312111




                                                                                                          312111






























                                                                                                              draft saved

                                                                                                              draft discarded




















































                                                                                                              Thanks for contributing an answer to Stack Overflow!


                                                                                                              • Please be sure to answer the question. Provide details and share your research!

                                                                                                              But avoid



                                                                                                              • Asking for help, clarification, or responding to other answers.

                                                                                                              • Making statements based on opinion; back them up with references or personal experience.


                                                                                                              To learn more, see our tips on writing great answers.




                                                                                                              draft saved


                                                                                                              draft discarded














                                                                                                              StackExchange.ready(
                                                                                                              function () {
                                                                                                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11720079%2fhow-can-i-see-the-size-of-files-and-directories-in-linux%23new-answer', 'question_page');
                                                                                                              }
                                                                                                              );

                                                                                                              Post as a guest















                                                                                                              Required, but never shown





















































                                                                                                              Required, but never shown














                                                                                                              Required, but never shown












                                                                                                              Required, but never shown







                                                                                                              Required, but never shown

































                                                                                                              Required, but never shown














                                                                                                              Required, but never shown












                                                                                                              Required, but never shown







                                                                                                              Required, but never shown







                                                                                                              Popular posts from this blog

                                                                                                              MongoDB - Not Authorized To Execute Command

                                                                                                              How to fix TextFormField cause rebuild widget in Flutter

                                                                                                              in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith