{"id":28436284,"url":"https://github.com/james-firth/useful-commandline-snippets","last_synced_at":"2026-05-16T11:06:28.781Z","repository":{"id":140082849,"uuid":"41749345","full_name":"James-Firth/useful-commandline-snippets","owner":"James-Firth","description":"A list of commandline snippets I find useful or always need to look up. Also some useful shell scripts apparently.","archived":false,"fork":false,"pushed_at":"2022-01-24T18:10:13.000Z","size":35,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-23T23:11:43.977Z","etag":null,"topics":["bash","snippets"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/James-Firth.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-09-01T16:10:54.000Z","updated_at":"2022-09-12T15:50:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"1a04cd78-37f0-4c65-8318-a6a087ffb5a8","html_url":"https://github.com/James-Firth/useful-commandline-snippets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/James-Firth/useful-commandline-snippets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-Firth%2Fuseful-commandline-snippets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-Firth%2Fuseful-commandline-snippets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-Firth%2Fuseful-commandline-snippets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-Firth%2Fuseful-commandline-snippets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/James-Firth","download_url":"https://codeload.github.com/James-Firth/useful-commandline-snippets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/James-Firth%2Fuseful-commandline-snippets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33100321,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","snippets"],"created_at":"2025-06-05T22:07:46.389Z","updated_at":"2026-05-16T11:06:28.775Z","avatar_url":"https://github.com/James-Firth.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Useful Snippets of commandline code\n\n## General Information o7\n\n* The `^` (carat) symbol is often used to denote the `Ctrl` button so `^C` means `Ctrl+C`\n* `NO_PUBKEY` error? Make sure to add keys via something like \n  \n```bash\nwget http://download.opensuse.org/repositories/PATH/TO/KEY/Release.key\n\napt-key add - \u003c Release.key\n```\n\n* Use `^L` (`Ctrl+L`) to clear the terminal, even if using a sub-program like mongo or python's interactive shells.\n\n* `\u003c(echo \"hello world\")` will put the results of your process in a temp file and pass the file path to a different process, `cat \u003c(echo \"Hello world\")` for instance will invoke something like `cat /proc/self/fd/11`. Very useful for diffs, etc.\n\n## File Mangling\n\nAccidentally spew the entire HTTP header, including the Authentication header, to a log file?\n\nThis will look for `Api-Key: THEKEY`and replace `THEKEY` with a redaction, in-place.\n`gawk -i inplace '{IGNORECASE=1; r = gensub(/(Api-Key:)\\s*(.+)$/, \"\\\\1 ***REDACTED***\", \"g\"); print r;}' oops.log`\n\n## SCP\n\nReferences: http://www.hypexr.org/linux_scp_help.php\n\nCopy the file \"foobar.txt\" from the local host to a remote host\n\n`scp foobar.txt your_username@remotehost.edu:/some/remote/directory`\n\nTo copy a directory:\n\n`scp -r \"path/to/directory\" your_username@remotehost.edu:/some/remote/directory`\n\n## SSH keys\n\nhttp://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/\n\nCopy your ssh key to another machine to avoid typing in passwords\n\n`ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host`\n\nAlternatively use my script `the_keymaker.sh` to automate this process a bit. Also maintains a nicer ssh config file.\n\n\n## Tar\n\nuntar\n`tar -xvf filename`\n\n## Process Management\n\nFind all the processes that contain a word, such as all python processes\n`ps aux | grep \u003csearch string\u003e` - shows a lot of output including the path of the file and args (more detailed)\n`ps -e | grep \u003csearch string\u003e` - shows the PID and the process name (much cleaner)\n\nParallelize processes.\nUsing the code below command1 and command2 will be run in the background and command3 will be run normally. The benefit is when a SIGINT (via `^C`) is sent, all 3 commands will be killed.\n```\ntrap 'kill %1 kill %2' SIGINT\ncommand1 \u0026 command2 \u0026 command3\n```\n\n## Grep\n\nUse status code to determine if that line of text exists in that file.\n`grep -Fxq \"line of text\" /path/to/file` \n\nSearch a directory recursively for a term. (Ignores case, only searches text files, and shows a line above and below the matched term)\n`grep -ainr -B 1 -A 1 \"TERM\" /DIR/TO/SEARCH`\n\n## Moving files\nIf you want to move everything in the current working directory into a sub-folder named `newdir` and want an exit status code of `0`, you can't use `mv` because it will try to move `newdir` into itself and error. Instead use this\n`find . -maxdepth 1 ! -path . | grep -v \"newdir\" | xargs -i mv {} newdir`\n\n## Useful CLI programs to install/uses\n\n* Woof\n  * Simple file server\n* mpv\n  * Commandline media player\n* tmux\n  * Terminal multiplexer. Better than screen (debatably) and useful for servers.\n  * \n* [jq](https://stedolan.github.io/jq/download/)\n  * like `sed` for JSON data\n  \n\n## Git - Useful snippets and common gotchas\n\n* [Oh crap I commited to the current branch but I wanted to make a new one](http://stackoverflow.com/questions/1628563/move-the-most-recent-commits-to-a-new-branch-with-git)\n* \n\n## TODO\n\n* Eventually split this into better chunks/files.\n* Add useful snippets for diffregits\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames-firth%2Fuseful-commandline-snippets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjames-firth%2Fuseful-commandline-snippets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjames-firth%2Fuseful-commandline-snippets/lists"}