Skip to main content

Command Palette

Search for a command to run...

Metadata and a shell program displaying metadata

Published
2 min read
Metadata and a shell program displaying metadata
G

I'm passionate about coding and enjoy working with embedded systems, app development, and compiler design.

Metadata of a File

A file's metadata contains important details about the file without storing its actual content. It provides information such as permissions, ownership, size, and modification time. Metadata helps the system organize, secure, and manage files efficiently.

Uses of Metadata

  • Helps in file organization by storing timestamps, size, and file type.

  • Maintains security by defining file ownership and access permissions.

  • Supports search operations by allowing filtering based on file attributes.

  • Aids in data recovery by storing creation and modification history.

Types of Metadata

  1. File System Metadata – Stores file permissions, ownership, timestamps, and size.

  2. Descriptive Metadata – Includes file name, title, and author (used in documents and media files).

  3. Structural Metadata – Defines relationships between multiple files (e.g., chapters in an eBook).

  4. Administrative Metadata – Stores management details like usage rights and storage policies.


About This Program

This Bash script retrieves metadata of a file provided as an argument. If no file is given, it prints "display does not exist”. Otherwise, it uses ls -l to get detailed file information, extracts specific metadata fields using cut, and then displays them.

How It Works:

  • Checks if an argument is passed ($# -eq 0), and if not, displays an error message.

  • Uses ls -l to list file details and stores them in a temporary file (t2).

  • Extracts file permissions, owner, modification date, and file name using cut.

  • Displays the extracted metadata.

#!/bin/bash
if [ $# -eq 0 ];
then
        echo "display does not exist"
else
        ls -l $1 > t2
        x=`cut -d ' ' -f 1,2,6,7,8,9 t2`
        echo $x
        echo "\n"
fi

Hope you learnt something new

Happy Coding…