File type, directory size, free space, disk usage, and tar in Linux


A few quick notes for people who want to know how to do simple things in *nix. This is for Windows users who are making the transition or find themselves dealing with *nix from time to time.

Use file FooBar to find out what kind of file FooBar is. This is helpful when you need to know what program is needed to open FooBar file.

To find out size of a directory, including the size of subdirectories, use du -ah.

To find file system disk usage, use df -h

Note on Solaris, based on my experience, -h won’t work. You will have to do -k, which to me is a pain.

Quick note on tar:
tar -cvf archive.tar FilesOrDirectoriesToBeArchived
tar -tvf archive.tar # List all files in archive.tar verbosely.
tar -xvf archive.tar # Extract all files from archive.tar with verbose output message.

To archive and compress in one shot, add z, which uses gzip/gunzip for compression/decompression:
tar -czvf archive.tar FilesOrDirectoriesToBeArchived
tar -tzvf archive.tar # List all files in archive.tar verbosely.
tar -xzvf archive.tar # Extract all files from archive.tar.


One response to “File type, directory size, free space, disk usage, and tar in Linux”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.