r/bashtricks • • Apr 25 '20

[Tip] How to remove root password prompt for specific apps

1 Upvotes

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:

  1. root access

  2. log in name

  3. 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 visudo

then 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 • • May 30 '17

Pdf viewing for the impatient terminal lover.

0 Upvotes

Simple. Stupid. Elegant.

edit: More like Pdf viewer and editor.

I feel like an idiot for not doing this sooner.

less name-of-file.pdf > name-of-file.txt

Duh.

Not necessarily a trick, more like less doing what less does, print text to stdout.


r/bashtricks • • Feb 22 '14

Screen saver for your Shell

Thumbnail thelinuxnotes.com
1 Upvotes

r/bashtricks • • Mar 16 '16

역삼오피 시내 오피업소위치를 【구글검색 『Udaiso05.cOm』】에서 제공하며, 역삼휴게텔,역삼op,역삼건마,역삼안마등의 위치정보까지

0 Upvotes

역삼오피 시내 오피업소위치를 【구글검색 『Udaiso05.cOm』】에서 제공하며, 역삼휴게텔,역삼op,역삼건마,역삼안마등의 위치정보까지역삼오피 시내 오피업소위치를 【구글검색 『Udaiso05.cOm』】에서 제공하며, 역삼휴게텔,역삼op,역삼건마,역삼안마등의 위치정보까지역삼오피 시내 오피업소위치를 【구글검색 『Udaiso05.cOm』】에서 제공하며, 역삼휴게텔,역삼op,역삼건마,역삼안마등의 위치정보까지역삼오피 시내 오피업소위치를 【구글검색 『Udaiso05.cOm』】에서 제공하며, 역삼휴게텔,역삼op,역삼건마,역삼안마등의 위치정보까지역삼오피 시내 오피업소위치를 【구글검색 『Udaiso05.cOm』】에서 제공하며, 역삼휴게텔,역삼op,역삼건마,역삼안마등의 위치정보까지역삼오피 시내 오피업소위치를 【구글검색 『Udaiso05.cOm』】에서 제공하며, 역삼휴게텔,역삼op,역삼건마,역삼안마등의 위치정보까지역삼오피 시내 오피업소위치를 【구글검색 『Udaiso05.cOm』】에서 제공하며, 역삼휴게텔,역삼op,역삼건마,역삼안마등의 위치정보까지


r/bashtricks • • May 23 '17

The world in the eyes on the bash shell.

Post image
3 Upvotes

r/bashtricks • • Dec 09 '20

A bash Function to run passed commands with cache | Let's Code

Thumbnail
youtube.com
0 Upvotes

r/bashtricks • • May 10 '11

List of all bash commands

Thumbnail
oreilly.com
12 Upvotes

r/bashtricks • • Jul 20 '22

8 Uses of sed in Linux

Thumbnail
medium.com
1 Upvotes

r/bashtricks • • Jun 30 '13

A one-liner to change the extension of many files at once (eg. JPG -> jpeg)

8 Upvotes

I had to upload some pics to a website but the form processing logic was so miserably poor that it only accepted files with png, jpeg or gif extensions. Since my files were .JPG, it didn't know that they were jpegs, because (I guess) it would litterally look for the jpeg string in the filename.

So, to rename my files from .JPG to .jpeg, I had to use this bash trick called substring substitution.

for file in *; do mv $file ${file%.JPG}.jpeg; done;

Explanation :

${file} prints the filename ${file%something} scans the string contained in the $flle variable from the left until it finds "something", it then returns the rest of the string (again, it scans from left to right).

So for example :

file=abcdef.ghijkl

echo ${file%i} 

would print

abcdef.gh, without the i.

r/bashtricks • • May 17 '11

Execute previous command as root

14 Upvotes

If you type out a long command and forget to sudo it, it's a pain to type it out again. Instead:

sudo !!

r/bashtricks • • Feb 12 '21

[Blog] Bash variables — Things that you probably don’t know about it

4 Upvotes

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 Medium: https://medium.com/unboxing-the-cloud/bash-variables-things-that-you-probably-dont-know-about-it-8a5470887331?sk=26693ca772a0c54c99d3712303560ed4

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 • • Dec 03 '19

Hi guys and gals I've opened a twitter to share my bash tricks with you! I would appreciate a follow or even a like on this post😊 thanks! 🐧🐧🐧

Thumbnail
twitter.com
5 Upvotes

r/bashtricks • • May 09 '11

Poorman's "Which"

12 Upvotes
$ type type
type is a shell builtin

r/bashtricks • • May 09 '11

Everybody post your customized .bashrc!

2 Upvotes

Here is mine. (ShortText link--I'll post it in a different way if asked.) It is compiled from various (forgotten) sources, and also includes some of my own code. It could be improved upon, and is a bit messy, but it makes my life much easier.

I can't wait to see what cool tricks you guys have in yours! (Don't forget to remove any identifying lines of code.)

Edit: I hope it is not blasphemy in this subreddit to do so, but in case there is interest, here is my .cshrc file. As you can see, it is much less used than my .bashrc.


r/bashtricks • • Feb 17 '21

[Blog] A CLI tool that can easily manage more than 281 runtimes, making it easy to keep things updated and/or switching between versions. And it’s open-source :)

3 Upvotes

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 Medium: https://medium.com/bash-tips-and-tricks/an-easy-way-to-switch-between-runtime-versions-nodejs-terraform-and-279-53fdfbcb4049?sk=43548418bf394d80e277a39a76070843

See on my Website: https://www.lozanomatheus.com/post/an-easy-way-to-switch-between-runtime-versions-nodejs-terraform-and-279


r/bashtricks • • Jul 04 '16

Need to find all files with certain characters

2 Upvotes

What ls command options would i use to find all files with the characters "doc" in all nested directories. I was thinking ls --doc | grep or ls grep --doc..idk. ive been trying to fig this out for hours.


r/bashtricks • • Jun 30 '13

Handy Bash reference cards

Thumbnail tldp.org
5 Upvotes

r/bashtricks • • Jan 26 '23

stail.sh - Short Tail

Thumbnail self.bash
5 Upvotes

r/bashtricks • • Oct 02 '21

POSIX compliant way to remove directories from PATH

2 Upvotes

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%.}"
fi

The 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 • • Dec 04 '17

Importing other shell scripts without any of those imported shell scripts having the executable bit

2 Upvotes

Main test.sh file:

#!/bin/sh

if test \! "$ASDFGHJKL"; then
    export ASDFGHJKL=QWERTYUIOP
    TMPFILE="/tmp/.$$.`basename $0`"

    soelim -r "$0" > "$TMPFILE"
    chmod a+x "$TMPFILE"

    exec "$TMPFILE"
    RET=$?

    rm "$TMPFILE"
    exit $?
else
    unset ASDFGHJKL
fi

.so test2.sh
.so test3.sh

test2.sh looks like this:

echo "Hello World!"

test3.sh looks like this:

echo "This is the last file."
exit 5

Set the executable bit for test.sh and test.sh only. Run test.sh and it should work. :p


r/bashtricks • • 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.

Thumbnail
github.com
5 Upvotes

r/bashtricks • • May 08 '14

Some of this is review but there are a LOT of tips in here I wasn't aware of before and I've been slinging bash for 20 years.

Thumbnail
robertmuth.blogspot.com
5 Upvotes

r/bashtricks • • Apr 15 '13

The .ideas file - Quickly jot ideas from the Terminal

Thumbnail
stevenloria.com
1 Upvotes

r/bashtricks • • Nov 25 '19

A nifty alias to quickly create a bash script

Thumbnail
gist.github.com
4 Upvotes