Post your Command line tricks

Forum rules
Share your brain ;)
User avatar
Alad
should take a shower
Posts: 447
Joined: Wed May 21, 2014 12:52 am

Re: Post your Command line tricks

Unread post by Alad » Tue Jun 03, 2014 7:28 pm

^ Just in time *splat*

Code: Select all

alias rotmuggen='play -n synth sine 20k'
Thanks :)
It's funny how we used to be able to do real stuff with rudimentary computers, but now we can't. -- ratcheer

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Post your Command line tricks

Unread post by rhowaldt » Wed Jun 04, 2014 9:13 am

^ rotmuggen :D
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Post your Command line tricks

Unread post by pidsley » Thu Jun 12, 2014 12:04 am

Maybe old knowledge, but I just learned that vim can browse tar archives.

Code: Select all

$ vim <file.tar.gz>
You can even drill down to individual files and open them.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Thu Jun 12, 2014 7:16 am

^ That's really handy, I didn't know that.
be useful to help extract them in conjunction with the !command i guess.
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5878
Joined: Tue Sep 03, 2013 7:05 am

Re: Post your Command line tricks

Unread post by GekkoP » Thu Jun 12, 2014 9:15 am

^^ very useful!

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Thu Jun 12, 2014 9:47 am

Trollbacon has to mention the Tarmode of Emacs, in this case: http://www.emacswiki.org/emacs/TarMode

Can basically do the same, like in dired.
..gnutella..

User avatar
Alad
should take a shower
Posts: 447
Joined: Wed May 21, 2014 12:52 am

Re: Post your Command line tricks

Unread post by Alad » Sun Jul 13, 2014 11:16 pm

Dynamic titles for urxvt/xterm like in tmux; add to ~/.bashrc

Code: Select all

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
	PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'

	# Show the currently running command in the terminal title:
	# http://www.davidpashley.com/articles/xterm-titles-with-bash.html
	show_command_in_title_bar() {
	case "$BASH_COMMAND" in
	*\033]0*)
		# The command is trying to set the title bar as well;
		# this is most likely the execution of $PROMPT_COMMAND.
		# In any case nested escapes confuse the terminal, so don't
		# output them.
		;;
	*)
		echo -ne "\e]0;"
		echo -n "$BASH_COMMAND"
		echo -ne "\007"
		;;
	esac
    	}

	trap show_command_in_title_bar DEBUG
	;;
*)
	;;
esac
http://mg.pov.lt/blog/bash-prompt.html
It's funny how we used to be able to do real stuff with rudimentary computers, but now we can't. -- ratcheer

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Mon Jul 14, 2014 12:46 am

^ great, thanks Alad!
..gnutella..

User avatar
Alad
should take a shower
Posts: 447
Joined: Wed May 21, 2014 12:52 am

Re: Post your Command line tricks

Unread post by Alad » Tue Sep 02, 2014 3:06 am

Small tip if you have a delay when switching between X and TTYs, and use a newer Intel GPU:

Code: Select all

/etc/X11/xorg.conf.d/20-intel.conf
----
Section "Device"
   Identifier  "Intel Graphics"
   Driver      "intel"
   Option      "AccelMethod"  "glamor"
EndSection
(source)
It's funny how we used to be able to do real stuff with rudimentary computers, but now we can't. -- ratcheer

User avatar
z3bra
Window Manager
Posts: 53
Joined: Fri Jun 27, 2014 8:34 am
Location: France
Contact:

Re: Post your Command line tricks

Unread post by z3bra » Wed Sep 03, 2014 9:13 am

Need a to test a quick C snippet ?

Code: Select all

~ $ alias cquick="echo '#include \"/dev/stdin\"'; cc a.c; ./a.out"
~ $ cquick
#include <stdio.h>
int
main ( void )
    {
    printf ( "Hello, world!\n" );
    return 0;
    }
Hello, world!
Upon compilation, you'll be able to type your program to stdin. Once you're done, press ^D and the program you just typed will compile to "a.out" and start it.
BANGARANG, MOTHERFUCKER.

User avatar
z3bra
Window Manager
Posts: 53
Joined: Fri Jun 27, 2014 8:34 am
Location: France
Contact:

Re: Post your Command line tricks

Unread post by z3bra » Wed Sep 03, 2014 11:01 am

Another fine trick is the use of the "base64" tool to upload any file to a pastebin, like this:

Code: Select all

base64 random_file.tar.gz | curl -sF 'sprunge=<-' http://sprunge.us
This command will upload your base64'd file as plain text, and give you the URL to access it. You will then be able to download it as such:

Code: Select all

