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.
» 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:
Oneliner to run commands on multiple servers over ssh.
- First parameter "$1" is the command you want to execute remotely.
( It can be multiple commands e.g. "hostname;uptime")
- Second parameter "${@:2}" represents the remote host/s you want to run the command/s on.
Bash function to change your default prompt to something simpler and restore it to normal afterwards.
Awk replaces the value of a specific field while retaining the field separator "/" .
This inserts an element as last child under /breakfast_menu/food in simple.xml.
xml used - http://www.w3schools.com/xml/simple.xml
This prints file access rights in octal - useful when "stat" is unavailable.
You can push files to up to 32 servers at once assuming ssh keys are in place.
Great tool, it is part of the pssh suite.
This is also handy for taking a look at resource usage of a remote box.
ssh -t remotebox top
Awk replaces every instance of foo with bar in the 5th column only.
Run this before you run a command in order to see what the command does as it starts.
The -c flag is useful here as the PID is unknown before startup.
All config files, libraries, logs, ports, etc used by the command as it starts up, (and shuts down) will be captured at 1s intervals and written to a file.
Useful for debugging etc.
The output of lsof is piped to txt2html which converts it to html.
# Perl module HTML::TextToHTML needed
If you spot a dubious looking cp command running you can use this command to view what is being copied and to where.
1234 is the PID of the cp command being passed to the lsof utility.
3r.*REG will display the file/directory that is being read/copied.
4w.*REG will display the destination it is being written to.
Here's an awk alternative, for those lacking the version of cut with the --complement argument.
View details of both TCP and UDP network activity within a specified port range.
View all files opened by a user in specified directory.
The +D option makes lsof search all sub-directories to complete depth, while ignoring symbolic links.
Netcat is used to serve a log-file over a network on port 1234.
Point a browser to the specified server/port combo to view log-file updates in real-time.
This searches the Apache error_log for each of the 5 most significant Apache error levels, if any are found the date is then cut from the output in order to sort then print the most common occurrence of each error.
Finds the top ten pages returning an http response code of 404 in an apache log.
Add permanent line numbers to a file without creating a temp file.
The rm command deletes file10 while the nl command works on the open file descriptor of file10 which it outputs into a new file again named file10.
The new file10 will now be numbered in the same directory with the same file name and content as before, but it will in fact be a new file, using (ls -i) to show its inode number will prove this.
The "-r 2" option puts lsof in repeat mode, with updates every 2 seconds. (Ctrl -c quits)
The "-p" option is used to specify the application PID you want to monitor.
The "-u' option can be used to keep an eye on a users network activity.
"lsof -r 2 -u username -i -a"