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.
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:
"find . -type d -print0 | xargs -0 chmod 755"
With this command you can get a previous or future date or time. Where can you use this? How about finding all files modified or created in the last 5 mins?
touch -t `echo $(date -d "5 minute ago" "+%G%m%d%H%M.%S")` me && find . -type f -newer me
List all directories created since last week?
touch -t `echo $(date -d "1 week ago" "+%G%m%d%H%M.%S")` me && find . -type d -cnewer me
I'm sure you can think of more ways to use it. Requires coreutils package.
unzips all zip files in any subdirectory under the current directory. The zip files are unzipped in their respective subdirs
In the example, uid 0 is root. foo:foo are the user:group you want to make owner and group. '.' is the "current directory and below." -print0 and -0 indicate that filenames and directories "are terminated by a null character instead of by whitespace."
This uses Bash's "process substitution" feature to compare (using diff) the output of two different process pipelines.
The "find" command can be annoying when used inside of a Subversion (or CVS) working directory. Obviously, you can combine this with other predicates and commands to create a more elaborate pipeline:
find /var/svn -type f -not \( -name .svn -prune \) -print0 | xargs -0 md5sum
Note: You can use my "dont-go-there.sh" script to wrap the "find" command and do this automatically at http://forwardlateral.com/blog/2006/02/27/dont-go-there/
Deletes empty directories and prints an error if directory is not empty.
find largest file in /var
I have a bash alias for this command line and find it useful for searching C code for error messages.
The -H tells grep to print the filename. you can omit the -i to match the case exactly or keep the -i for case-insensitive matching.
This find command find all .c and .h files
Change your wallpaper every thirty minutes (or however long you like, I suppose) to a randomly selected image in a directory and subdirectories. Bear in mind this is not safe to use if anyone else has write access to your image directory.
Clone linux installation.
Copy every file from current directory to destination preserving modification time.
Have a grudge against someone on your network? Do a "find -writable" in their directory and see what you can vandalize! But seriously, this is really useful to check the files in your own home directory to make sure they can't inadvertently be changed by someone else's wayward script.
By time thumbnail images in ~/thumbnails take up too much space, this command will help deleting old ones.
Find options explained:
-type f : find files only, not directories
-atime +30 : last accessed more than 30 days ago
This is useful if you have a collection of files in folders (for example, a bunch of .zip files that are contained in folders) and you want to move them all to a common folder.
Can be used for other commands as well, replace rm with ls.
It is easy to make this shorter but if the filenames involved have spaces, you will need to do use find's "-print0" option in conjunction with xargs's "-0" option. Otherwise the shell that xargs uses to execute the "rm" command line will treat the space as a token separator, thereby treating the name as two (or more) names.
Ever wanted to find the most recently modified files, but couldn't remember exactly where they were in a project directory with many subdirectories? The "find" command, using a combination of "-mtime -N" and "-depth -D" can be used to find those files. If your directory structure isn't very deep, just omit the "-depth -D", but if your directory structure is very deep, then you can limit the depth of the traversal using "-depth -D", where "D" is the maximum number of directory levels to descend.
Takes filenames and directory names and replace space to '_'.