Commands by realkstrawn93 (9)

  • Because Mac app bundles contain everything in one place, it makes running them from anywhere, including from a device such as a USB flash drive or external HDD, possible. So if your Mac has a mere 256GB of storage (as mine does), you can free up large quantities of disk space by storing apps like, say, Xcode on external devices.

    sudo mv /Applications/foo /Volumes/bar/Applications/foo && sudo ln -s /Volumes/bar/Applications/foo /Applications/foo
    realkstrawn93 · 2022-01-20 18:03:36 5
  • Adding this alias to ~/.bashrc or, better yet, the system-wide /etc/bash.bashrc (as in my setup) will make it possible to not only run pacman as any user without needing to prepend sudo but will also ensure that it always assumes that the user knows what he or she is doing. Not the best thing for large multi-user enterprise setups at all to say the least, but for home (desktop) use, this is a fantastic time-saver.

    alias pacman=‘sudo pacman --noconfirm’
    realkstrawn93 · 2021-12-28 20:29:13 36
  • Breakdown of the subshell: cat /etc/group # contents of file containing all groups on the system grep -v 65534 # filter out the ‘nobody’ group cut -d\: -f1 # extract the group names themselves tr ‘\n’ ‘,’ # replace all new lines in the extracted output with commas sed -e “s/\,$//“ # remove trailing comma from the end of the output After rebooting, if you type the “groups” command, you’ll find yourself added to (almost) every group on the system.

    sudo usermod -G $(cat /etc/group | grep -v 65534 | cut -d\: -f1 | tr ‘\n’ ‘,’ | sed -e “s/\,$//) $USER
    realkstrawn93 · 2021-11-30 19:02:10 41
  • After downloading an ISO image, assuming you have QEMU installed, it’s possible to boot an ISO image in a virtual machine and then install that ISO from within the virtual machine directly to a physical drive, bypassing the need to reboot. Simply pass the ISO image as the -cdrom parameter, followed by “format=raw,file=/dev/sdb” (replace /dev/sdb with the drive you want to install to) as the hard drive parameter (making absolutely certain to specify the raw format, of course). Once you boot into the ISO image with QEMU, just run the installer as if it were a virtual machine — it’ll just use the physical device as an install target. After that, you’ll be able to seamlessly boot multiple distros (or even other operating systems) at once.

    sudo qemu-system-x86_64 -bios /usr/share/ovmf/x64/OVMF.fd -accel kvm -boot d -cdrom ubuntu-21.10-desktop-amd64.iso -drive format=raw,file=/dev/sdb -m 4096
    realkstrawn93 · 2021-11-04 22:50:57 60
  • “$0” is a variable returning the name of the script that you call it in — so running “./$0&” twice amounts to the script running itself in a separate process twice. Show Sample Output

    echo -e “\x23\x21/bin/bash\n\.\/\$\0\&\n\.\/\$\0\&” > && ./
    realkstrawn93 · 2021-04-30 19:33:40 43
  • Get newest kernel version by parsing the most bleeding-edge Makefile possible. Useful for doing things like writing live ebuilds and/or self-updating PKGBUILDs for testing purposes. Breakdown: * wget -qO - — retrieve Makefile and pipe to stdout * head -n5 — only the first 5 lines are relevant, that's where all the version variables are grep -E '\ \=\ [0-9]{1,}' — version variables always have an equals sign followed by a number * cut -d' ' -f3 — extract the individual numbers from the version variables * tr '\n' '.' — replace newlines with periods * sed -e "s/\.$// — remove trailing period Show Sample Output

    wget -qO - | head -n5 | grep -E '\ \=\ [0-9]{1,}' | cut -d' ' -f3 | tr '\n' '.' | sed -e "s/\.$//"
    realkstrawn93 · 2021-04-27 17:12:05 84
  • Placing sudo in the shebang line of a shell script runs the entire thing as root. Useful for scripts designed to, e.g. automate system upgrades or package manager wrappers — makes prepending everything with sudo no longer necessary

    #!/usr/bin/sudo /bin/bash
    realkstrawn93 · 2021-04-27 05:04:30 54
  • In this example, I’m creating a wrapper for apt-get that assumes yes every time — but the command could be anything.

    sudo su -c “echo -e \”\x23\x21/usr/bin/sudo /bin/bash\napt-get -y \x24\x40\” > /usr/bin/apt-yes”
    realkstrawn93 · 2019-09-19 16:28:33 23
  • Writes hybrid ISO directly to USB stick; replace /dev/sdb with USB device in question and the ISO image link with the link of your choice

    wget -O /dev/sdb
    realkstrawn93 · 2019-09-19 04:03:13 11

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

list block devices
Shows all block devices in a tree with descruptions of what they are.

get all Amazon cloud (amazonws etc) ipv4 subnets

Multi line grep using sed and specifying open/close tags
This line does not include your closing tag in the output.

Get first Git commit hash
git log --format=%H | tail -1 doesn't work anymore

How to trim a video using ffmpeg
Will trim the video to 4 seconds starting from the beginning. The -vcodec , -acodec options are required so that ffmpeg knows in what video/audio format you want for the new video.

list files recursively by size

Exclude a string with awk

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

diff 2 remote files

umount --rbind mount with submounts

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: