Alternative of OJM snippet : This one show the IP too, where ports bind. It's very important, because if there's only 127.0.0.1 instead of 0.0.0.0, connections from internet are rejected.
For fancier and cleaner output, try the following snippet :
showendlines(){ while read i; do od --address-radix=n --width=$(wc -c <<< "$i") -c <<< "$i" | perl -pe 's/.\K\s{2,3}//g'; done < $1 | grep --color '\\.'; }
Now you can run that with :
showendlines <FILE>
Thanks to prince_jammys to "debug" my English ;)
Require "grep -P" ( pcre ).
If you don't have grep -P, use that :
grep -Eo '"url":"[^"]+' $(ls -t ~/.mozilla/firefox/*/sessionstore.js | sed q) | cut -d'"' -f4
This is a joke for @putnamhill and @glaudiston I'm pretty sure we can write longer if we want ;)
No problem with word splitting. That should works on many Unix likes. Show Sample Output
No need $_ netp ;)
For vi(m) users : Add it in your ~/.bashrc Add an "exit" @ the end if you are masochist ;) Show Sample Output
@putnamhill, no need if statement in that case. && is a AND and || is a OR
Like the tiltle said, you can use an argument too ( the interface )
MyIps eth0
will show only the IP of this interface and the public IP
( tested with Linux )
You can add that function in ~/.bashrc, then
. ~/.bashrc
Now you are ready to call this function in all your terms...
Show Sample Output
Especially for sysadmins when they don't want to waste time to add -p flag on the N processes of a processname.
In the old school, you did ;
pgrep processname
and typing strace -f -p 456 -p 678 -p 974...
You can add -f argument to the function. That way, the function will deal with pgrep to match the command-line.
Example :
processname -f jrockit
I modify 4077 and marssi commandline to simplify it and skip an error when parsing the first line of lsmod (4077). Also, it's more concise and small now. I skip using xargs ( not required here ). This is only for GNU sed.
For thoses without GNU sed, use that :
modinfo $(lsmod | awk 'NR>1 {print $1}') | sed -e '/^dep/s/$/\n/g' -e '/^file/b' -e '/^desc/b' -e '/^dep/b' -e d
That makes a function you can put in your ~/.bashrc to run it when you need in any term with an IP as argument Show Sample Output
An other way to run it ( playing a random file ending with avi, flv or mpeg ) from a specified dir and a specified type of extension :
making MOVIE array with a glob :
MOVIE=( /PATH/TO/MY/FAVORITE/MOVIES/*.{avi,flv,mpeg} )
playing the random file from a random key from the array
mplayer ${MOVIE[ RANDOM % ( ${#i[@]} + 1 ) ]]}
I use only globs and a bash array.
I use GNU bash, version 3.2.48
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: