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:
Create backup (.tar.gz) for all first-level directory from current dir.
-t, --target-directory=DIRECTORY (copy all SOURCE arguments into DIRECTORY).
This command will kill all processes using a directory. It's quick and dirty. One may also use a -9 with kill in case regular kill doesn't work. This is useful if one needs to umount a directory.
"." is current dir, maxdepth is the level, -print0 | xargs -0 fix spaces in names, -i interactive , ./ is the current dir {} actual name , and {,.bak} is the atual name + bak
This adds all new files to SVN recursively. It doesn't work for files that have spaces in their name, but why would you create a file with a space in its name in the first place?
Removes all unversioned files and folders from an svn repository. Also:
svn status --no-ignore | grep ^I | awk '{print $2}' | xargs rm -rf
will remove those files which svn status ignores. Handy to add to a script which is in your path so you can run it from any repository (a la 'svn_clean.sh').
This will get the job done in the most efficient way -
spawning only one `rm` process.
"On-the-fly" find data is displayed through `tee` and
you should have plenty of time to ctrl-c if needed before it's too late.
You may need to re-run this after major Software Updates.
To leave more languages in, add more ``-and \! -iname "lang*"'' statements:
sudo find / -iname "*.lproj" -and \! -iname "en*" -and \! -iname "spanish*" -print0 | tee /dev/stderr | sudo xargs -0 rm -rfv
**Edit: note the 2nd sudo near the end of the pipeline - this is necessary.
Run this in the directory you store your music in.
mp3gain and vorbisgain applies the ReplayGain normalization routine to mp3 and ogg files (respectively) in a reversible way.
ReplayGain uses psychoacoustic analysis to make all files sound about the same loudness, so you don't get knocked out of your chair by loud songs after cranking up the volume on quieter ones.
You also can sum the file usage of all files
find /usr/lib -maxdepth 1 -type l -print0 | xargs -r0 du -Lch
Useful if you want get all the md5sum of files but you want exclude some directories. If your list of files is short you can make in one command as follow:
find . -type d \( -name DIR1 -o -name DIR2 \) -prune -o -type f -exec md5sum {} \;
Alternatively you can specify a different command to be executed on the resulting files.
I use this to generate a playlist with all the podcasts I listen to.
Ordered from most recent to older.
This command kills all processes with 'SomeCommand' in the process name. There are other more elegant ways to extract the process names from ps but they are hard to remember and not portable across platforms. Use this command with caution as you could accidentally kill other matching processes!
xargs is particularly handy in this case because it makes it easy to feed the process IDs to kill and it also ensures that you don't try to feed too many PIDs to kill at once and overflow the command-line buffer.
Note that if you are attempting to kill many thousands of runaway processes at once you should use 'kill -9'. Otherwise the system will try to bring each process into memory before killing it and you could run out of memory. Typically when you want to kill many processes at once it is because you are already in a low memory situation so if you don't 'kill -9' you will make things worse
These part of the command:
svn status | grep '^\?' => find new file or directory on working copy
sed -e 's/^\?//g' => remove "^" character on the first character of file name
xargs svn add => add file to subversion repository
You can modify above command to other circumtances, like revert addition files or commit files that have been modified. ^_^
rpm, sometimes, is not wildcard friendly. To search files installed from package this could be useful.
change PACKAGENAME to any package do you want to search
Will search recursively and output the searchResult.txt in the same folder you are located.
grep ERROR *.log
-bash: /bin/grep: Argument list too long
echo *.log | xargs grep ERROR /dev/null
20090119.00011.log:DANGEROUS ERROR
kills all pids matching the search term of "PROCESS". Be careful what you wish for :)
Note that the file at the given path will have the contents of the (still) deleted file, but it is a new file with a new node number; in other words, this restores the data, but it does not actually "undelete" the old file.
I posted a function declaration encapsulating this functionality to http://www.reddit.com/r/programming/comments/7yx6f/how_to_undelete_any_open_deleted_file_in_linux/c07sqwe (please excuse the crap formatting).