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

Downsample mp3s to 128K
This will lower the quality of mp3 files, but is necessary to play them on some mobile devices.

Print the contents of $VARIABLE, six words at a time
Print out the contents of $VARIABLE, six words per line, ignoring any single or double quotes in the text. Useful when $VARIABLE contains a sentence that changes periodically, and may or may not contain quoted text.

list files recursively by size

Get the total length of all videos in the current dir in H:m:s
You're behind on your TV catch-up, but how far behind? This command tries to open mplayer against all files in the current dir. If it's a video file it will contain ID_LENGTH, which is summed and output in hours, minutes and seconds. Someone better at awk could probably reduce this down a lot.

syncronizing datas beetween two folder (A and B) excluding some directories in A (dir1 and dir2)

using tee to echo to a system file with sudo privileges
We sometimes need to change kernel parameters by echoing the file . This needs root privilege and if we do it using sudo like this , it fails $ sudo echo ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor -bash: /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor: Permission denied We can achieve this with the tee command by just doing sudo without logging as root user http://www.zaman4linux.in/2010/09/using-tee-to-echo-to-system-file-with.html

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

recursive search and replace old with new string, inside files
Search and replace recursively. :-) Shorter and simpler than the others. And allows more terms: replace old new [old new ...] -- `find -type f`

Like top, but for files

Watch the progress of 'dd'
The 'dd' command doesn't provide a progress when writing data. So, sending the "USR1" signal to the process will spit out its progress as it writes data. This command is superior to others on the site, as it doesn't require you to previously know the PID of the dd command.


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: