### All commands (12,646) the last day the last week the last month all time sorted by date votes

• Needs to be run in a battery sysfs dir, eg. /sys/class/power_supply/BAT0 on my system. Displays the battery's current charge and the rate per-second at which energy is {dis,}charging. All values are displayed as percentages of "full" charge. The first column is the current charge. The second is the rate of change averaged over the entire lifetime of the command (or since the AC cable was {un,}plugged), and the third column is the rate of change averaged over the last minute (controlled by the C=60 variable passed to awk). The sample output captures a scenario where I ran 'yes' in another terminal to max out a CPU. My battery was at 76% charge and you can see the energy drain starts to rise above 0.01% per-second as the cpu starts working and the fan kicks in etc. While idle it was more like 0.005% per-second. I tried to use this to estimate the remaining battery life/time until fully charged, but found it to be pretty useless... As my battery gets more charged it starts to charge slower, which meant the estimate was always wrong. Not sure if that's common for batteries or not. Show Sample Output

-1
while cat energy_now; do sleep 1; done |awk -v F=\$(cat energy_full) -v C=60 'NR==1{P=B=\$1;p=100/F} {d=\$1-P; if(d!=0&&d*D<=0){D=d;n=1;A[0]=B=P}; if(n>0){r=g=(\$1-B)/n;if(n>C){r=(\$1-A[n%C])/C}}; A[n++%C]=P=\$1; printf "%3d %+09.5f %+09.5f\n", p*\$1, p*g, p*r}'
· 2015-09-19 15:45:40
• U have to make key exchange in order to avoid continuous password prompt. Show Sample Output

-1
find <dir> -type f -mtime +<days> -exec scp -r {} user@backuphost:/data/bkup \;
· 2009-02-12 07:43:29
• lists the files found by find, waits for user input then uses xdg-open to open the selected file with the appropriate program. usage: findopen path expression [command] With the third optional input you can specify a command to use other than xdg-open, for example you could echo the filename to stdout then pipe it to another command. To get it to work for files with spaces it gets a bit messier... `findopen() { files=( \$(find "\$1" -iname "\$2" | tr ' ' '@') ); select file in "\${files[@]//@/ }"; do \${3:-xdg-open} "\$file"; break; done }` You can replace the @ with any character that probably wont be in a file name.

-1
findopen() { local PS3="select file: "; select file in \$(find "\$1" -iname "\$2"); do \${3:-xdg-open} \$file; break; done }
· 2010-02-28 02:28:59
• Monitoring TCP connections number showing each state. It uses ss instead of netstat because it's much faster with high trafic. You can fgrep specific ports by piping right before awk: watch "ss -nat | fgrep :80 | awk '"'{print \$1}'"' | sort | uniq -c" Show Sample Output

-1
watch "ss -nat | awk '"'{print \$1}'"' | sort | uniq -c"
· 2012-12-07 19:07:33
• Same thing just a different way to get there. You will need lynx

-1
lynx --dump --source http://www.xkcd.com | grep `lynx --dump http://www.xkcd.com | egrep '(png|jpg)'` | grep title | cut -d = -f2,3 | cut -d '"' -f2,4 | sed -e 's/"/|/g' | awk -F"|" ' { system("display " \$1);system("echo "\$2); } '
· 2009-12-03 18:53:57
• % lsof -v lsof version information: revision: 4.78

-1
lsof | awk '/*:https?/{print \$2}' | sort -u
· 2011-02-04 01:37:17
• Needs rpmorphan installed Show Sample Output

-1
ruby -e 'puts `rpmdep glibc`.split(",")[2..-1]'
· 2011-10-26 16:44:59

• -1
find . -name *.properties -exec /bin/echo {} \; -exec cat {} \; | grep -E 'listen|properties'
· 2014-02-17 02:25:49

• -1
pkill -HUP syslogd
· 2009-02-09 09:32:06
• This command, when run from the directory containing "filename", will remove the file and any hard or symbolic links to the file.

