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:
Created to deal with an overzealous batch rename on our server that renamed all files to .jpg files.
echo "ls" > script.bash;
This is my script, a simple 'ls'.
gpg -c script.bash;
Here I encrypt and passord-protect my script. This creates file script.bash.gpg.
cat script.bash.gpg | gpg -d --no-mdc-warning | bash
Here I open file script.bash.gpg, decrypt it and execute it.
The original command doesn't work for me - does something weird with sed (-r) and xargs (-i) with underscores all over...
This one works in OSX Lion. I haven't tested it anywhere else, but if you have bash, gpg and perl, it should work.
(Please see sample output for usage)
Use any script name (the read command gets it) and it will be encrypted with the extension .crypt, i.e.:
myscript --> myscript.crypt
You can execute myscript.crypt only if you know the password. If you die, your script dies with you.
If you modify the startup line, be careful with the offset calculation of the crypted block (the XX string).
Not difficult to make script editable (an offset-dd piped to a gpg -d piped to a vim - piped to a gpg -c directed to script.new ), but not enough space to do it on a one liner.
Sorry for the chmod on parentheses, I dont like "-" at the end.
Thanks flatcap for the subshell abbreviation to /dev/null
'readlink -fn' gets canonical path of the file/directory without newline at the end;
'xsel -ib' copies pipelined string from STDIO to system clipboard (ready to be pasted with CTRL+V).
Execute matlab sentences in shell script:
for var in `seq 0 0.2 1` ; do
echo "my_function($var);" | matlab -nodisplay
done
(Please see sample output for usage)
script.bash is your script, which will be crypted to script.secure
script.bash --> script.secure
You can execute script.secure only if you know the password. If you die, your script dies with you.
If you modify the startup line, be careful with the offset calculation of the crypted block (the XX string).
Not difficult to make script editable (an offset-dd piped to a gpg -d piped to a vim - piped to a gpg -c directed to script.new ), but not enough space to do it on a one liner.
make a bunch of files with the same permissions, owner, group, and content as a template file
(handy if you have much to do w. .php, .html files or alike)
Get the amount of physical memory in an HP-UX v11 OS when following are NOT available:
- root account
- no privileges in /proc
- no privileges in /dev/mem
instead of printing the whole line, print just the capture matched, but with the "cut" pipe :( I'm so sad with grep.
In order to unrar several files in different subfolders, you just need to launch this command in your parent folder in order to have your files ready for manipulation and already extracted;
I did not put anything to delete the original rar files
Very similar as doing "wget http://example.com/mytarball|tar xzv", this one involves the "tee" command between both, which will simultaneously write the tarball and copy it to stdout. So this command will locally save the tarball and extract it - both at the same time while it downloads.
When you need a quick ref guide while troubleshooting Apache|NGINX error|access logs.