{"id":13584226,"url":"https://github.com/labbots/bash-oneliners","last_synced_at":"2025-04-14T04:24:40.102Z","repository":{"id":50713887,"uuid":"268804500","full_name":"labbots/bash-oneliners","owner":"labbots","description":"Curated list of useful bash onliner commands and functions.","archived":false,"fork":false,"pushed_at":"2021-01-27T20:09:57.000Z","size":17,"stargazers_count":24,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-27T18:21:23.235Z","etag":null,"topics":["bash","bash-hacks","bash-script"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/labbots.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-06-02T13:11:55.000Z","updated_at":"2025-02-20T04:56:04.000Z","dependencies_parsed_at":"2022-09-24T16:50:32.191Z","dependency_job_id":null,"html_url":"https://github.com/labbots/bash-oneliners","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labbots%2Fbash-oneliners","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labbots%2Fbash-oneliners/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labbots%2Fbash-oneliners/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/labbots%2Fbash-oneliners/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/labbots","download_url":"https://codeload.github.com/labbots/bash-oneliners/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248820233,"owners_count":21166628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","bash-hacks","bash-script"],"created_at":"2024-08-01T15:04:06.257Z","updated_at":"2025-04-14T04:24:40.084Z","avatar_url":"https://github.com/labbots.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eBash Oneliners\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/labbots/bash-oneliners/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/labbots/bash-oneliners.svg?style=for-the-badge\" alt=\"License\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.codacy.com/manual/labbots/bash-oneliners?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=labbots/bash-oneliners\u0026amp;utm_campaign=Badge_Grade\"\u003e\u003cimg src=\"https://img.shields.io/codacy/grade/a72b150d9e8b4166996abf8f871c42b0?style=for-the-badge\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\nCurated list of useful bash onliner commands and functions.\n\n## Table of Contents\n- [Files \u0026 Directory](#files--directory)\n- [Git](#git)\n- [Network](#network)\n- [System](#system)\n- [Terminal](#terminal)\n\n## Files \u0026 Directory\nList only empty directories and delete safely.\n\n```shell\nfind . -type d -empty -exec rm -i -R {} \\;\n```\n\nFind duplicate files in directory using MD5.\n\n```shell\nfind . -not -empty -type f -printf \"%s\\n\" | sort -rn | uniq -d | xargs -I{} -n1 find . -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate\n```\n\nSort disk usage in human-readable format on current directory.\n\n```shell\nfor i in $(echo -e 'G\\nM\\nK'); do du -hsx *  2\u003e/dev/null | grep '[0-9]'$i | sort -rn; done\n```\n\n## Git\n\nPrint the list of your Git commits this month.\n\n```shell\ngit log --since='last month' --author=\"$(git config user.name)\" --oneline\n```\n\nDelete all local git branches that have been merged and deleted from remote.\n\n```shell\ngit branch -d $( git branch -vv | grep '\\[[^:]\\+: gone\\]' | awk '{print $1}' | xargs )\n```\n\nRevert files with changed mode, not content.\n\n```shell\ngit diff --numstat | awk '{if ($1 == \"0\" \u0026\u0026 $2 == \"0\") print $3}' | xargs git checkout HEAD\n```\n\nList all authors of a git project.\n\n```shell\ngit log --format='%aN \u003c%aE\u003e' | awk '{arr[$0]++} END{for (i in arr){print arr[i], i;}}' | sort -rn | cut -d ' '  -f2-\n```\n\nShows a short descriptive information inline including branch details in a coloured log tree.\n\n```shell\ngit log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Cblue - %cn %Creset' --abbrev-commit --date=relative\n```\n\n## Network\n\nGet your public IP address.\n```shell\ncurl -s http://checkip.dyndns.org | sed 's/[a-zA-Z\u003c\u003e/ :]//g'\n```\n\n## System\n\nShow all the startup applications that are hidden in \"startup applications\".\n\n```shell\nsudo sed -i \"s/NoDisplay=true/NoDisplay=false/g\" /etc/xdg/autostart/*.desktop\n```\n\nQuick and dirty way to update system time in Linux if there is any issues with ntp.\n\n```shell\nsudo date -s \"$(wget -qSO- --max-redirect=0 google.com 2\u003e\u00261 | grep Date: | cut -d' ' -f5-8)Z\"\n```\nCount the total number of hours of your music in the directory.\n\n```shell\nfind . -print0 | xargs -0 -P 40 -n 1 sh -c 'ffmpeg -i \"$1\" 2\u003e\u00261 | grep \"Duration:\" | cut -d \" \" -f 4 | sed \"s/.$//\" | tr \".\" \":\"' - | awk -F ':' '{ sum1+=$1; sum2+=$2; sum3+=$3; sum4+=$4; if (sum4 \u003e 100) { sum3+=1; sum4=0 }; if (sum3 \u003e 60) { sum2+=1; sum3=0 }; if (sum2 \u003e 60) { sum1+=1; sum2=0 } if (NR % 100 == 0) { printf \"%.0f:%.0f:%.0f.%.0f\\n\", sum1, sum2, sum3, sum4 } } END { printf \"%.0f:%.0f:%.0f.%.0f\\n\", sum1, sum2, sum3, sum4 }'\n```\n\n### Clear Linux Cache\n1. Clear PageCache only\n   ```shell\n   sync \u0026\u0026 echo 1 | sudo tee /proc/sys/vm/drop_caches\n   ```\n2. Clear dentries and inodes\n   ```shell\n   sync \u0026\u0026 echo 2 | sudo tee /proc/sys/vm/drop_caches\n   ```\n3. Clear PageCache, dentries and inodes\n   ```shell\n   sync \u0026\u0026 echo 3 | sudo tee /proc/sys/vm/drop_caches\n\n## Terminal\n\nGet top 10 used commands from history.\n\n```shell\nhistory | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] \" \" CMD[a]/count*100 \"% \" a;}' | grep -v \"./\" | column -c3 -s \" \" -t | sort -nr | nl |  head -n10\n```\nPrint all the supported terminal colours and their reference code to use with tput.\n\n```shell\n( x=`tput op` y=`printf %$((${COLUMNS}-6))s`;for i in {0..256};do o=00$i;echo -e ${o:${#o}-3:3} `tput setaf $i;tput setab $i`${y// /=}$x;done; )\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabbots%2Fbash-oneliners","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flabbots%2Fbash-oneliners","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flabbots%2Fbash-oneliners/lists"}