SQLite is a public domain zero-configuration, transactional SQL database engine. Used by macOS, Firefox web browser, WIndows 10, Dropbox, Skype and many other client programs.
Syntax sqlite3 [OPTIONS] FILENAME [SQL_Command] Create a new database called demo64: sqlite3 demo64 Display help/syntax: sqlite3 --help Interactive mode: sqlite3 List the .dot commands available:
sqlite> .help Key FILENAME The name of an SQLite database. A new database is created if the file does not previously exist.
-ascii set output mode to 'ascii' -bail stop after hitting an error -batch force batch I/O -column set output mode to 'column' -cmd COMMAND run "COMMAND" before reading stdin -csv set output mode to 'csv' -echo print commands before execution -init FILENAME read/process named file -[no]header turn headers on or off -help show this message -html set output mode to HTML -interactive force interactive I/O -line set output mode to 'line' -list set output mode to 'list' -lookaside SIZE N use N entries of SZ bytes for lookaside memory -mmap N default mmap size set to N -newline SEP set output row separator. Default: '\n' -nullvalue TEXT set text string for NULL values. Default '' -pagecache SIZE N use N slots of SZ bytes each for page cache memory -scratch SIZE N use N slots of SZ bytes each for scratch memory -separator SEP set output column separator. Default: '|' -stats print memory stats before each finalize -version show SQLite version -vfs NAME use NAME as the default VFS
Examples
Run a select command against database demo64:
$ sqlite3 demo64.db "SELECT * FROM Sales;"
On macOS list the full download history from all applications:
$ sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineAgentName, LSQuarantineDataURLString, date(LSQuarantineTimeStamp + 978307200, "unixepoch") as downloadedDate from LSQuarantineEvent order by LSQuarantineTimeStamp' | sort | grep '|' --color
Delete the macOS download history from all applications:
$ sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
Then rebuild the DB to confirm full deletion (via zoharbabin.com):
$ sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'vacuum'
“Effective management always means asking the right question” ~ Robert Heller
Related macOS commands:
Command Line shell for SQLite - sqlite.org
SQL as understood by SQLite - sqlite.org