curl -s http://sprunge.us/XXXX | base64 -d > download_file.tar.gz
Or even quicker (in this case)

Code: Select all

curl -s http://sprunge.us/XXX | base64 -d | gunzip - | tar cvf -
BANGARANG, MOTHERFUCKER.

User avatar
johnraff
Sperminator
Posts: 199
Joined: Wed Oct 17, 2012 6:38 pm
Location: Japan
Contact:

Re: Post your Command line tricks

Unread post by johnraff » Wed Sep 10, 2014 5:13 am

(Hi again Image )
Shuffle an array.
I googled this but all the solutions seemed overcomplicated. If you have 'shuf' available, then the simplest way seemed to be to shuffle the indices of the array, not the elements. The indices are just simple integers, so the array elements can contain anything - spaces, line breaks, whatever. You could shuffle paragraphs of text for example (Rhowaldt?)

Only limitation - you can't shuffle the array in place, you have to make a new shuffled one - rename it later if you want.
A is the original array, B is the shuffled one:

Code: Select all

for i in $(shuf -e ${!A[@]});do B+=("${A[$i]}");done
Thanks to Pidsley for pointing out the -e option for shuf in his random mp3 stick filler.

If you just want to spit out the shuffled elements:

Code: Select all

for i in $(shuf -e ${!A[@]});do echo "${A[$i]}";done
or whatever.
All code is one.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Wed Sep 10, 2014 6:09 pm

Thanks for the input guys, as you know, take me away from the browsers built in spelling thing, and i'm a bit lost.
having trouble:

Code: Select all

aspell -a
puts it in interactive mode, so i can type my spazzy word; nessaccery - for example - and it pops out with all the variations it can thing of:
wux wrote:wux@chauvin:~$ aspell -a
@(#) International Ispell Version 3.1.20 (but really Aspell 0.60.7-20110707)

nessacary
& nessacary 12 0: NASCAR, necessary, scary, descry, massacre, Nescafe, sacra, NASCAR's, mascara, scare, cascara, sugary
I think you can pipe the word in, but you'd need echo or something, then write a bash function, yadahyada...
"Seek, and Ye shall find"
"Github | Chooons | Site"

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Wed Sep 10, 2014 6:24 pm

Code: Select all

function gal() { find . -iname "*.jpg" -o -iname "*.png" -printf '<img src="%f" title="%f">\n' > gallery.html ;}
creates a html gallery of all png/jpg image files in the directory it is run.
..gnutella..

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Thu Sep 11, 2014 7:33 am

Runaway find process hogging your i/o?

Code: Select all

ionice -c3 -p `pidof find`
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
Alad
should take a shower
Posts: 447
Joined: Wed May 21, 2014 12:52 am

Re: Post your Command line tricks

Unread post by Alad » Fri Sep 12, 2014 2:03 pm

Find out an IP or hostname's location:

Code: Select all

ipif() { 
	if grep -P "(([1-9]\d{0,2})\.){3}(?2)" <<< "$1"
	then
		curl ipinfo.io/"$1"
	else
		ipadd=$(host "$1") &&
		ipawk=$(awk '{ print $4 }' <<< "$ipadd")
		curl ipinfo.io/"$ipawk"
	fi
	echo
}
PS: I suck at regex

edit: got some help from wei2912 - note that neither pattern works with bash =~, so I went with grep -P. If you want details, ask him. :P

edit9000: ugh
Last edited by Alad on Fri Sep 12, 2014 3:15 pm, edited 6 times in total.
It's funny how we used to be able to do real stuff with rudimentary computers, but now we can't. -- ratcheer

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Post your Command line tricks

Unread post by rhowaldt » Fri Sep 12, 2014 2:19 pm

^ hahaha, you really suck at rege... oh wait you said that already.
okay i agree there is probably a shorter solution for that regex line, but i really cant be arsed to figure it out. if it works, it works :)
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Fri Sep 12, 2014 11:24 pm

Code: Select all

Ragex
"Seek, and Ye shall find"
"Github | Chooons | Site"

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Post your Command line tricks

Unread post by machinebacon » Sat Sep 13, 2014 2:51 am

Code: Select all

geoip(){ curl freegeoip.net/xml/$1; }
take it easy ;) limited to 10'000 queries per hour
..gnutella..

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Post your Command line tricks

Unread post by wuxmedia » Sat Sep 13, 2014 9:19 am

or the slightly more convoluted:

Code: Select all

<install> geoip-database 
then:

Code: Select all

geoiplookup <ip>
yeah -linux! Ten million ways to find out an IP
"Seek, and Ye shall find"
"Github | Chooons | Site"

Post Reply