Skip to content

Linux & shell: View & compare files

9 Linux & shell commands: View & compare files. Click a command to see what each part does.

Index
9 items
Click a command to see what each part does.

View & compare files9

  • cat <file>Print a file

    What each part does

    1. catconcatenate: print one or more files to the screen
  • cat -n <file>Print with line numbers

    What each part does

    1. -n--number: number every output line
  • less <file>Read a long file page by page

    What each part does

    1. lessscroll a file: Space/b = page down/up, /text = search, n = next match, G = end, q = quit
  • head -n 20 <file>First lines of a file

    What each part does

    1. headstart of a file
    2. -n 20how many lines (default 10)
  • tail -n 50 <file>Last lines of a file

    What each part does

    1. tailend of a file
    2. -n 50how many lines (default 10); add -f to keep following
  • wc -l <file>Count lines, words, bytes

    What each part does

    1. wcword count
    2. -lcount lines only (-w words, -c bytes)
  • diff -u <old-file> <new-file>Compare two files

    What each part does

    1. diffshow differences (exit 0 = same, 1 = different)
    2. -uunified format: - removed lines, + added lines, 3 lines of context
  • file <file>What kind of file is this?

    What each part does

    1. filedetect the type: text, ELF binary, gzip, JSON…
  • stat <file>Size, permissions and timestamps of a file

    What each part does

    1. statdetailed metadata: size, inode, permissions, access/modify/change times

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…