Hide

What's this?

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/

Get involved!

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using cut from sorted by
Terminal - Commands using cut - 468 results
asterisk -rx "core show calls" | grep "active" | cut -d' ' -f1
buf () { oldname=$1; if [ "$oldname" != "" ]; then datepart="$(date +%Y-%m-%d).bak"; firstpart=`echo $oldname | cut -d "." -f 1`; newname=`echo $oldname | sed s/$firstpart/$firstpart.$datepart/`; cp -iv ${oldname} ${newname}; fi }
2012-08-15 08:31:44
User: juliushibert
Functions: cp cut sed
1

Appends the input file with the date format YYYY-MM-DD.bak. Also runs silently if you remove the -v on the cp at the end of the function.

nmap -n -sP -oG - 10.10.10.*/32 | grep ": Up" | cut -d' ' -f2
2012-08-13 15:37:21
Functions: cut grep
0

You can substitute 10.10.10.* by your own network. Or whatever nmap accepts, inlcluding submask.

ssh-keygen -l -f [pubkey] | cut -d ' ' -f 2 | tr -ds '\n:' ''
eselect bashcomp enable --global $(eselect bashcomp list | sed -e 's/ //g'| cut -d']' -f2 | sed -e 's/\*//'| xargs)
curl -s http://checkrealip.com/ | grep "Current IP Address" | cut -d ' ' -f 4
ip a s eth0 | grep "inet " | head -n 1 | awk '{print $2}' | cut -f1 -d'/'
2012-07-16 07:54:43
User: thelan
Functions: awk cut grep head
Tags: IP
-4

Get the first IPv4 address of an interface

ifconfig | grep "inet addr" | cut -d":" -f2 | cut -d" " -f1
for user in $(getent passwd|cut -f1 -d:); do echo "### Crontabs for $user ####"; crontab -u $user -l; done
2012-07-11 13:06:17
User: harpo
Functions: crontab cut echo getent
Tags: crontab getent
0

added echo "### Crontabs for $user ####"; to make clear whose crontab is listed.

for user in $(cut -f1 -d: /etc/passwd); do echo "### Crontabs for $user ####"; crontab -u $user -l; done
2012-07-11 12:25:56
User: harpo
Functions: crontab cut echo
Tags: crontab
3

added echo "### Crontabs for $user ####"; to make clear whose crontab is listed.

smbclient -N -gL \\SambaServer 2>&1 | grep -e "Disk|" | cut -d'|' -f2
cut -d: -f 1 names.txt
2012-06-26 19:28:25
User: ankush108
Functions: cut
Tags: column cut
0

Display the 1st field (employee name) from a colon delimited file

netstat -tn | grep :80 | awk '{print $5}'| grep -v ':80' | cut -f1 -d: |cut -f1,2,3 -d. | sort | uniq -c| sort -n
2012-06-26 08:29:37
User: krishnan
Functions: awk cut grep netstat sort uniq
0

cut -f1,2 - IP range 16

cut -f1,2,3 - IP range 24

cut -f1,2,3,4 - IP range 24

nl -ba FILE | sort -nr | cut -f2-
2012-06-24 23:07:06
User: maher
Functions: cut nl sort
0

"nl -ba" numbers all lines in the file (including empty lines), "sort -nr"

sorts the lines in descending order, and the "cut" command finally removes

the line numbers again.

curl -s kernel.org | grep '<strong>' | head -3 | tail -1 | cut -d'>' -f3 | cut -d'<' -f1
cut -f 3 | uniq
printf "%s," "${LIST[@]}" | cut -d "," -f 1-${#LIST[@]}
2012-06-04 14:56:12
User: Valise
Functions: cut printf
0

printf reapeats the format as longer as it has arguments. Then the idea is to make cut retain as much fields as we have elements in the array.

As usual with such join/split string manipulation, you have to make sure you don't have conflicts between your separator and your array content.

mysqlbinlog <logfiles> | grep exec | grep end_log_pos | cut -d' ' -f2- | cut -d: -f-2 | uniq -c
2012-05-30 09:42:21
User: theist
Functions: cut exec grep uniq
1

shows number of mysql bin log events (which are mysql server events) per minute, useful to check stress times postmortem

members () { dscl . -list /Users | while read user; do printf "$user "; dsmemberutil checkmembership -U "$user" -G "$*"; done | grep "is a member" | cut -d " " -f 1; };
2012-05-20 11:34:33
User: eduo
Functions: cut grep printf read
-1

Group membership in OS X is a mish-mash of standards that end up meaning there's almost a half-dozen of ways to belong to a group, what with group inheritance and automatic assignment. This means there's no easy command to find out all groups a user belongs to. The only sensible way then is to list all users and then query each user for membership.

NOTE: This is a function. Once input you can execute it by calling with a groupname.

find ./src -type d -name "Entity" | xargs ls -A | cut -d . -f1 | sed 's_^_app/console doctrine:generate:entities YourOwnBundleName:_'
2012-04-11 21:28:02
User: renoirb
Functions: cut find ls sed xargs
0

When I do a major change in my entities, I want to find a way to find all my Entities names and create the commande for me.

So instead of doing ls src/Your/OwnBundle... and then do it manually, this helps a lot.

find . -mount -type f -printf "%k %p\n" | sort -rg | cut -d \ -f 2- | xargs -I {} du -sh {} | less
svn stat | grep M | cut -d " " -f8 | xargs svn revert
pmset -g batt | egrep "([0-9]+\%).*" -o --colour=auto | cut -f1 -d';'
2012-03-23 23:23:46
User: deshawnbw
Functions: cut egrep
2

adjusting the field "f1" will give you additional information such as

f1 = 98%

f2 = discharging

f3 = 2:02 remaining

lsgrp() { read GID USERS <<< "$(grep "^$1:" /etc/group | cut -d: -f3,4 | tr ':,' ' ')" ; echo -e "${USERS// /\n}" | egrep -v "^($1)?$" ; egrep :[0-9]+:$GID: /etc/passwd | cut -d: -f1 ; }
2012-03-16 09:57:33
User: livibetter
Functions: cut echo egrep read
0

I can't find the lid command on my system, there is also another complied program: http://xyne.archlinux.ca/projects/lsgrp/

find / -type f -name IMG_????.JPG -print0 |xargs -0 exiv2 -g Exif.Canon.ModelID '{}' |grep A520 |rev |cut --complement -d " " -f1-40 |rev |xargs -I {} cp --parents {} /where
2012-03-10 03:01:01
User: fladam
Functions: cp cut find grep rev xargs
-1

You must spezify /where folder and / folder

If you have another camera you must experiment with Exif data (after -g and after grep) and mask of your photo files IMG_????.JPG

I have do it on Knoppix 6.7.0

You must have installed exiv2.