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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
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.
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:
If you want all the URLs from all the sessions, you can use :
perl -lne 'print for /url":"\K[^"]+/g' ~/.mozilla/firefox/*/sessionstore.js
Thanks to tybalt89 ( idea of the "for" statement ).
For perl purists, there's JSON and File::Slurp modules, buts that's not installed by default.
For the record: I didn't build this. Just shared what I found that worked. Apologies to the original author!
I decided I should fix the case where http://example.com is not matched for the next time I need this. So I read rfc1035 and formalized the host name regex.
If anyone finds any more holes, please comment.
don't have to be that complicated
Thought it would be useful to commandlinefuers.
The -i option in sed allows in-place editing of the input file.
Replace myexpression with any regular expression.
/expr/d syntax means if the expression matches then delete the line.
You can reverse the functionality to keep matching lines only by using:
sed -i -n '/myexpression/p' /path/to/file.txt
Sometimes, you don't really care about all the other information that ifconfig spits at you (however useful it may otherwise be). You just want an IP. This strips out all the crap and gives you exactly what you want.
Place the regular expression you want to validate between the forward slashes in the eval block.
This will comment out a line, specified by line number, in a given file.
Handles everything except octets with 255. Ran through ip generator with variable octet lengths.
if you want to only print the IP address from a file.
In this case the file will be called "iplist" with a line like "ip address 18.104.22.168"
it will only print the "22.214.171.124" portion
This obey that you don't match any broadcast or network addresses and stay between 126.96.36.199 - 254.254.254.254
regex to match an ip
This does the following:
1 - Search recursively for files whose names match REGEX_A
2 - From this list exclude files whose names match REGEX_B
3 - Open this as a group in textmate (in the sidebar)
And now you can use Command+Shift+F to use textmate own find and replace on this particular group of files.
For advanced regex in the first expression you can use -regextype posix-egrep like this:
mate - `find * -type f -regextype posix-egrep -regex 'REGEX_A' | grep -v -E 'REGEX_B'`
Warning: this is not ment to open files or folders with space os special characters in the filename. If anyone knows a solution to that, tell me so I can fix the line.
Same thing as above, just uses fetch and ipchicken.com
This command will output 1 if the given argument is a valid ip address and 0 if it is not.
Quick and easy way of validating a date format of yyyy-mm-dd and returning a boolean, the regex can easily be upgraded to handle "in betweens" for mm dd or to validate other types of strings, ex. ip address.
Boolean output could easily be piped into a condition for a more complete one-liner.
txt2regex can be interactive or noninteractive and generates regular expressions for a variety of dialects based on user input. In interactive mode, the regex string builds as you select menu options. The sample output here is from noninteractive mode, try running it standalone and see for yourself. It's written in bash and is available as the 'txt2regex' package at least under debian/ubuntu.
Although less behaves more or less like vim in certain aspects, the vim regex for word boundaries (\< and \>) do not work in less. Instead, use \b to denote a word boundary. Therefore, if you want to search for, say, the word "exit", but do not want to search for exiting, exits, etc., then surround "exit" with \b. This is useful if you need to search for specific occurrences of a keyword or command. \b can also be used at just the beginning and end, if needed.