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:
print sum of disk usage for filetype within current dir and subdirs
for when find . -print | grep -v .svn | xargs doesnt cut it.
This is for bash - make an alias - also a good blueprint for making aliases that take arguments to functions. If for Solaris use "-size +${1}000000c" to replace "-size +${1}M"
Deletes capistrano-style release directories (except that there are dashes between the YYYY-MM-DD)
One of my friends committed his code in the encoding of GB2312, which broke the build job. I have to find his code and convert.
must be in the directory containing the track
outputs to ~ but could be replaced with whatever you like e.g. ~/music/
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 :-)
'-mtime -10' syncs only files newer 10 days (-mtime is just one example, use whatever find expressions you need)
printf %P: File's name with the name of the command line argument under which it was found removed.
this way, you can use any src directory, no need to cd into your src directory first.
using \\0 in printf and a corresponding --from0 in rsync ensures that even filenames with newline characters work (thanks syssyphus for #3808).
both, #1481 and #3808 just work if you either copy the current directory (.) , or the filesystem root (/), otherwise the output from find and the source dir from rsync just don't match. #7685 works with an arbitrary source directory.
Consider using this cmd when:
1. You are planning to traverse a big directory.
2. There is a subdir you don't want find to decend to. (entirely ignore)
3. You don't want find to decend to any mounted filesystems under this dir.
* The -xdev flag tells find do not go to other filesystems.
* -path ./junk_dir -prune is the pattern to ignore ./junk_dir entirely.
* The rest is the typical search and print.
To ignore multiple subdirs, you can just iterate the pattern, e.g.
find . -path ./junk1 -prune -o -path ./junk2 -prune ...
If you do want to include other filesystems, then remove -xdev flag.
If you want to search files, then change -type d to -type f.
A quick find command to identify all TAR files in a given path, extract a list of files contained within the tar, then search for a given string in the filelist. Returns to the user as a list of TAR files found (enclosed in []) followed by any matching files that exist in that archive. TAR can easily be swapped for JAR if required.
recursively search dir for a a particular file type, search each file for a particular text.
Also:
* find . -type f -exec ls -s {} \; | sort -n -r | head -5
* find . -type f -exec ls -l {} \; | awk '{print $5 "\t" $9}' | sort -n -r | head -5
If you want to pull all of the files from a tree that has mixed files and directories containing files, this will link them all into a single directory. Beware of filesystem files-per-directory limits.
-depth argument will cause find to do a "depth first" tree search, this will eliminate the "No such file or directory" error messages
Used this command recently to remove the trailing ?> from all the files in a php project, which has having some unnecessary whitespace issues. Obviously, change *.php to whatever you'd like.
Extract in the current directory the content of all parted archives.
Use the same password for each one.
expands through shell and not find
but may hits the limit of max argument size for rm
(thus: for f in **/*.htm;do rm $f;done
but then I prefer the find command ;)
In this way it doesn't have problems with filenames with spaces.