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:
Umask is obtained subtracting 7 from each cypher of octal format. I store octal perm format in an array,then for each element of array I subtract 7. The result is the umask.
You've opened a terminal window and you've connected off to a remote host that didn't pick up your terminal size, and all your curses and paging apps are screwed up as a result. You need to quickly determine how many lines are in your current terminal view (to feed into "stty rows X").
From screen's manpage: "Attach here and now. In detail this means: If a session is running, then reattach. If necessary detach and logout remotely first. If it was not running create it and notify the user. This is the author's favorite."
Toss this in your ~/.bash_profile so that you never have that "oh crap" moment where you wanted to run something in screen and didn't.
Also works with files:
cat file
Hello world
base64 file
SGVsbG8gd29ybGQK
To decrypt use the -d option:
echo SGVsbG8gd29ybGQK | base64 -d
Hello world
Basically an improvement on an earlier ethtool command line.
You can also use sha1sum and variants for longer passwords
Give the Speed and Link status of eth# 0-3. This is sort of what mii-tool does, but eth-tool is better, yet lacks device discovery.
Sometimes "ls" is just too slow, especially if you're having problems with terminal scroll speed, or if you're a speed freak. In these situations, do an echo * in the current directory to immediately see the directory listing. Do an echo * | tr ' ' '\n' if you want a column. Do an alias ls='echo *' if you want to achieve higher echelons of speed and wonder. Note that echo * is also useful on systems that are so low in memory that "ls" itself is failing - perhaps due to a memory leak that you're trying to debug.
Note that this will not work with files with spaces or characters that need to be escaped. Feel free to leave any comments to improve upon this command, and I'll add it in.
Thanks!
Echos the number of seconds from the current time till the specified time (Example in command is (2**31-1)) aka the Unix epoch. Just replace that number with the specified date (in seconds past Jan. 1st 1970) and it will return the seconds.
NOTE: Only works in bash
This will perform one of two blocks of code, depending on the condition of the first. Essentially is a bash terniary operator.
To tell if a machine is up:
ping -c1 machine { echo succes;} || { echo failed; }
Because of the bash { } block operators, you can have multiple commands
ping -c1 machine && { echo success;log-timestamp.sh }|| { echo failed; email-admin.sh; }
Tips:
Remember, the { } operators are treated by bash as a reserved word: as such, they need a space on either side.
If you have a command that can fail at the end of the true block, consider ending said block with 'false' to prevent accidental execution
But who knows to delete the rest of the lines?
I want only "string".
http://en.wikipedia.org/wiki/Year_2038_problem
Some other notable dates that have passed:
date -d@1234567890
date -d@1000000000
Allows you to save progress without committing.
To revert to an undo point, svn revert then apply the undo point with patch.
svn revert -R . && patch -p0 < .undo/2009-03-27_08:08:11rev57
Similar: http://www.commandlinefu.com/commands/view/373/archive-all-files-containing-local-changes-svn
Seems obvious, but other seemingly simple ways to use it don't work:
echo !whammy
and
echo "!whammy"
both output:
-bash: !whammy: event not found
and this:
echo "\!whammy"
outputs:
\!whammy
with the slash :(
you can also do any combinations of quotes for a complex string:
echo "It's great to be able to use a bang ("'!'") in a command"'!'
outputs:
It's great to be able to use a bang (!) in a command!
See man vmstat for information about the statistics.
This does the same thing without the timestamp:
vmstat 5
Here $HOME/shots must exist and have appropriate access rights and sitecopy must be correctly set up to upload new screen shots to the remote site.
Example .sitecopyrc (for illustration purposes only)
site shots
server ftp.example.com
username user
password antabakadesuka
local /home/penpen/shots
remote public_html/shots
permissions ignore
The command uses scrot to create a screen shot, moves it to the screen shot directory, uploads it using screen uses xsel to copy the URL to the paste buffer (so that you can paste it with a middle click) and finally uses feh to display a preview of the screen shot.
Note that $BASE stands for the base URL for the screen shots on the remote server, replace it by the actual location; in the example http://www.example.com/~user/shots would be fitting.
Assign this command to a key combination or an icon in whatever panel you use.
A web server using $HOME/public_html as user directory is required, $HOME/public_html/shots must exist and have appropriate access rights and $HOSTNAME must be known to and accessible from the outside world.
The command uses scrot to create a screen shot, moves it to the screen shot directory, uses xsel to copy the URL to the paste buffer (so that you can paste it with a middle click) and finally uses feh to display a preview of the screen shot.
Assign this command to a key combination or an icon in whatever panel you use.