Commands using grep (1,935)

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

list files recursively by size

find file/dir by excluding some unwanted dirs and filesystems
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.

encode HTML entities
Encodes HTML entities from input (file or stdin) so it's possible to directly past the result to a blog or HTML source file.

View details of network activity, malicious or otherwise within a port range.
View details of both TCP and UDP network activity within a specified port range.

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

get the top 10 longest filenames

Find usb device
I often use it to find recently added ou removed device, or using find in /dev, or anything similar. Just run the command, plug the device, and wait to see him and only him

Make a dedicated folder for each zip file
${f%*.zip} strips off the extension from zip filenames

generate file list modified since last commit and export to tar file
################################################################################ # get all modified files since last commit and zip them to upload to live server ################################################################################ # delete previous tar output file rm mytarfile.tar -rf #rm c:/tarOutput/*.* -rf # get last commit id and store in variable declare RESULT=$(git log --format="%H" | head -n1) # generate file list and export to tar file git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT $RESULT | xargs tar -rf mytarfile.tar # extract tar files to specified location tar -xf mytarfile.tar -C c:/tarOutput


Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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: