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.
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:
In this way it doesn't have problems with filenames with spaces.
Returns any file in the folder which would be rejected by Gmail, if you were to send zipped version.
(Yes, you could just zip it and knock the extension off and put it back on the other side, but for some people this just isn't a solution)
Increase the modification date for the files selected with the find command.
Some MP3s come with tags that don't work with all players. Also, some good tag editors like, EasyTAG output tags that don't work with all players. For example, EasyTAG saves the genre as a numeric field, which is not used correctly in Sansa MP3 players.
This command corrects the ID3 tags in MP3 files using mid3iconv, which comes with mutagen. To install Mutagen on Fedora use "yum install python-mutagen"
This command is recursive and will delete in all directories in ".". It will find and delete all files not specified with ! -name "pattern". In this case it's file extensions. -type f means it will only find files and not directories. Finally the -delete flag ask find to delete what it matches. You can test the command by running it first without delete and it will list the files it will delete when you run it.
Preserve file structure when coping and exclude some file o dir patterns
Search in all html files and remove the lines that 'String' is found.
This deals nicely with filenames containing special characters and can deal with more files than can fit on a commandline. It also avoids spawning du.
recursive find and replace. important stuff are grep -Z and zargs -0 which add zero byte after file name so sed can work even with file names with spaces.
Looking for carriage returns would also identify files with legacy mac line endings. To fix both types:
perl -i -pe 's/\r\n?/\n/g' $(find . -type f -exec fgrep -l $'\r' "{}" \;)
find . -type f -iname '*.flac' # searches from the current folder recursively for .flac audio files
| # the output (a .flac audio files with relative path from ./ ) is piped to
while read FILE; do FILENAME="${FILE%.*}"; flac -cd "$FILE" | lame -b 192 - "${FILENAME}.mp3"; done
# for each line on the list:
# FILE gets the file with .flac extension and relative path
# FILENAME gets FILE without the .flac extension
# run flac for that FILE with output piped to lame conversion to mp3 using 192Kb bitrate
If you would like to ignore a directory including its subdirectory. For example, a tmp/ directory
All with only one pipe. Should be much faster as well (sort is slow). Use find instead of ls for recursion or reliability.
Edit: case insensitive
If your grep doesn't have an -o option, you can use sed instead.
This is a command template for achiving the following:
* loop over files --> find -name "" | while read file; do ...; done
* output progress --> echo -n .
* execute some command on each file and save output for later usage --> output=$()
* if command failed, open subshell and echo newline --> || (echo;...;...;)
* echo output of command --> echo "$output"