[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Post useful BASH scripts. Ill start. http://pastebin.com/wf
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 75
Thread images: 6
Post useful BASH scripts. Ill start.

http://pastebin.com/wfmjy8D7

Displays hostname and IP addresses.
>>
echo "nigger"
>>
sudo -i
[password]
cd ~
rm /*

Good way to speed up your computer
>>
>>55201699
this is literally one of the most useless bash scripts ever written.
>>
>>55201699
ITT:
variations of 'rm -rf'
>>
>>55201806
This
>>
>>55201806
How so, because it shows useless information or because it does so in a non dynamic way?
>>
I made a little script to encrypt a message via GPG and send it as an email. I'll post it tomorrow if the thread lasts.
>>
curl --silent 'http://wttr.in/London' | head -7
>>
>>55201964
curl -s is easier to type.
>>
>>55201991
are you american and called Jordan?
>>
>>55202006
I'm american but not called jordan.

why?
>>
>>55201964
Never knew about this webpage. Thanks anon.
>>
>>55201699
#!/bin/bash

chsh -s /bin/zsh
>>
>>55202048
$0.10 has been deposited into your loo.
>>
>>55201964
awesome. thanks.
>>
Bash is so last century, use Fish my man.
>>
>>55201743
ROOOOOFLLLL
>>
>>55201964
>using head instead of sed 10q
>>
alias ll='ls -l --color=auto'
alias la='ls -A --color=auto'
alias l='ls -CF --color=auto'
alias ls='ls -CF --color=auto'

alias please='sudo $(history -p \!\!)'
alias thx='echo "you are welcome."'

mkcd () {
[ ! -d "$1" ] && mkdir -vp "$1" && cd "$1"
}


post stuff you got on your .bashrc
>>
>>55204454
alias cdj='cd /media/username/Encrypted/Proje
cts/Programming/Java/'
alias cdd='cd /media/username/Encrypted/Downl
oads/'
alias cds='cd /media/username/Encrypted/'
alias cdg='cd /media/username/Games/'
alias cdm='cd /mnt/Media/'
alias c='clear'
>>
>>55201699
>>55201743
Don't use echo, use printf.

>>55202048
Use #!/usr/bin/env bash.

>>55202413
>what is POSIX

>>55205376
>
alias c='clear'

CTRL+L
>>
>>55205624
I like c+enter
>>
colortest-skulls1()
{
f=3 b=4
for j in f b; do
for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m"
done
done
bld=$'\e[1m'
rst=$'\e[0m'
inv=$'\e[7m'
cat << EOF
$rst
$f1▄█ █▄ $f2▄█ █▄ $f3▄█ █▄ $f4▄█ █▄ $f5▄█ █▄ $f6▄█ █▄
$f1 ▄█████▄ $f2 ▄█████▄ $f3 ▄█████▄ $f4 ▄█████▄ $f5 ▄█████▄ $f6 ▄█████▄
$f1 █▄▄█▄▄█ $f2 █▄▄█▄▄█ $f3 █▄▄█▄▄█ $f4 █▄▄█▄▄█ $f5 █▄▄█▄▄█ $f6 █▄▄█▄▄█
$f1▄▄ █▀█▀█ ▄▄ $f2▄▄ █▀█▀█ ▄▄ $f3▄▄ █▀█▀█ ▄▄ $f4▄▄ █▀█▀█ ▄▄ $f5▄▄ █▀█▀█ ▄▄ $f6▄▄ █▀█▀█ ▄▄
$f1 ▀ ▀ $f2 ▀ ▀ $f3 ▀ ▀ $f4 ▀ ▀ $f5 ▀ ▀ $f6 ▀ ▀
$bld
$f1▄█ █▄ $f2▄█ █▄ $f3▄█ █▄ $f4▄█ █▄ $f5▄█ █▄ $f6▄█ █▄
$f1 ▄█████▄ $f2 ▄█████▄ $f3 ▄█████▄ $f4 ▄█████▄ $f5 ▄█████▄ $f6 ▄█████▄
$f1 █▄▄█▄▄█ $f2 █▄▄█▄▄█ $f3 █▄▄█▄▄█ $f4 █▄▄█▄▄█ $f5 █▄▄█▄▄█ $f6 █▄▄█▄▄█
$f1▄▄ █▀█▀█ ▄▄ $f2▄▄ █▀█▀█ ▄▄ $f3▄▄ █▀█▀█ ▄▄ $f4▄▄ █▀█▀█ ▄▄ $f5▄▄ █▀█▀█ ▄▄ $f6▄▄ █▀█▀█ ▄▄
$f1 ▀ ▀ $f2 ▀ ▀ $f3 ▀ ▀ $f4 ▀ ▀ $f5 ▀ ▀ $f6 ▀ ▀
$rst
EOF
}
>>
colortest-skulls2()
{
f=3 b=4
for j in f b; do
for i in {0..7}; do
printf -v $j$i %b "\e[${!j}${i}m"
done
done
rst=$'\e[0m'
bld=$'\e[1m'
inv=$'\e[7m'
cat << EOF
$rst
$f1 ▄▄▄▄▄▄▄ $f2 ▄▄▄▄▄▄▄ $f3 ▄▄▄▄▄▄▄ $f4 ▄▄▄▄▄▄▄ $f5 ▄▄▄▄▄▄▄ $f6 ▄▄▄▄▄▄▄
$f1▄█▀ ▀█▄ $f2▄█▀ ▀█▄ $f3▄█▀ ▀█▄ $f4▄█▀ ▀█▄ $f5▄█▀ ▀█▄ $f6▄█▀ ▀█▄
$f1█ █ $f2█ █ $f3█ █ $f4█ █ $f5█ █ $f6█ █
$f1███ ▄ ██ █ $f2███ ▄ ██ █ $f3███ ▄ ██ █ $f4███ ▄ ██ █ $f5███ ▄ ██ █ $f6███ ▄ ██ █
$f1█▄ ▄▄██ $f2█▄ ▄▄██ $f3█▄ ▄▄██ $f4█▄ ▄▄██ $f5█▄ ▄▄██ $f6█▄ ▄▄██
$f1 █▄█▄█▄██▀ $f2 █▄█▄█▄██▀ $f3 █▄█▄█▄██▀ $f4 █▄█▄█▄██▀ $f5 █▄█▄█▄██▀ $f6 █▄█▄█▄██▀
$bld
$f1 ▄▄▄▄▄▄▄ $f2 ▄▄▄▄▄▄▄ $f3 ▄▄▄▄▄▄▄ $f4 ▄▄▄▄▄▄▄ $f5 ▄▄▄▄▄▄▄ $f6 ▄▄▄▄▄▄▄
$f1▄█▀ ▀█▄ $f2▄█▀ ▀█▄ $f3▄█▀ ▀█▄ $f4▄█▀ ▀█▄ $f5▄█▀ ▀█▄ $f6▄█▀ ▀█▄
$f1█ █ $f2█ █ $f3█ █ $f4█ █ $f5█ █ $f6█ █
$f1███ ▄ ██ █ $f2███ ▄ ██ █ $f3███ ▄ ██ █ $f4███ ▄ ██ █ $f5███ ▄ ██ █ $f6███ ▄ ██ █
$f1█▄ ▄▄██ $f2█▄ ▄▄██ $f3█▄ ▄▄██ $f4█▄ ▄▄██ $f5█▄ ▄▄██ $f6█▄ ▄▄██
$f1 █▄█▄█▄██▀ $f2 █▄█▄█▄██▀ $f3 █▄█▄█▄██▀ $f4 █▄█▄█▄██▀ $f5 █▄█▄█▄██▀ $f6 █▄█▄█▄██▀
$rst
EOF
}
>>
Launch a program or focus existing window
app_exec=$1
if [ -z "$2" ] ;then
app_wm_class=$1
else
app_wm_class=$2
fi

if [ -z "`wmctrl -lx | grep $app_wm_class`" ]; then
$app_exec &
else
wmctrl -x -a $app_wm_class
fi


MKV to webm cut out + conversion
#!/bin/bash
# Usage: webm.sh 'file.foo' 'size in MB' "height" "from" "to"

source=$1
size=$2
height=$3 || "480"
from=$4
to=$5
tmp="cut.mkv"
threads=`nproc`

command="ffmpeg -hide_banner -i '$source' "
if [[ "$from" != "" ]]; then
ffmpeg+="-ss $from -to $to "
fi
command+="-c copy -y $tmp"
echo $command
eval $command

length=`ffprobe -i $tmp -show_format -v quiet | sed -n 's/duration=//p'`
bitrate=`bc -l <<< "$size / $length * 8"`M
common='ffmpeg -hide_banner -i $tmp -c:v libvpx -threads $threads -crf 4 -b:v $bitrate -vf scale=-1:${height} -y -f webm -pass'
eval $common '1 /dev/null &&' $common '2 "${source%.*}-${height}p_${from}_${to}_${size}MB.webm"'
rm ./ffmpeg2pass-0.log
rm $tmp
>>
>>55205735
Don't use backticks (``), use $().
Always quote variables.
It's a good idea to use -- when you work with rm and variables, this avoids problems when the variable changes to problematic things like "-rf"-
>>
File: 1459144428359.jpg (53 KB, 540x545) Image search: [Google]
1459144428359.jpg
53 KB, 540x545
>>55205624
>use printf
>>
>>55205782
Don't be retarded. printf is more portable and more secure than echo. Some echo implementations even have different or missing options.
>>
File: scrot612.png (2 MB, 1920x1200) Image search: [Google]
scrot612.png
2 MB, 1920x1200
https://github.com/onodera-punpun/neet

neet - A script to easily play and manage your anime/drama/series
>>
>>55205763
Why? $() is supposed to be slower, because it spawns a subshell.

The variables passed to rm are guaranteed to be fine, because they don't depend on user input.
>>
>>55205823
No, $() executes just like ``, but makes nesting more easy.
() (without $) spans a subshell.
>>
File: 1435025490356.jpg (32 KB, 329x300) Image search: [Google]
1435025490356.jpg
32 KB, 329x300
>>55205800
>printf is more portable and more secure than echo
>>
File: scrot613.png (180 KB, 622x426) Image search: [Google]
scrot613.png
180 KB, 622x426
>>55205815
https://github.com/onodera-punpun/bin/blob/master/lrnhira
https://github.com/onodera-punpun/bin/blob/master/lrnkata

lrnhira - Learn hiragana in the terminal.
lrnkata - Learn katakana in the terminal.
>>
hex2rgb() {
printf '%d %d %d\n' "0x${1:0:2}" "0x${1:2:2}" "0x${1:4:2}"
}

rgb2hex() {
printf '%02X%02X%02X\n' "$1" "$2" "$3"
}
>>
File: scrot614.png (18 KB, 787x528) Image search: [Google]
scrot614.png
18 KB, 787x528
>>55205853
https://github.com/onodera-punpun/bin/blob/master/spurdo

spurdo - Spurdofy text
>>
>>55205815
Are you employed?
>>
>>55205888
Yeah I am, even if I wasn't, writing scripts and learning linux/unix commands is still an infinity more productive hobby that playing video games for example.
>>
>>55205902
Can't argue against that.
I myself am writing some low tier bash scripts, mostly one purposed stuff though.
I asked cause I remember you from years ago in the desktop threads (you're the guy with openbox / lemonbar, right?) and IRC where it seems you were living at your parents place hence my strange question.

Your thick titleless titlebars were one of my inspirations tho, I guess I should thank you for that.

Out of curiosity, what's your job?
>>
>>55205815
>neet
>doesn't have an -o option

You blew it.
>>
>>55205884
too bad its for the fish shell and it doesnt work in bash or zsh :DDDD
>>
>>55206090
It has a shebang so it works in every shell, that's like saying python scripts don't work when you use bash. You just need to have fish installed.
>>
>>55206168
i gnow XDD XDD btw i doesnd matter anymore begauze i found a c++ implemendation of de egzact same dign XDD (dis sendence was gonverted wid:)

https://github.com/Pr0Wolf29/libspurdoxx
>>
>>55206233
oh dat's bredty gool actually :DDD shame that id's sum library inztead of juzt a program :-D
>>
>>55201699
curl curlmyip.com
>>
>>55201699
Use
curl curlmyip.com
instead
>>
>>55206367
connection refused.
>>
>>55206411
>>55206367
It's .org, faggot.
>>
>>55205815
>fish script
Fuck man, I'm used to bash's line noise now. And I'm starting to like perl too. Help.
>>
>not using ksh
>>
>>55208600
>using ksh
>>
>>55208600
>not using xonsh
>>
>>55205800
>secure
Kek
>>
>>55205657
I'm not familiar with this bash script

how do i execute it?
>>
extract () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 ;;
*.tar.gz) tar xvzf $1 ;;
*.bz2) bunzip2 $1 ;;
*.rar) unrar x $1 ;;
*.gz) gunzip $1 ;;
*.tar) tar xvf $1 ;;
*.tbz2) tar xvjf $1 ;;
*.tgz) tar xvzf $1 ;;
*.zip) unzip $1 ;;
*.Z) uncompress $1 ;;
*.7z) 7z x $1 ;;
*) echo "don't know how to extract '$1'..." ;;
esac
else
echo "'$1' is not a valid file!"
fi
}


EXTRACT THEM ALL
>>
>>55209212
This semicolons triggered me
>>
>>55206411
Thank
>>
>>55209321
I found this on SO
>>
>>55209321
you must not ike C or perl
>>
>>55201785
Damn this made my ubuntu inbstall even faster, thanks m8
>>
>>55201964
awesome!
>>
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'
alias .......='cd ../../../../../..'
>>
>>55204454
# User specific aliases and functions
alias ..="cd ../"
alias ...="cd ../../"
alias ....="cd ../../../"
alias .....="cd ../../../../"
alias ......="cd ../../../../../"
alias .......="cd ../../../../../../"
#for l337 hakkking
alias SHOCK2TH3SYSTEM="export GREP_COLOR='1;32'; cat /dev/urandom | hexdump -C | grep --color=auto \"ca fe\""
>>
>>55201699
But how do i know your not doing any voodoo to my pc when i run it?!
>>
>>55209189
Save into your ~/.bashrc
Restart terminal
Enter colortest-skulls1
>>
>>55209960
Because you can clearly see what the code is doing?
>>
>>55209960
You caught me
>>
http://pastebin.com/5cAk2HfR

I have a Python one too.
>>
one I got from a previous /g/ thread, and haven't even yet.
#!/bin/bash
for a in ./*.flac; do
ffmpeg -i "$a" -qscale:a 0 "${a[@]/%flac/mp3}"
done

Also check out fred's imagemagick scripts if you like to play with imagemagick.
http://www.fmwconcepts.com/imagemagick/index.php
>>
>>55211292
Oh yeah, also here you guys go
#!/bin/bash

#This script prints the VPNBook public username and password

#By Enigma

wget -q http://www.vpnbook.com/freevpn
cat freevpn | grep Username: | sed -e '1d' | cut -d ">" -f 3 | cut -d "<" -f 1
cat freevpn | grep Password: | sed -e '1d' | cut -d ">" -f 3 | cut -d "<" -f 1
rm freevpn
>>
Not a script, but a .bashrc thing, sub in your own CDPATH stuff
# set CDPATH in interactive shells, without exporting it to noninteractive scripts
if test “${PS1+set}”; then CDPATH="$HOME/:$HOME/Documents/:$HOME/Music/:$HOME/Pictures/:$HOME/Pictures/Camera/:$HOME/Pictures/Wallpaper/:$HOME/Videos/";fi
>>
>>55209212
>>55209321
Doesn't this look much much cleaner

function extract
if test -f $argv
switch $argv
case "*.tar.bz2"
tar xvjf $argv
case "*.tar.gz"
tar xvzf $argv
case "*.bz2"
bunzip2 $argv
case "*.rar"
unrar x $argv
case "*.gz"
gunzip $argv
case "*.tar"
tar xvf $argv
case
"*.tbz2"
tar xvjf $argv
case "*.tgz"
tar xvzf $argv
case "*.zip"
unzip $argv
case "*.Z"
uncompress $argv
case "*.7z"
7z x $argv
case "*"
echo "don't know how to extract '$argv'..."
end
else
echo "'$argv' is not a valid file!"
end
end
>>
Nifty one liner to show cpu and mem % the stuff running on your display is using.
ps -o pid,comm,pmem,pcpu,uname -C $(xlsclients | cut -d" " -f3 | paste - -s -d ',')
>>
How I $DIRSTACK like a boss.
alias p='pushd' +='pushd .' -='popd' d='dirs -v -l' x='dirs -c'
>>
Does no clear ALT+F2 command history option in cinnamon make you really, really mad?
apt-get install dconf-cli
alias F2clear='dconf reset /org/cinnamon/command-history'
Thread replies: 75
Thread images: 6

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.