commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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:
Works only on Linux.
Last option (n) turn name of service resolving (/etc/services) off.
or you can add "-x" to get a typical hexdump like output
USAGE: gate listening_port host port
Creates listening socket and connects to remote device at host:port. It uses pipes for connection between two sockets. Traffic which goes through pipes is wrote to stdout. I use it for debug network scripts.
you must be in the directory to analyse
report all files and links in the currect directory, not recursively.
this find command ahs been tested on hp-ux/linux/aix/solaris.
This command gives you the charset of a text file, which would be handy if you have no idea of the encoding.
Checks the Gmail ATOM feed for your account, parses it and outputs a list of unread messages.
For some reason sed gets stuck on OS X, so here's a Perl version for the Mac:
curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*<name>(.*)<\/name>.*$/$2 - $1/'
If you want to see the name of the last person, who added a message to the conversation, change the greediness of the operators like this:
curl -u username:password --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | perl -pe 's/^<title>(.*)<\/title>.*?<name>(.*?)<\/name>.*$/$2 - $1/'
Shell timeout variables (TMOUT) can be very liberal about what is classified as 'activity', like having an editor open. This command string will terminate the login shell for an user with more than a day's idle time.
If you use Linux in a Windows domain and there are N days to expiry, this is how you can change it without resorting to a windows machine.
Remove newlines from output.
One character shorter than awk /./ filename and doesn't use a superfluous cat.
To be fair though, I'm pretty sure fraktil was thinking being able to nuke newlines from any command is much more useful than just from one file.
Gets the internal and external IP addresses of all your interfaces, or the ones given as arguments
default stack size is 10M. This makes your multithread app filling rapidly your memory.
on my PC I was able to create only 300thread with default stack size.
Lower the default stack size to the one effectively used by your threads, let you create more.
ex. putting 64k I was able to create more than 10.000threads.
Obviously ...your thread shouldn't need more than 64k ram!!!
Within /proc and /sys there are a lot of subdirectories, which carry pseudofiles with only one value as content. Instead of cat-ing all single files (which takes quite a time) or do a "cat *" (which makes it hard to find the filename/content relation), just grep recursively for . or use "grep . /blabla/*" (star instead of -r flag).
For better readability you might also want to pipe the output to "column -t -s : ".
If you are doing some tests which require reboots (e. g. startup skripts, kernel module parameters, ...), this is very time intensive, if you have got a hardware with a long pre-boot phase due to hardware checks.
At this time, kexec can help, which only restarts the kernel with all related stuff.
First the kernel to be started is loaded, then kexec -e jumps up to start it.
Is as hard as a reboot -f, but several times faster (e. g. 1 Minute instead of 12 on some servers here).
The initial version of this command also outputted extra empty lines, so it went like this:
192.168.166.48
127.0.0.1
This happened on Ubuntu, i haven't tested on anything else.
and, a lot uglier, with sed:
ifconfig | sed -n '/inet addr:/s/[^:]\+:\(\S\+\).*/\1/p'
Edit:
Wanted to be shorter than the perl version. Still think that the perl version is the best..
Fetches the IPs and ONLY the IPs from ifconfig. Simplest, shortest, cleanest.
Perl is too good to be true...
(P.S.: credit should go to Peteris Krumins at catonmat.net)
Instead of calculating the offset and providing an offset option to mount, let lomount do the job for you by just providing the partition number you would like to loop mount.
gemInst.sh:
#!/bin/bash
for i in [email protected]; do
if [ "$1" != "$i" ]
then
echo /newInstall/gem install $1 -v=\"$i\"
/newInstall/gem install $1 -v="$i"
if [ "$?" != "0" ]
then
echo -e "\n\nGEM INSTALL ERROR: $1\n\n"
echo "$1" > gemInst.err
fi
fi
done
This command displays a clock on your terminal which updates the time every second. Press Ctrl-C to exit.
A couple of variants:
A little bit bigger text:
watch -t -n1 "date +%T|figlet -f big"
You can try other figlet fonts, too.
Big sideways characters:
watch -n 1 -t '/usr/games/banner -w 30 $(date +%M:%S)'
This requires a particular version of banner and a 40-line terminal or you can adjust the width ("30" here).