sed -n 's/stuff\(.*\)more stuff/\1/p'
This will only show the data matched by the parenthesised expression.
The following example shows only unique filenames leaving out paths:
find . -iname "*file*"| sed -n 's/.*\/\(.*\)$/\1/p' | sort | uniq | less
Thursday, December 8, 2011
Tuesday, November 29, 2011
The watch command
Wow, what a useful command I just learned of.
Watch executes any task at a given interval, like a hassle-free on the fly cron job.
For instance to display your arp table and refresh every 10 seconds:
watch -n 10 arp -a
Watch executes any task at a given interval, like a hassle-free on the fly cron job.
For instance to display your arp table and refresh every 10 seconds:
watch -n 10 arp -a
Thursday, November 3, 2011
Mass file renaming
I just learned that Linux's rename command can use regular expressions to substitute file name parts.
(-v tells you what was renamed)
rename -v 's/FROM/TO/g' *
This will replace the word FROM to the word TO in all file names.
(-v tells you what was renamed)
rename -v 's/FROM/TO/g' *
This will replace the word FROM to the word TO in all file names.
Wednesday, October 5, 2011
Make inplace changes with sed
If you want sed to actually make changes to a file, not just show the output on stdout, use the -i option. If you add an extension, it will be used to create a backup of the file before changing it.
-i is inline
-i.bak (No space) will make a .bak
sed -i.bak 's/findthis/changetothis/' myfile
-i is inline
-i.bak (No space) will make a .bak
sed -i.bak 's/findthis/changetothis/' myfile
Monday, September 26, 2011
Send signal to dd to view progress
If you start dd and want to see how far its progressed send it a USR1 signal.
The loop shown doesn't work for me, but this does "sudo killall -USR1 dd" albeit not in a loop. There is also some similar documentation in the man page for dd (or the help page one).
The loop shown doesn't work for me, but this does "sudo killall -USR1 dd" albeit not in a loop. There is also some similar documentation in the man page for dd (or the help page one).
Wednesday, August 31, 2011
One line web server using Python
Python 2.x:
python -m SimpleHTTPServer
Python 3.x: *
python -m http.server 8000
From http://www.garyrobinson.net/2004/03/one_line_python.html
*The 3.x option doesn't work for me as I have no "http" module, but I can use:
python -m BASEHTTPServer instead, pydoc -k http will show all modules with http in the name.
Monday, August 15, 2011
Great Android programming video
It's two hours long, and over a year old so may be getting out of date, but this is really good.
Youtube video
Youtube video
Friday, July 29, 2011
USB Sniffing
This page details how to sniff usb data in Linux. Under Ubuntu some things have changed. You can use lsusb to see the USB information for your devices, and the folder under /sys has changed to /sys/kernel/debug/usb/usbmon
Monday, July 11, 2011
Transparent backgrounds with CSS
Simple method:
#lightbox {
background: white;
border: 20px solid rgba(0,0,0,0.3);
}
There may be more to it depending on what you want to accomplish
(where does the transparency begin and end?):
http://css-tricks.com/7423-transparent-borders-with-background-clip/
Friday, July 8, 2011
Disable broken scrollbars in Ubuntu 11.04
The code below willsupposedlystart applications that don't work
with the new Ubuntu 11.04 overlay scrollbar (such as eclipse),
without the scrollbar.
LIBOVERLAY_SCROLLBAR=0 /usr/bin/program_to_run
Thursday, July 7, 2011
Monitor the light sensor in Android
Haven't tried it yet, but
From this post
Only two files:
Code:
And layout:
From this post
Only two files:
Code:
package com.exercise.AndroidLightSensor;
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
public class AndroidLightSensor extends Activity {
SensorManager mySensorManager;
Sensor myLightSensor;
TextView textLightSensorData;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textLightSensor = (TextView)findViewById(R.id.lightsensor);
textLightSensorData = (TextView)findViewById(R.id.lightsensordata);
mySensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
myLightSensor = mySensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
if (myLightSensor == null){
textLightSensor.setText("No Light Sensor!");
}else{
textLightSensor.setText(myLightSensor.getName());
mySensorManager.registerListener(lightSensorEventListener,
myLightSensor,
SensorManager.SENSOR_DELAY_NORMAL);
}
}
SensorEventListener lightSensorEventListener
= new SensorEventListener(){
@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent arg0) {
// TODO Auto-generated method stub
if(arg0.sensor.getType()==Sensor.TYPE_LIGHT){
textLightSensorData.setText("Light Sensor Date:"
+ String.valueOf(arg0.values[0]));
}
}};
}
And layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:id="@+id/lightsensor"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/lightsensordata"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
Monday, July 4, 2011
Satisfying depdencies when building from source
If a source package has a Make file with "make install" functionality, running the command "check install" will generate a pseudo package for you that will install all required dependencies and after building the package can be used to remove all dependencies. What a find!
Handy tips
I just realized that a good way to remember the tips and things I come across that I have no place to put them, yet I realize I will never remember them when I actually need to use them, is to create a blog. So here we are. (I am thinking of Linux stuff, but anything will work).
Subscribe to:
Posts (Atom)