Showing posts with label cygwin. Show all posts
Showing posts with label cygwin. Show all posts

Wednesday, January 13, 2016

More day to day one liners


List directories and sort them by largest:


du -hcx –max-depth=5 | grep [0-9]G | sort -rnk1,1

This goes to a depth of 5 directories and sorts largest, only if they are in gigs, and takes into account decimals.

If you need more drive space, you can reduce your reserve space, but you probably don't want to reduce that space to 0 their is a chance your system could grind to a halt. To reduce reserve space to 2 percent:

sudo tune2fs -m 2 /dev/sda1

Now if you need to check what your reserve space is currently set at:

sudo dumpe2fs -h /dev/sda1 2> /dev/null | awk -F ':' '{ if($1 == "Reserved block count") { rescnt=$2 } } { if($1 == "Block count") { blkcnt=$2 } } END { print "Reserved blocks: "(rescnt/blkcnt)*100"%" }'

I didn't write that one, I first encountered it at a hosting gig, but I had to look it up and found it at commandlinefu.

Parsing an html table using perl:

perl -pe "s/.*<tr><th><b>(.*): <\/b><\/th><th.*<\/th><td>(.*)<\/td><\/tr>/\"\1\":\"\2\"/gi"

I'm not going to explain this one, because I wrote it a long time ago and it's perl regex so I would essentially have to rewrite it to understand it.


I have another list of one liners, particularly related to hosting.

Wednesday, March 9, 2011

Favorite way to regex a file using perl

Sometimes you want to do some magic fu on your file, while it's not loaded in a vim buffer. This is what I use with perl. I know there is probably a way to do this with sed, but I couldn't find it quickly enough. Most of the time when I do a search and replace out side of vim I want to replace something that's already in the file, with itself in a different position. For example:

I want to replace variablewordspace with variablewordtime, so in the file var.txt I have:

variablewordspace
hammerspace

So what I would do is:


cat var.txt | perl -pe 's/(\w+)space/\1time/'

which would give me the output:


variablewordtime
hammertime



For a brief description:
You are display the file var.txt, through the cat command. Then using the pipe (|) you are passing that to perl, with the switches p and e. Switch e allows you to run from the command line without explicitly writing a perl program, while switch p allows you to run a program against every line on standard input, and prints whatever is in $_ after each line. A search and replace using s/// with the search term in the first set of slashes

/(\w+)space/

The parentheses mark that as a group.

The \w+ means any number of word characters, as where the 'space' just represents the word space.

In the last set of slashes is what you want to replace it with.

/\1time/

\1 represents what is in that first set of parenthesis.

And time of course, represents the letters 'time'

Thursday, January 13, 2011

Simple Stupid Linux Tricks ssh port forwarding

At work I'm firewalled in, and I'm on a linux server...however they allow traffic over port 22. So it's really easy to get to meebo. You can do this with most sites, however if they require more than one port you'll need a more complex solution.

I fire up cygwin and type this in.(You can use any ssh client though)


ssh -L 8888:meebo.com:80 root@wereboobs.com -N

ssh creates a tunnel from me to wereboobs, which the proxy doesn't care about to meebo which the proxy does(ironic, no?). So now if I type localhost:8888 into my browser I can get to meebo without going through the web proxy. Bonus...the web traffic from meebo is encrypted until it reaches wereboobs.

Friday, December 19, 2008

Stupid nix trix: Making awful noises, or testing your speakers in linux

Because everything in linux / Unix / MacOS X is a file, you can do some interesting things with devices, like send data straight to them. Your sound card is typicaly denoted by /dev/dsp. There is another file that is a (pseudo)random number generator and it is /dev/random or /dev/urandom. There is also a program that has a primary purpose of the low-level copying and conversion of raw data. So you can pipe garbage to your soundcard with this:

dd if=/dev/urandom of=/dev/dsp
or
sudo dd if=/dev/urandom of=/dev/dsp

This will work in cygwin as well.