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.
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:
Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:
This version makes uses of Bash shell expansion, so it might not work in all other shells.
This is a command that I find myself using all the time. It works like regular grep, but returns the paragraph containing the search pattern instead of just the line. It operates on files or standard input.
grepp <PATTERN> <FILE>
<SOMECOMMAND> | grepp <PATTERN>
Quick and easy way to find out which php.ini file is being used. Especially useful if you just need to find the location of the file for editing purposes.
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
Like the tiltle said, you can use an argument too ( the interface )
will show only the IP of this interface and the public IP
( tested with Linux )
You can add that function in ~/.bashrc, then
Now you are ready to call this function in all your terms...
There's no need for ls or grep; printf is builtin to most modern shells
no need to use grep.
It's not a big line, and it *may not* work for everybody, I guess it depends on the detail of access_log configuration in your httpd.conf. I use it as a prerotate command for logrotate in httpd section so it executes before access_log rotation, everyday at midnight.
Extracts the model name of the CPU and displays it on screen.
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.
If you issue the "set" command, you'll see a list of variables and functions. This command displays just those functions' names.
Really useful way to combine less and grep while browsing log files.
I can't figure out how to make it into a true oneliner so paste it into a script file called lgrep:
lgrep searchfor file1 [file2 file3]
Advanced example (grep for an Exception in logfiles that starts with qc):
lgrep Exception $(find . -name "qc*.log")
Place this in your .bash_profile and you can use it two different ways. If you issue 'h' on its own, then it acts like the history command. If you issue:
Then it will display all the history with the word 'cd'
I needed a way to search all files in a web directory that contained a certain string, and replace that string with another string. In the example, I am searching for "askapache" and replacing that string with "htaccess". I wanted this to happen as a cron job, and it was important that this happened as fast as possible while at the same time not hogging the CPU since the machine is a server.
So this script uses the nice command to run the sh shell with the command, which makes the whole thing run with priority 19, meaning it won't hog CPU processing. And the -P5 option to the xargs command means it will run 5 separate grep and sed processes simultaneously, so this is much much faster than running a single grep or sed. You may want to do -P0 which is unlimited if you aren't worried about too many processes or if you don't have to deal with process killers in the bg.
Also, the -m1 command to grep means stop grepping this file for matches after the first match, which also saves time.
This is how I typically grep. -R recurse into subdirectories, -n show line numbers of matches, -i ignore case, -s suppress "doesn't exist" and "can't read" messages, -I ignore binary files (technically, process them as having no matches, important for showing inverted results with -v)
I have grep aliased to "grep --color=auto" as well, but that's a matter of formatting not function.
After executing this, click on a window you want to track X Window events in.
Explaination: "xev will track events in the window with the following -id, which we get by greping window information obtained by xwininfo"
for one line per process:
ss -p | cat
for established sockets only:
ss -p | grep STA
for just process names:
ss -p | cut -f2 -sd\"
ss -p | grep STA | cut -f2 -d\"