Skip to content

Latest commit

 

History

History
322 lines (244 loc) · 3.67 KB

file.md

File metadata and controls

322 lines (244 loc) · 3.67 KB

File Command Cheatsheet

Installation Instructions

Windows

# Using Chocolatey
choco install file

# Using MSYS2
pacman -S file

Linux

# Debian/Ubuntu
sudo apt-get install file

# RHEL/CentOS
sudo yum install file

# Arch Linux
sudo pacman -S file

macOS

# Usually pre-installed, if not:
brew install file

Basic Usage

  1. Basic file identification:
file filename
  1. Don't follow symlinks:
file -P filename
  1. Show mime type:
file --mime-type filename

Multiple File Operations

  1. Process multiple files:
file file1 file2 file3
  1. Process entire directory:
file *
  1. Recursive file analysis:
file -R directory/

Output Formatting

  1. Brief mode:
file -b filename
  1. No filename in output:
file -b filename
  1. Detailed mime type:
file --mime filename

Special File Types

  1. Analyze compressed file:
file -z compressed.gz
  1. Look inside ZIP files:
file -z archive.zip
  1. Examine device files:
file -s /dev/sda1

Binary Analysis

  1. Show ELF details:
file -h binary
  1. Check for stripped binaries:
file binary | grep stripped
  1. Display architecture:
file binary | grep -o ".*bit"

Advanced Options

  1. Use specific magic file:
file -m /path/to/magic filename
  1. Show magic file compilation:
file -C -m filename
  1. Debug magic file compilation:
file --debug-magic filename

Network Operations

  1. Examine URLs:
file -L http://example.com/file
  1. Follow symbolic links:
file -L symlink

Special Analysis

  1. Preserve file times:
file -k filename
  1. Show file version info:
file --version
  1. Check magic file syntax:
file -c magic_file

Security Analysis

  1. Check for malformed files:
file --apple filename
  1. Analyze raw data:
file -r filename

Filesystem Analysis

  1. Examine filesystem type:
file -s /dev/sda
  1. Show partition info:
file -s /dev/sda1

Archive Analysis

  1. Look inside tar files:
file -z archive.tar.gz
  1. Examine ISO images:
file disk.iso

Character Encoding

  1. Check text encoding:
file -i textfile
  1. Show line endings:
file -k textfile | grep -o "text.*"

Output Control

  1. Separator string:
file -F ":" filename
  1. Custom output format:
file -f namefile

Special File Systems

  1. Analyze core dumps:
file core.dump
  1. Examine memory dumps:
file memory.dmp

Performance Options

  1. No pad option:
file -N filename
  1. Fast mode:
file -f -

Integration Features

  1. Generate machine-readable output:
file --print0 filename
  1. Print magic database:
file -m -

System Information

  1. Show supported filesystems:
file -v
  1. Display compilation options:
file -v | grep "compiled"

Advanced File Types

  1. Check for scripts:
file --keep-going script.sh
  1. Analyze symbolic links:
file -h symlink

Special Modes

  1. No buffering:
file --no-buffer filename
  1. Raw output mode:
file -r filename

Error Handling

  1. Continue after errors:
file --keep-going filename
  1. Show error details:
file --debug filename

Custom Magic

  1. Test magic patterns:
file -M magic_file filename
  1. Compile magic file:
file -C -m magic_file
  1. Check magic syntax:
file -c magic_file