{"id":19989156,"url":"https://github.com/clamytoe/useful-linux-commands","last_synced_at":"2026-02-17T05:33:38.640Z","repository":{"id":84639638,"uuid":"149830700","full_name":"clamytoe/useful-linux-commands","owner":"clamytoe","description":"Code examples of some useful Linux/Unix commands.","archived":false,"fork":false,"pushed_at":"2018-09-27T13:54:33.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T05:42:34.815Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clamytoe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2018-09-22T00:04:34.000Z","updated_at":"2018-09-27T13:54:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"b6a16362-7c4a-461e-94c8-276b326fdd71","html_url":"https://github.com/clamytoe/useful-linux-commands","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/clamytoe/useful-linux-commands","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clamytoe%2Fuseful-linux-commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clamytoe%2Fuseful-linux-commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clamytoe%2Fuseful-linux-commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clamytoe%2Fuseful-linux-commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clamytoe","download_url":"https://codeload.github.com/clamytoe/useful-linux-commands/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clamytoe%2Fuseful-linux-commands/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29534975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T05:00:25.817Z","status":"ssl_error","status_checked_at":"2026-02-17T04:57:16.126Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":[],"created_at":"2024-11-13T04:45:39.548Z","updated_at":"2026-02-17T05:33:38.620Z","avatar_url":"https://github.com/clamytoe.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Useful Linux/Unix Commands\n\u003e Code examples of some useful Linux/Unix commands.\n\nSome of the multi-line commands can be condensed into one-liners by simply separating the commands with an `;`. The ones that I have left in multi-line format are ones that I've created into scripts and are in their own files.\n\n## Check file change/download status\nIf you are downloading a bunch of files or generating new ones this command will show you its progress in bytes.\n\n```bash\n#!/bin/bash\nwhile true\n    do\n        clear\n        ls -alt | awk '{print $5}' | head -n 2\n        sleep 1\n    done\n```\n\n## Check if your password has been pwned\n```bash\n#!/bin/bash\nsha1=$(echo -n \"$1\" | sha1sum | awk '{print toupper($1)}' | tr -d '\\n');\ncurl -s -H $'Referer: https://haveibeenpwned.com/' https://api.pwnedpasswords.com/range/$(echo -n $sha1 | cut -c1-5) | grep -i $(echo -n $sha1 | cut -c6-40);\n```\n\n## Clear history\n```bash\n#!/bin/bash\ncat /dev/null \u003e ~/.local/share/recently-used.xbel\n```\n\n## Creat a favicon.ico from a png file\nThe following requires that the latest version of *imagemagick* be installed on your system. The `-background transparent` portion is optional.\n\n```bash\n#!/bin/bash\nconvert -background transparent $1 -define icon:auto-resize=16,32,48,64,128 favicon.ico\n```\n\n## Converting from .m4b to .mp3\n\n```bash\nfaad --stdio INPUT.m4b | lame --preset standard - OUTPUT.mp3\n```\n\n## Generate an ascii table\nI've never needed this, but if I ever do, well I have it :)\n\n```bash\n#!/bin/bash\nSTART=33    # Range of printable ASCII characters (decimal).\nEND=126     # Will not work for unprintable characters (\u003e 126).\n\necho \" Decimal  Hex     Character\"  # Header.\necho \" -------  ---     ---------\"\n\nfor ((i=START; i\u003c=END; i++))\ndo\n  echo $i | awk '{printf(\"   %3d     %2x         %c\\n\", $1, $1, $1)}'\n# The Bash printf builtin will not work in this context:\n#   printf \"%c\" \"$i\"\ndone\n\nexit 0\n```\n\n## Generate a random password\nThe following is a python script that uses *f-strings* so requires 3.6 and above.\n\n```python\n#!/usr/bin/env python3.6\nfrom secrets import choice\nimport string\n\nalphabet = string.ascii_letters + string.digits\nwhile True:\n    password = ''.join(choice(alphabet) for i in range(10))\n    if (any(c.islower() for c in password)\n            and any(c.isupper() for c in password)\n            and sum(c.isdigit() for c in password) \u003e= 3):\n        break\n\n# On standard Linux systems, use a convenient dictionary file.\n# Other platforms may need to provide their own word-list.\nwith open('/usr/share/dict/words') as f:\n    words = [word.strip() for word in f]\n    xkcd = ' '.join(choice(words) for i in range(4))\n\nprint(f'RANDOM PASSWORD: {password}')\nprint(f'  XKCD PASSWORD: {xkcd}')\n```\n\n## Extracting audio track from a video file\n\n```bash\nffmpeg -i INPUT.mp4 -vn -acodec copy OUTPUT.m4a\n```\n\n## Fix brightness\nMy Linux Mint machine dims the screen if I unplug the power, which is a normal behavior for power management. The problem arises later when I plug the power back it, it doesn't restore the brightness to what it normally is. Hence, this hack:\n\n```bash\n#!/bin/bash\nme=`whoami`\nmax=`cat /sys/class/backlight/radeon_bl0/max_brightness`\nsudo chown ${me}:${me} /sys/class/backlight/radeon_bl0/brightness\nsudo chmod o+x /sys/class/backlight/radeon_bl0/brightness\nls -al /sys/class/backlight/radeon_bl0/brightness\necho ${max} \u003e /sys/class/backlight/radeon_bl0/brightness\nsudo chmod 444 /sys/class/backlight/radeon_bl0/brightness\nsudo chown root:root /sys/class/backlight/radeon_bl0/brightness\nexit\n```\n\n## Fix Steam\nIf you start getting all kinds of library errors while trying to start a Steam game, this little command will most likely fix you up.\n\n```bash\n#!/bin/bash\nfind ~/.steam/steam/ubuntu12_32/steam-runtime \\( -name \"libgcc_s.so*\" -o -name \"libstdc++.so*\" -o -name \"libxcb.so*\" -o -name \"libgpg-error.so*\" \\) -print -delete\n```\n\n## Fix system keys\nI don't know why, but there are times when updates just start failing because of bad keys. Here's a quick way of restoring your system back to normal.\n\n```bash\n#!/bin/bash\nsudo apt-get clean\ncd /var/lib/apt\nsudo mv lists lists.old\nsudo mkdir -p lists/partial\nsudo apt-get clean\nsudo apt-get update\n```\n\n## Fix updates\nIf your updates stop working, try this before you panic:\n\n```bash\n#!/bin/bash\nsudo rm -r /var/cache/apt/var/lib/apt/lists\nsudo apt-get update\n```\n\n## Format USB stick\nMake sure you know what device your USB stick is before attempting this.\nIt's useful to run a `dmesg` right after connecting it, to see what was\ndetected.\n\n```bash\n#!/bin/bash\numount /dev/sdc\nmkfs.vfat -I /dev/sdc\nmount /dev/sdc\n```\n\n## Remove old kernels and headers\nI ran into an issue trying to update to a new kernel. It turns out that the old kernels aren't removed by default so my /boot/ partition ran out of space! This little script will list all of the kernels that you are currently installed and display the command that you have to use to remove them.\n\n\u003e NOTE: Keep the most recent kernel and at least one more to fall back to in case of any issues. I just keep the two most recent ones.\n\n```bash\n#!/bin/bash\nclear\necho \"##################\"\necho \"# CURRENT KERNEL #\"\necho \"##################\"\necho \"\"\nuname -r\necho \"\"\necho \"######################\"\necho \"# INSTRALLED KERNELS #\"\necho \"######################\"\necho \"\"\ndpkg --list | grep linux-image | awk '{print $2}'\necho \"\"\necho \"######################\"\necho \"# INSTRALLED HEADERS #\"\necho \"######################\"\necho \"\"\ndpkg --list | grep linux-headers | awk '{print $2}'\necho \"\"\necho \"Remove unwated kernels with:\"\necho \"  sudo apt autoremove\"\necho \"  sudo apt-get purge linux-image-x...\"\n```\n\n## Remove old SSH Key\nI keep forgetting this command, so I put it into a script. Although I think the system tells you how to remove it when it finds that the key has changed...\n\n```bash\n#!/bin/bash\nssh-keygen -f \"/home/`whoami`/.ssh/known_hosts\" -R $1\n```\n\n## Removing spaces from file names\nFor some tasks, it's easier to deal with files that don't have any spaces. Used the following to remove spaces and then put them back.\n\ndespace.sh\n```bash\n#!/bin/bash\nj=`echo $1 | sed 's# #_#g' - `\nmv \"$1\" \"$j\"\n```\n\nrespace.sh\n```bash\n#!/bin/bash\nj=`echo $1 | sed 's#_# #g' - `\nmv \"$1\" \"$j\"\n```\n\n## Setup your git key-ring\n```bash\n#!/bin/bash\n\nsudo apt-get install libgnome-keyring-dev\ncd /usr/share/doc/git/contrib/credential/gnome-keyring\nsudo make\ngit config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring\n```\n\n## Show installed memory modules\n```bash\n#!/bin/bash\nsudo dmidecode | awk '/^Memory\\ Device$/,/Size/{if ($0~/Size/)print}'\n```\n\n## Show your IP address\n```bash\n#!/bin/bash\necho $(ifconfig | awk '/inet /{print $2}' | grep -v ^127)\n```\n\n## Show system serial number\nNeed your machine's serial number but the label is damaged or you're just too lazy to look, don't worry, I've got your back!\n\n```bash\n#!/bin/bash\nsudo /usr/sbin/dmidecode -s system-serial-number\n```\n\n## Splitting up a large audio file\nThe `-segment_time` value is the amount of *seconds* that the audio segment should be.\n\n```bash\nffmpeg -i INPUT.mp3 -f segment -segment_time 3600 -c copy %03d-OUTPUT.mp3\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclamytoe%2Fuseful-linux-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclamytoe%2Fuseful-linux-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclamytoe%2Fuseful-linux-commands/lists"}