Analyzing file metadata in the shell

Taking Stock

© Lead Image © Sebastian Duda,

© Lead Image © Sebastian Duda,

Article from Issue 233/2020

Armed with the right shell commands, you can quickly identify and evaluate file and directory metadata.

Imagine you have a directory with hundreds or even thousands of files (without uniform extensions) that you want to organize. Or maybe you want to know the last access date of a file for backup, forensics, or version management purposes.

Instead of tediously clicking your way through the files in a graphical file manager, a shell script with the test command can help identify filesystem objects as well as provide additional information about the files.

Determining File Type

The file command provides information about a file's contents (Figure 1). Because it tests for patterns in the content, file cannot be misled by file extensions (Figure 2).


Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Ask Klaus!

    Understanding and taming file timestamps.

  • Command Line: ls

    The ls command lists files at the command line and gives you many useful details about file properties. With or without colors, this command keeps you on top of your files.

  • Ncdu

    Ncdu adds some GUI-like features to the classic du command.

  • Perl: Desktop Searches

    On a big, busy Linux desktop, it is too easy for files to get lost. We’ll show you a Perl script that creates a MySQL database to find files in next to no time.

  • File Management

    We give you an overview of commands for moving, editing, compressing, and generally manipulating files.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95