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:
expand to:
cp /work/host/phone/ui/main.cpp /work/target/phone/ui/main.cpp
!#
The entire command line typed so far.
This causes cp to detect and omit large blocks of nulls. Sparse files are useful for implying a lot of disk space without actually having to write it all out.
http://en.wikipedia.org/wiki/Sparse_file
You can use it in a pipe too:
dd if=/dev/zero bs=1M count=5 |cp --sparse=always /dev/stdin SPARSE_FILE
preserve all except context and xattr. useful when moving a running system to a new partition.
Some people put spaces in filenames. Others have an $EDITOR environment variable set. This defaults to vim, but you can use whatever you wish: emacs, nano, ed, butterflies, etc.
Remember to backup everything before changing it so you can restore all to normal.
1) Find true type fonts;
2) Copy them to /usr/share/fonts/truetype;
3) Reload font information.
Bash function copies a file prefixed with a version number to a subdirectory
This is a BASH feature.
The above command will create a backup of "filename" called "filename.DATE", where DATE is the actual day in %Y%m%d (year, month and day numbers together) format.
Take a folder full of files and split it into smaller folders containing a maximum number of files. In this case, 100 files per directory.
find creates the list of files
xargs breaks up the list into groups of 100
for each group, create a directory and copy in the files
Note: This command won't work if there is whitespace in the filenames (but then again, neither do the alternative commands :-)
This will tighten up security for your box. The default value for PermitRootLogin sadly is 'yes'.
"infix" version in bash (4.x+)
Remove -v to make it silent.
BTW: The OP forgot to use "cat" and "nmap" ;-) I had a good laugh though.
This backup function preserve the file suffix allowing zsh suffix aliases and desktop default actions to work with the backup file too.
1. you don't need to prepend the year with 20 - just use Y instead of y
2. you may want to make your function a bit more secure:
buf () { cp ${1?filename not specified}{,$(date +%Y%m%d_%H%M%S)}; }
buf myfile.txt
This is useful when you are making small but frequent changes to a file. It keeps things organised and clear for another administrator to see what changed and at what time. An overview of changes can be deduced using a simple:
ls -ltr
Maybe it could work for any music player if you change "audacious2" with the string you see in `ps aux` for your player. Needs testing in different systems.
This command will a particular folder-name recursively found under the src-path-to-search to the dest-path-to-copy retaining the folder structure
Change the value of p to match the path where you wish to create the profile.
To run it again in the future, use the parameter --user-data-dir (which gets echoed to you when run):
chromium-browser --user-data-dir=/path/to/your/
Quick Functions:
# create a new chromium profile
new-chromium-profile() { p=~/.config/chromium/$1; cp -r ~/.config/chromium/Default $p && echo "chromium-browser --user-data-dir=$p" && chromium-browser --user-data-dir=$p; }
# runs a chromium profile
run-chromium-profile() { chromium-browser --user-data-dir=~/.config/chromium/$1; }
Preserve file structure when coping and exclude some file o dir patterns