{
    "version": "https:\/\/jsonfeed.org\/version\/1.1",
    "title": "Blog — George Mishurovsky: posts tagged mac",
    "_rss_description": "A blog by George Mishurovsky — a senior software engineer with a medical degree. Drawing from both engineering and scientific thinking, he explores software, architecture, design, psychology, and product thinking.",
    "_rss_language": "en",
    "_itunes_email": "george@mishurovsky.com",
    "_itunes_categories_xml": "",
    "_itunes_image": "https:\/\/mishurovsky.com\/blog\/pictures\/userpic\/userpic-square@2x.jpg?1753619610",
    "_itunes_explicit": "no",
    "home_page_url": "https:\/\/mishurovsky.com\/blog\/?go=tags\/mac\/",
    "feed_url": "https:\/\/mishurovsky.com\/blog\/?go=tags%2Fmac%2Fjson%2F",
    "icon": "https:\/\/mishurovsky.com\/blog\/pictures\/userpic\/userpic@2x.jpg?1753619610",
    "authors": [
        {
            "name": "George Mishurovsky",
            "url": "https:\/\/mishurovsky.com\/blog\/",
            "avatar": "https:\/\/mishurovsky.com\/blog\/pictures\/userpic\/userpic@2x.jpg?1753619610"
        }
    ],
    "items": [
        {
            "id": "5",
            "url": "https:\/\/mishurovsky.com\/blog\/?go=all\/how-to-quickly-retrieve-past-terminal-commands\/",
            "title": "How to View Past Terminal Commands — from Simple to Robust",
            "content_html": "<p>Suppose you want to re-run some shell command you used ten days ago. It is a complex one; you do not remember exact flags and argument values, and it would take a long time to recall an exact text. What can you do?<\/p>\n<h2>1. The upwards arrow<\/h2>\n<p>Majority of devs working with command line knows it. Press “up” to see a previous command, press “down” for a next command, press “Ctrl+C” to drop whatever is in the prompt and start fresh.<\/p>\n<p>This approach works, but gets very tedious when you need to find a command you used last week or last month. Once more than ten or twenty commands have passed, scrolling through them becomes tedious.<\/p>\n<h2>2. Terminal history file<\/h2>\n<p>All the commands you enter into a terminal get stored in <span class=\"inline-code\">.bash_history<\/span> file (or <span class=\"inline-code\">.zsh_history<\/span> if you are on Mac) up to a certain limit. Thus, you can run:<\/p>\n<div class=\"e2-code-block\" data-language=\"shell\"><div class=\"e2-code-header\"><span class=\"e2-code-language\">Shell<\/span><button class=\"e2-code-copy\" type=\"button\" aria-label=\"Copy code to clipboard\" data-copy-text=\"Copy\" data-copied-text=\"Copied!\" data-failed-text=\"Failed\"><span class=\"e2-svgi\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 16 16\"><mask id=\"cutout\"><rect width=\"100%\" height=\"100%\" fill=\"white\"\/><rect x=\"1.75\" y=\"5.25\" width=\"9\" height=\"9\" stroke-width=\"1.33\" rx=\"1\" fill=\"black\" stroke=\"black\"\/><\/mask><rect x=\"5.25\" y=\"1.75\" width=\"9\" height=\"9\" rx=\"1\" stroke-width=\"1.33\" fill=\"none\" mask=\"url(#cutout)\"\/><rect x=\"1.75\" y=\"5.25\" width=\"9\" height=\"9\" rx=\"1\" stroke-width=\"1.33\" fill=\"none\"\/><\/svg>\r\n<\/span>Copy<\/button><\/div><pre><code class=\"hljs language-shell\">cat ~\/.bash_history # output all into the terminal\nless ~\/.bash_history # or use any text viewer\ntail -n 20 ~\/.bash_history # or observe only the most recent n lines\ncat ~\/.bash_history | grep whatever # to search for specific patterns<\/code><\/pre><\/div><p>This method gives you full access to your history file, and lets you search more flexibly.<\/p>\n<h2>3. <span class=\"inline-code\">history<\/span> command<\/h2>\n<p>Almost the same as using the history file directly: you get a list commands, but now it is <i>numbered<\/i>.<\/p>\n<div class=\"e2-code-block\" data-language=\"shell\"><div class=\"e2-code-header\"><span class=\"e2-code-language\">Shell<\/span><button class=\"e2-code-copy\" type=\"button\" aria-label=\"Copy code to clipboard\" data-copy-text=\"Copy\" data-copied-text=\"Copied!\" data-failed-text=\"Failed\"><span class=\"e2-svgi\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 16 16\"><mask id=\"cutout\"><rect width=\"100%\" height=\"100%\" fill=\"white\"\/><rect x=\"1.75\" y=\"5.25\" width=\"9\" height=\"9\" stroke-width=\"1.33\" rx=\"1\" fill=\"black\" stroke=\"black\"\/><\/mask><rect x=\"5.25\" y=\"1.75\" width=\"9\" height=\"9\" rx=\"1\" stroke-width=\"1.33\" fill=\"none\" mask=\"url(#cutout)\"\/><rect x=\"1.75\" y=\"5.25\" width=\"9\" height=\"9\" rx=\"1\" stroke-width=\"1.33\" fill=\"none\"\/><\/svg>\r\n<\/span>Copy<\/button><\/div><pre><code class=\"hljs language-shell\">history -20 # show the last 20 commands\nhistory -500 | grep ssh # search for a specific patter in a command\n!780 # execute command with order number 780<\/code><\/pre><\/div><p>But there is one important difference from direct usage of <span class=\"inline-code\">.bash_history<\/span>:<\/p>\n<ul>\n<li><span class=\"inline-code\">history<\/span> command uses the last <span class=\"inline-code\">HISTSIZE<\/span> history entries (default 1000)<\/li>\n<li><span class=\"inline-code\">.bash_history<\/span> file uses the last <span class=\"inline-code\">HISTFILESIZE<\/span> entries (default 2000)<br \/>\nSo, if your command was run a really long time ago, <span class=\"inline-code\">history<\/span> may not find it, but direct inspection of <span class=\"inline-code\">.bash_history<\/span> can do.<\/li>\n<\/ul>\n<h2>4. <span class=\"inline-code\">fc -l<\/span> command<\/h2>\n<p>This command behaves very similar to <span class=\"inline-code\">history<\/span>, with an additional ability to display ranges of command numbers::<\/p>\n<div class=\"e2-code-block\" data-language=\"shell\"><div class=\"e2-code-header\"><span class=\"e2-code-language\">Shell<\/span><button class=\"e2-code-copy\" type=\"button\" aria-label=\"Copy code to clipboard\" data-copy-text=\"Copy\" data-copied-text=\"Copied!\" data-failed-text=\"Failed\"><span class=\"e2-svgi\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 16 16\"><mask id=\"cutout\"><rect width=\"100%\" height=\"100%\" fill=\"white\"\/><rect x=\"1.75\" y=\"5.25\" width=\"9\" height=\"9\" stroke-width=\"1.33\" rx=\"1\" fill=\"black\" stroke=\"black\"\/><\/mask><rect x=\"5.25\" y=\"1.75\" width=\"9\" height=\"9\" rx=\"1\" stroke-width=\"1.33\" fill=\"none\" mask=\"url(#cutout)\"\/><rect x=\"1.75\" y=\"5.25\" width=\"9\" height=\"9\" rx=\"1\" stroke-width=\"1.33\" fill=\"none\"\/><\/svg>\r\n<\/span>Copy<\/button><\/div><pre><code class=\"hljs language-shell\">fc -l -20 # show the last 20 commands\nfc -l 100 150 # show commands 100 to 150<\/code><\/pre><\/div><h2>5. Reverse-i-search<\/h2>\n<p>This is the most powerful approach. Press “Ctrl+R” to enter reverse incremental search mode. Initially you get no output; start writing any part of a command you remember, e. g. <span class=\"inline-code\">ssh<\/span> or <span class=\"inline-code\">input.json<\/span> or <span class=\"inline-code\">-n 10<\/span> — and you will see the first full command entry with that match!<\/p>\n<p>From there, you can:<\/p>\n<ul>\n<li>Press “Enter” to execute the command immediately<\/li>\n<li>Use left\/right arrow keys to move within a command to edit it, then press “Enter” to execute<\/li>\n<li>Press “Ctrl+R” again to go to the next, older match<\/li>\n<li>Press “Ctrl+S” to go to the previous, newer match (see comment below)<\/li>\n<li>Press up-down arrows to view to nearby entries in history around the match<\/li>\n<li>Press “Ctrl+C” or “Ctrl+G” to exit the search<\/li>\n<\/ul>\n<p>On many systems “Ctrl+S” shortcut will not work, as it is prioritized to pause terminal output (press “Ctrl+Q” to resume). To make it work for reverse-i-search, add <span class=\"inline-code\">stty -ixon<\/span> to your shell config. It will disable “Ctrl+S” \/ “Ctrl+Q” shortcuts for terminal flow control:<\/p>\n<div class=\"e2-code-block\" data-language=\"shell\"><div class=\"e2-code-header\"><span class=\"e2-code-language\">Shell<\/span><button class=\"e2-code-copy\" type=\"button\" aria-label=\"Copy code to clipboard\" data-copy-text=\"Copy\" data-copied-text=\"Copied!\" data-failed-text=\"Failed\"><span class=\"e2-svgi\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 16 16\"><mask id=\"cutout\"><rect width=\"100%\" height=\"100%\" fill=\"white\"\/><rect x=\"1.75\" y=\"5.25\" width=\"9\" height=\"9\" stroke-width=\"1.33\" rx=\"1\" fill=\"black\" stroke=\"black\"\/><\/mask><rect x=\"5.25\" y=\"1.75\" width=\"9\" height=\"9\" rx=\"1\" stroke-width=\"1.33\" fill=\"none\" mask=\"url(#cutout)\"\/><rect x=\"1.75\" y=\"5.25\" width=\"9\" height=\"9\" rx=\"1\" stroke-width=\"1.33\" fill=\"none\"\/><\/svg>\r\n<\/span>Copy<\/button><\/div><pre><code class=\"hljs language-shell\">echo &quot;stty -ixon&quot; &gt;&gt; ~\/.bashrc\nsource ~\/.bashrc<\/code><\/pre><\/div><p>Happy command line manipulation!<\/p>\n<p>💡 This post has a second part: <a href=\"https:\/\/mishurovsky.com\/blog\/all\/shell-configs-for-better-command-history-search\/\">Shell Configs for Better Command History Search<\/a><\/p>\n",
            "date_published": "2025-08-03T14:18:24+02:00",
            "date_modified": "2025-10-21T11:41:00+02:00",
            "tags": [
                "devops",
                "guides",
                "linux",
                "mac",
                "search",
                "shell",
                "terminal"
            ],
            "_date_published_rfc2822": "Sun, 03 Aug 2025 14:18:24 +0200",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "5",
            "_rss_enclosures": [],
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        }
    ],
    "_e2_version": 4134,
    "_e2_ua_string": "Aegea 11.3 (v4134e)"
}