Post your *nix trix...

Soldato
Joined
8 Mar 2006
Posts
13,300
Location
Near Winchester
While I consider myself a GNU/Linux guru, I still learn new things all the time. This is a thread where I'd like you all to post a nifty command/technique you've picked up. Not how to get nVidia dual screen to work, but something small that you use often. There's only one rule; no more than one line of code per post.

I'll start us off:

mv supports embedded substitution, this can be useful when renaming a file:
Code:
mv /any/old/file{,.backup}
The substitution is inside the curly braces, replace the bit before the comma (nothing) with the bit after the comma (".backup"). This also works with cp.
 
Last edited:
Nice idea :)

Ctrl+R to search through bash history in a shell, saves a lot of time if you don't know it :)

Also last night I found something called Devils Pie for Gnome. Basically it lets you define scripts that intercept window creation and let you do things like minimize, maximize or set the geometry of the window. I used it to enforce Chrome to start on my second screen which was seemingly impossible otherwise :D

Code:
(if
	(is (application_name) "chromium")
		(begin
			(unmaximize)
			(geometry "640x480+1920+0")
			(maximize)
		)
)


Oops I broke the one line rule :(
 
To see what program is using the sound server. This is important for me as I use optical out which requires exclusive use and so I run this if something is hogging the output..

fuser -v /dev/snd/*

To neatly restart pulseaudio..

pulseaudio -k; sleep 4; pulseaudio -D
 
I used it to enforce Chrome to start on my second screen which was seemingly impossible otherwise :D

Another no less correct method is to use the compiz "place window" plugin.





grep can show you lines after and before the matching lines:
Code:
user@hostname ~ $ grep -B1 -A2 sometext /any/old/file
hello bob
have you seen sometext anywhere
yes
I have
 
Last edited:
gotta have the hammer to crack a nut:

Separate a column in a commands output by piping it into awk:
Code:
tail /var/log/messages | awk '{print $2}'
The delimiter between the columns is whitespace, but you can set it to anything with the -F parameter on awk.

sed can do this too, but I like awk.
 
If you type a huge amount out yet forget to 'sudo' at the start.

Just type 'sudo !!' instead of typing it out again or backspacing.
 
Get a file's contents suitable for embedding in a C program:

Code:
$ xxd -i smile.gif
Code:
unsigned char smile_gif[] = {
  0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x0f, 0x00, 0x0f, 0x00, 0xd5, 0x00,
  0x00, 0xf7, 0xd7, 0x00, 0xf3, 0xd3, 0x00, 0xed, 0xcd, 0x00, 0xea, 0xca,
  0x00, 0xe3, 0xc3, 0x00, 0xe0, 0xc1, 0x00, 0xde, 0xbe, 0x00, 0xd8, 0xb9,
  0x00, 0xd3, 0xb4, 0x00, 0xd1, 0xb2, 0x00, 0xd0, 0xb1, 0x00, 0xcd, 0xae,
  0x00, 0xc1, 0xa3, 0x00, 0xc6, 0xa7, 0x00, 0xc5, 0xa6, 0x00, 0xc0, 0xc0,
  0xc0, 0xbc, 0x9e, 0x00, 0xb9, 0x9b, 0x00, 0xb6, 0x98, 0x00, 0xb5, 0x97,
  0x00, 0xb1, 0x93, 0x00, 0xad, 0x8f, 0x00, 0xac, 0x8e, 0x00, 0xaa, 0x8d,
  0x00, 0xa9, 0x8c, 0x00, 0xa2, 0x85, 0x00, 0xa5, 0x87, 0x00, 0xa0, 0x82,
  0x00, 0x9f, 0x82, 0x00, 0x9d, 0x7f, 0x00, 0x99, 0x7c, 0x00, 0x94, 0x77,
  0x00, 0x92, 0x75, 0x00, 0x90, 0x74, 0x00, 0x8d, 0x71, 0x00, 0x8e, 0x71,
  0x00, 0x89, 0x6c, 0x00, 0x89, 0x6d, 0x00, 0x88, 0x6b, 0x00, 0x85, 0x68,
  0x00, 0x82, 0x66, 0x00, 0xbf, 0xbf, 0xbf, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x21, 0xf9, 0x04, 0x01, 0x00, 0x00, 0x0f, 0x00, 0x2c, 0x00, 0x00,
  0x00, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x00, 0x06, 0x94, 0xc0, 0x87, 0x50,
  0xa8, 0x2a, 0x16, 0x87, 0xc8, 0x47, 0xd1, 0x70, 0x50, 0x34, 0x20, 0x47,
  0xa4, 0x6a, 0x20, 0x18, 0x10, 0x0e, 0x0b, 0x86, 0x04, 0xa3, 0x1a, 0x4e,
  0x03, 0x80, 0xc0, 0xc0, 0x90, 0x70, 0x44, 0x2c, 0x9c, 0xae, 0x52, 0x00,
  0x28, 0x0a, 0x0a, 0x88, 0x62, 0x65, 0xd3, 0x55, 0x19, 0x06, 0x81, 0xe2,
  0x38, 0x51, 0x44, 0x83, 0x8a, 0x07, 0x04, 0x54, 0x56, 0x58, 0x5a, 0x18,
  0x1d, 0x21, 0x45, 0x0a, 0x07, 0x06, 0x05, 0x4c, 0x4e, 0x10, 0x14, 0x1a,
  0x1e, 0x22, 0x45, 0x0d, 0x0b, 0x09, 0x08, 0x09, 0x0b, 0x4f, 0x13, 0x17,
  0x1c, 0x1f, 0x25, 0x45, 0x10, 0x0c, 0x2a, 0x0d, 0x0e, 0x0c, 0x10, 0x13,
  0x16, 0x19, 0x2a, 0x23, 0x27, 0x75, 0x12, 0x11, 0x2a, 0x11, 0x12, 0x14,
  0x17, 0xad, 0x21, 0x26, 0x6a, 0x2a, 0x18, 0x16, 0x15, 0x46, 0x45, 0x21,
  0x24, 0x28, 0x6a, 0x4a, 0x1c, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x23, 0x26,
  0xc5, 0x49, 0x45, 0x20, 0x21, 0x22, 0x25, 0xb0, 0xc6, 0xd1, 0xc1, 0x49,
  0x41, 0x00, 0x3b
};
unsigned int smile_gif_len = 375;
 
Get a file's contents suitable for embedding in a C program:

Code:
$ xxd -i smile.gif

That's really cool!

Here is mine

Code:
GST_DEBUG_DUMP_DOT_DIR=/tmp gst-launch-0.10 playbin2 uri=/home/brendan/yourMediaFile

This will dump in /tmp .dot files (graphviz files), that you can render with dot like so :
Code:
dot -Tpng 0.00.00.*PAUSED_PLAYING.dot > yourGstreamerPipeline.png

You'll end with up with the whole gstreamer pipeline draw out for you so you can see what element get selected etc... Great for debugging or even just understand complex elements like playbin2, decodebin etc...
 
Back
Top Bottom