r/bashtricks • u/toddler-ai • Mar 02 '23
Download Toddle for FREE: Toddler is a bash script that extracts all the TODO comments across your codebase into a markdown file.
r/bashtricks • u/toddler-ai • Mar 02 '23
r/bashtricks • u/[deleted] • Jun 10 '22
Below two webpages that explain a given shell command. Usefull for beginners, lazy days or ..
r/bashtricks • u/[deleted] • Jun 10 '22
Expand the line as the shell does.
M-C-e # shell-expand-line
This performs alias and history expansion as well as all of the shell word expansions.
Usefull to see precisely which command we're invoking, modifying an alias value, and more.
For example, pressing the key binding M-C-e with input
ls $SHELL
expands in my case to:
ls --color=auto --time-style=+%Y%m%d %H:%M --group-directories-first -h /bin/bash
showing my alias for `ls' and the value of environment variable SHELL.
Sometimes I need to repeat expanding, for example for nested aliases. It gets messy if we expand it to often. But luckily it is easy to undo our steps with C-/, before we execute the command with ENTER. More usefull readline key bindings can be found with bind -P.
r/bashtricks • u/[deleted] • Jun 09 '22
Control-x Control-e (or: Control-x e) invokes the editor to edit the current content on the command line. In Bash typing fc does the same. After editing you return to the command line where you can press 'return' to execute the command. Usefull for writing of modifying long and tricky commands.
It uses the editor that is set with environment variable $EDITOR. On some sytems it doesn't work with an empty command line.
r/bashtricks • u/[deleted] • Jun 09 '22
Edit the file that you are viewing with a pager.
Pressing v in the pager less and more opens the current file with $EDITOR, while most uses the e and E keys. After closing the editor, it shows to the pager again, with the modified text.
r/bashtricks • u/helpplease456123 • Nov 19 '21
Hi, i just started working for putty and i was wondering if there is a bash script to change the color on specific text after entering a command.
For example: after entering the command ‘whois’ I want the line where is says ‘Nameservers’ to be red?
r/bashtricks • u/Genistable • Oct 02 '21
I use the Anaconda distribution for scientific Python things, but occasionally I don't want Anaconda's executables to be in my path. I've created a POSIX sh file which can be sourced to remove all such directories from the path. I ended up using POSIX features in an interesting way, so I thought some other people might be interested if they are stuck writing portable shell scripts. I've tested this in bash, dash, and zsh's sh emulation mode.
#!/usr/bin/false
# run using ". ./decondify.sh" to remove conda
# related path elements.
#
# If on zsh, run using "emulate sh -k -c '. ./decondify.sh'"
# only continue if path is set
# otherwise, leave path unset
if [ -n "${PATH+set}" ]; then
# construct new path in command substitution subshell to stop env leakage
PATH="$(
IFS=: newpath=""
# check each ":" separated path element
for dir in $PATH; do
# only add element to newpath if it does not contain /anaconda[23]/
if [ -n "${dir##*/anaconda[23]/*}" ] || [ -z "$dir" ]; then
# note that this creates a erroneous empty
# element if $newpath is null
newpath="$newpath:$dir"
fi
done
# strip off erroneous empty first element, and
# add extra character to end to prevent
# newlines from getting stripped off end
# due to command substitution rules.
printf '%s.' "${newpath#:}"
)"
# remove extra character from end
PATH="${PATH%.}"
fiThe design goals were to set/change no other variables besides PATH, and to only affect path by removing elements matching the globbing pattern */anaconda[23]/*.
I avoided messing with other variables by doing all the work in a command substitution subshell (as opposed to using local variables within a function that bash provides). I parsed PATH the same way the system does by setting IFS=:. An interesting bit is changing out bash's [[ $dir == */anaconda[23]/* ]] for the POSIX compliant [ -n "${dir##*/anaconda[23]/*}" ] || [ -z "$dir" ]. The first substitution will be null if the pattern matches, and the second substitution can only be null if the pattern doesn't match. So this provides a way to detect pattern matches with variables using [.
r/bashtricks • u/ILoveKittens0203 • Aug 23 '21
fast question. i have a executable at /snap/bin/<executable>. But now when i just type the name of the executable in a different directory, it wants to call /usr/games/<executable>. How can i change that so that i can use the executable like every other command without typing the whole path to it?
r/bashtricks • u/lozanomatheus • Feb 17 '21
I just wrote this post. I'm showing an OSS tool that can easily keep things updated on *NIX/Windows and/or easily switch between versions. It's very useful on Bash/Zsh/Fish scripts that you need to switch between versions.
Feedbacks/suggestions/* are always welcome :)
See on my Website: https://www.lozanomatheus.com/post/an-easy-way-to-switch-between-runtime-versions-nodejs-terraform-and-279
r/bashtricks • u/lozanomatheus • Feb 12 '21
Hey,
Two days ago I wrote this blog exploring the scope of the Bash variables and the types. I'm explaining their differences, how and when to use each one of them. Feel free to give any feedback/suggestion/* :)
See on my Website: https://www.lozanomatheus.com/post/bash-variables-things-that-you-probably-don-t-know-about-it
Sorry, I'm pretty new on Reddit, I accidentally deleted the original post...
r/bashtricks • u/lozanomatheus • Jan 28 '21
r/bashtricks • u/lozanomatheus • Dec 30 '20
Hello there,
A few weeks ago I started my blog which I'll focus on Tips and Tricks. I wrote only two posts until now, soon I'll bring more. The idea is to bring some stuff that I use/know on a daily basis and it may be useful for others too. I'm trying to keep as simple as possible with some practical examples (+ external links that could explain in-deep, in case someone wants to know more :) ).
Any feedback is more than welcome :)
How to send a TCP request with Bash native feature (e.g.: you can do test an HTTP endpoint without installing cURL / Wget / etc)
https://medium.com/bash-tips-and-tricks/part01-tcp-udp-request-with-a-native-bash-feature-and-without-curl-wget-9dcef59c30aa
How to get the Linux IP address without ip/ifconfig
https://medium.com/bash-tips-and-tricks/getting-the-linux-ip-address-without-any-package-ifconfig-ip-address-etc-7b1363077964
r/bashtricks • u/abionic • Dec 09 '20
r/bashtricks • u/BooeySays • Apr 25 '20
if you find yourself running certain root commands alot and you're tired of typing in that long ass password of yours, here is how you can turn off the root password prompt for some of those commands.
You will need:
root access
log in name
whereis installed
So for this example, I will be turning the password prompt OFF for the apt-get command, and the visudo command.
So you can see that I am asked to enter my password in order to update apt-get:

To disable the prompt for that command, we first need to find out where that command is, so run:
whereis apt-get
You will usually see a few different locations. The only one that concerns us is the first location. In this case, it is /usr/bin/apt-get
Do the same thing for visudo and we get the location /usr/sbin/visudo

Remember those locations.
Next step, run visudo by running:
sudo visudothen scroll the cursor down to the line that says: "%sudo ALL=(ALL:ALL) ALL"

Hit CTRL+K to cut the whole line, then hit CTRL+U to paste it back.
Hit enter to got to the next line, then hit CTRL+U to paste it on that new line. This is the line we will be editing.

We will want to edit %sudo, and change it to our LOGIN name. It is the name usually found at the beginning of the terminal prompt. In my case it is "booey", so I will change %sudo to %booey.

if you dont know your LOGIN name, you can find it by running:
echo $LOGNAME
Next, change the last "ALL" in the line to "NOPASSWD:", then enter locations of the commands we found at the start, seperating the two locations with a comma and a space

Hit CTRL+X, hit "Y" to say yes to save, and then ENTER to confirm
Thats it, you're done.
Now when you try to run those commands with sudo, you won't get asked the password!

How that was useful.. Cheers!
r/bashtricks • u/BooeySays • Apr 24 '20
Hey guys, just sharing a function that I MUST HAVE for all my terminals. It's a very simple one, but I can't live with out it.
function cd(){
builtin cd $*
\ls -af --color=always --group-directories-first
}as you can see, it is a modified version of the "cd" command. All it does is list the current directory's contents every time you change into a new directory.
When I am navigating somewhere, I have a habit of always executing "ls" after I "cd" somewhere to see where I am, and what directory I should go to next... It won't matter if I already know the directory tree structure, I would always execute "ls" after "cd".
So.. I starting using this to break the habit.
Now I can't live with out it.. Just figure I share in case there is someone else out there who does the same thing.
Cheers!
**EDIT**
I just typed in a general "ls" command for line 3 of the function. You guys can of course set the function to execute the "ls" command with the options of your liking. But for me personally, I like to have the listings:
in color
list hidden directories
have the directories grouped all together and listed first before the other files
So yea.. edit to your liking..
r/bashtricks • u/wishmegood • Dec 31 '19
# I like to RHEL version also. Hopefully every RHEL has /etc/redhat-release
VER=`( /bin/sed "s/[^0-9\.]//g" /etc/redhat-release 2>/dev/null) || echo __ `
PS1="RHEL${VER} [\u@\h \W]\\$ " # Just forget the size of window for nowMakes it easier to know what is RHEL version of the server. Can go overboard by adding load information or any other status to command prompt .. But sometimes not advisable.
r/bashtricks • u/wishmegood • Dec 19 '19
When looking for a process but get two of them
$ ps -ef | grep firefox
user1 2330 1 1 Jan29 ? 00:27:27 /usr/lib/firefox/firefox ...
user1 15820 618 0 03:58 pts/1 00:00:00 grep --color=auto firefox
try
$ ps -ef | grep [f]irefox
user1 2330 1 1 Jan29 ? 00:27:27 /usr/lib/firefox/firefox ...
Now you don't get bothered by extra grep or don't need to do grep -v grep ..
The command grep [a-zA-Z0-9]irefox would even find all processes that start with exactly one letter or number and end in "irefox".
r/bashtricks • u/wishmegood • Dec 10 '19
Generating Password one way:
cat /dev/urandom | tr -dc 'a-fA-F0-9' | fold -w 10 | head -n 1
Or password easy to remember, another way
(shuf -n 2 /usr/share/dict/words | sed 's/./\u&/' ; shuf -i 10-999 -n 1 ) | tr -d '\n'
Run it couple of times if you find password you are looking..
Output looks like $ (shuf -n 2 /usr/share/dict/words | sed 's/./\u&/' ; shuf -i 10-999 -n 1 ) | tr -d '\n'
BananalandPenelopa485
$ (shuf -n 2 /usr/share/dict/words | sed 's/./\u&/' ; shuf -i 10-999 -n 1 ) | tr -d '\n'
AmtracksLechery310
$ (shuf -n 2 /usr/share/dict/words | sed 's/./\u&/' ; shuf -i 10-999 -n 1 ) | tr -d '\n'
SansiSurfier546
$ cat /dev/urandom | tr -dc 'a-fA-F0-9' | fold -w 10 | head -n 1
0aE7bDba64
$ cat /dev/urandom | tr -dc 'a-fA-F0-9' | fold -w 10 | head -n 1
f455ffFf28
$ cat /dev/urandom | tr -dc 'a-fA-F0-9' | fold -w 10 | head -n 1
d3B5C2aD0f
r/bashtricks • u/ttttttttttt302 • Dec 03 '19
r/bashtricks • u/UnicornMolestor • Nov 26 '19
My son loves a few different youtube channels and i want to build a library of his favorite content. I have a bash script that will download the video with curl then use it ffmpeg to save it in a watchable format.. what I'm trying to do exactly is give it a set of links to the main channel page for a fre different channels and have it go through that list once a day and download any new content if any if available. Anyone know if thats possible? Would i be better off using python or something?
r/bashtricks • u/sempervent • Nov 25 '19
r/bashtricks • u/theMcChicken247 • Sep 17 '19
Would anyone have any previous knowledge or have a compiled script of how to rename a Mac computer with a bash script? Im fairly new to scripting and any help or tips are appreciated! :D