Bash one-liners

|

Here are a few bash one-liners that you may find useful. All are written by me unless otherwise noted.

This one converts the symbolic permissions to octal (ie: numbers) when using 'ls -l':

ls -l | sed -e 's/rwx/7/g' -e 's/r--/4/g' -e 's/r-x/5/g' -e 's/rw-/6/g' -e 's/---/0/g'

Running in your home directory you may see something like:

total 1637
d700 3 bulliver wheel 128 Oct 3 2003 Desktop
d700 11 bulliver wheel 1296 Jun 14 15:02 Mail
-644 1 bulliver users 1015742 Jun 13 15:05 TICPP-2nd-ed-Vol-two.zip
d755 4 bulliver users 232 Jun 13 02:06 assembly_utils
d755 2 bulliver users 1712 Jun 12 02:01 c
d755 2 bulliver users 656 Jun 7 14:26 c++
-600 1 bulliver users 252785 Jun 7 23:25 channels.txt
d755 3 bulliver users 328 May 24 21:30 dir2ogg
-644 1 bulliver users 6451 May 30 00:08 dmesg.txt
d755 2 bulliver users 136 Jun 9 12:45 iso
d755 2 bulliver wheel 1352 Jun 8 14:24 kernels
d755 22 bulliver wheel 1624 Jun 13 18:40 local_docs
d755 2 bulliver users 216 Sep 23 2003 minix
d755 2 bulliver users 456 Jun 9 11:58 pdf
d755 2 bulliver users 320 Jun 13 23:43 perl
d755 4 bulliver users 1016 Jun 13 19:25 python
-644 1 bulliver users 154713 Jun 10 00:15 shot0001.jpg
-644 1 bulliver users 22252 Jun 11 00:29 snake.asm
d755 6 bulliver users 488 May 18 03:10 source
d755 6 bulliver wheel 208 May 3 15:26 xml

Here's one to find your IP address. It was not written by me, I gleamed it from linuxquestions.org. I will try and credit the author here soon:

lynx -dump http://whatismyip.com | awk '/Your/ {print $4}'

These next two match email addresses and hypertext links respectively:

grep -o "[-_a-z0-9\.]*@[-_a-z0-9\.]*\..\{2,3\}" file grep -o "http://[-_a-z0-9\.]*\..\{2,4\}[-_a-z0-9\.]*" file

We can use this to, say, grab the email address of all the kernel maintainers (please don't spam them...):

grep -o "[-_a-z0-9\.]*@[-_a-z0-9\.]*\..\{2,3\}" /usr/src/linux/MAINTAINERS | sort | uniq

or get all the slashdot article links without going to slashdot:

lynx --dump http://slashdot.org | grep -o "http://[-_a-z0-9\.]*\..\{2,4\}[-_a-z0-9\.]*" | sort | uniq | grep -v slashdot.org

このブログ記事について

このページは、ossanが2011年2月10日 15:26に書いたブログ記事です。

ひとつ前のブログ記事は「Linux Links」です。

次のブログ記事は「quick and dirty guides」です。

最近のコンテンツはインデックスページで見られます。過去に書かれたものはアーカイブのページで見られます。