1. Using ‘du -sh’ command
Syntax
du -sh file/directory name
Example
- Find the size of the file.
[root@no1010211066225 git-dir]# du -sh calculate_files.py
4.0K calculate_files.py
- Find the size of the directory.
[root@mac git-dir]# du -sh someDocs
2.9M someDocs
- Find the size of all files in a dictionary.
[root@mac git-dir]# du -sh scripts/*
4.0K scripts/bastionhost_eips.json
8.0K scripts/create_bastion.rb
2. Using ‘stat’ command
Syntax
stat filename
Examples
[root@nmac git-dir]# stat workflow.py
File: ‘workflow.py’
Size: 43000 Blocks: 88 IO Block: 4096 regular file
Device: fd01h/64769d Inode: 1058286 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2020-09-23 08:33:54.299246431 +0000
Modify: 2020-09-03 05:42:45.113104679 +0000
Change: 2020-09-03 05:42:45.113104679 +0000
Birth: -
Note:- stat command doesn’t show the content size of the directory. Its sizes remain fixed. This is not the size of the contents of the directory.
3. Using ‘ls -l’ command
Syntax
ls -l filename
Examples
[root@mac git-dir]# ls -l workflow.py
-rwxr-xr-x. 1 root root 43000 Sep 3 05:42 workflow.py
Note:- In the above command’s output, 43000 is the size of the file in bytes.
[root@mac git-dir] ls -lh workflow.py
-rwxr-xr-x. 1 root root 42K Sep 3 05:42 workflow.py
Note:- In the above command’s output, 42k is the size of the file in Kilobytes. It’s a more friendly output.