-1
ls -ai | grep filename | find . -inum `awk '{print \$1}'` -exec rm {} \;
· 2011-02-04 10:29:54
• This uses wget instead of curl

-1
wget -q -O - http://www.perl.org/get.html | grep -m1 '\.tar\.gz' | sed 's/.*perl-//; s/\.tar\.gz.*//'
· 2011-08-19 23:38:10
• This is a slight variation of an existing submission, but uses regular expression to look for files instead. This makes it vastly more versatile, and one can easily verify the files to be kept by running ls | egrep "[REGULAR EXPRESSION]"

-1
ls | egrep -v "[REGULAR EXPRESSION]" | xargs rm -v
· 2010-04-01 02:40:40
• Pulls all instances of table out of information schema, executes a SELECT COUNT(*) on each table/database instance, and then strips out any empty tables. Show Sample Output

-1
TABLE_NAME=YYZ ; for DATABASE in \$(echo "SELECT TABLE_SCHEMA FROM information_schema.tables WHERE TABLE_NAME='\$TABLE_NAME'" | mysql -N) ; do echo -n "\$DATABASE: " ; echo "SELECT COUNT(*) FROM \$TABLE_NAME" | mysql \$DATABASE -N ; done | fgrep -v ': 0'
· 2011-12-08 16:31:36

• -1
TAKEOWN /A /R /F c:\SomeFolder
· 2013-08-29 01:43:29

• -1
ps -efL | grep <Process Name>
· 2014-09-11 16:35:31
• This will give you a friendly warning if a command doesn't exists. Show Sample Output

-1
command_not_found_handle() { echo 6661696c626f61742e2e2e0a | xxd -p -r; }
· 2009-12-03 21:33:35
• Check if SSH tunnel is open and open it, if it isn't. NB: In this example, 3333 would be your local port, 5432 the remote port (which is, afaik, usually used by PostgreSQL) and of course you should replace REMOTE_HOST with any valid IP or hostname. The example above let's you work on remote PostgreSQL databases from your local shell, like this: `psql -E -h localhost -p 3333`

-1
while true; do nc -z localhost 3333 >|/dev/null || (ssh -NfL 3333:REMOTE_HOST:5432 USER@REMOTE_HOST); sleep 15; done
· 2015-09-21 02:25:49
• I constantly need to work on my local computer, thus I need a way to download the codeigniter user guide, this is the wget way I figured.

-1
wget -r --no-parent http://codeigniter.com/user_guide/ ; mv codeigniter.com/user_guide/* . ; rm -rf codeigniter.com
· 2010-03-01 02:37:26
• thx Montecristo, thx hckhckhck

-1
cat > {filename} {your text} [^C | ^D]
· 2010-06-03 09:02:12
• This will delete the branch 'featureless' on the origin remote. Do not forget to delete the branch locally using: git branch -d featureless 'I got it here'-credit: http://gitready.com/beginner/2009/02/02/push-and-delete-branches.html I duplicated here incase you stumbled here first. Show Sample Output

-1
git push origin :featureless
· 2011-06-02 14:53:31

• -1
uname -m
· 2013-02-15 17:23:44
• Tested on Solaris.

-1
/usr/sbin/ifconfig -a|awk -F" " 'NR==4{print \$2}'
· 2009-12-04 18:41:29
• If there is update available for the package you can see upgrade is from which version to which version. Also you will get detail about which release the package belongs to (stable/testing/sid). Show Sample Output

-1
apt-show-versions <packagename>
· 2010-06-03 15:52:11

• -1
svn st | grep -e [MA] | egrep -ve '.project|.classpath|.properties|.sh|.number' | awk -F' ' '{ print \$2}' | xargs svn ci -m "message"
· 2011-03-10 15:32:36
• Using sed to print newlines as doing it in one line with diff is non-trivial.

-1
diff --changed-group-format='differs from line %dF to line %dL|' --unchanged-line-format='' \$FILE1 \$FILE2 | sed 's/|/\n/'
· 2011-06-02 15:04:36
• ‹ First  < 420 421 422 423 424 >  Last ›

### 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.