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 gcc from sorted by
Terminal - Commands using gcc - 18 results
gcc -dM -E - </dev/null
2013-09-30 15:08:34
User: slower
Functions: gcc
Tags: gcc
3

Lists all macros and their values defined by gcc.

vim test.c && gcc -x c -o a.out test.c && ./a.out && rm a.out test.c
f=220;echo "int s=16e3/$f;main(i){unsigned char v[s];read(0,v,s);for(;;)putchar(v[i%s]=(v[i%s]+v[++i%s])/2);}"|gcc -x c -&&./a.out</dev/urandom|aplay -d 2
2013-06-28 14:52:53
User: tehdog
Functions: aplay echo gcc
Tags: alsa sh gcc
7

outputs a f=220Hz guitar string sound (fifth string A)

needs ALSA

sudo apt-get install git gcc make libx11-dev libxtst-dev pkg-config -y && git clone https://github.com/hanschen/ksuperkey.git && cd ksuperkey && make && sudo mv ksuperkey /usr/bin/ksuperkey && cd ~ && rm -rf ksuperkey
2013-04-17 07:12:46
User: FadeMind
Functions: cd gcc install make mv rm sudo
0

Install Ksuperkey one command in Kubuntu.

You must manually add ksuperkey to autostart in System Settings KDE.

echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay
2013-02-17 21:31:04
User: SNDR
Functions: echo gcc
Tags: aplay
9

Try modifying the numbers in the "(i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6)" part.

Crudely stolen from http://www.xkcdb.com/9067

echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i >>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay
2013-01-09 21:48:23
User: r0nd0n
Functions: echo gcc
0

Something I pulled off 4chan, it plays a tune.

gcc -E code.c | sed '/^\#/d' | indent -st -i2 > code-x.c
gcc -dM -E - < /dev/null
for c in gcc bison dialog bc asdf; do if ! which $c >/dev/null; then echo Required program $c is missing ; exit 1; fi; done
echo | gcc -dM -E -
cat | gcc -x c -o a.out - && ./a.out && rm a.out
2009-12-27 04:37:24
User: dgalling
Functions: c++ cat gcc rm
-2

This should work on any unix platform running bash. Just type the program into cat and give it a ^D when you're done, at which time it will compile, run, and remove the program. Obviously, you can run it without the "rm a.out" if you'd like to keep the binary. If you want to keep the source, well, you might as well just write it in vi or emacs first then.

alias cstdin='echo "Ctrl-D when done." && gcc -Wall -o ~/.stdin.exe ~/.stdin.c && ~/.stdin.exe'
2009-11-19 16:38:51
User: taliver
Functions: alias gcc
-3

This is a quick hack to make a gcc caller. Since it runs with gcc instead of tcc, it's a bit more trustworthy as far as the final answers of things go.

gcc -dM -E - <<<''
gcc -dM -E - < /dev/null
gcc -x c -o /tmp/out - -lgmp <<< '#include <stdlib.h> ... SEE SAMPLE OUTPUT FOR FULL COMMAND
2009-09-10 02:10:46
User: hank
Functions: c++ gcc
-5

It's hard to beat C. This is just slightly faster than the bc version on my machine.

real 0m26.856s

user 0m25.030s

sys 0m0.024s

Requirements: libgmp headers, gcc.

ls *.c | while read F; do gcc -Wall -o `echo $F | cut -d . -f 1 - ` $F; done
2009-08-28 13:01:56
User: pichinep
Functions: cut gcc ls read
-7

Compile *.c files with "gcc -Wall" in actual directory, using as output file the file name without extension.

/lib/ld-linux.so.2 =(echo -e '#include <stdio.h>\nint main(){printf("c one liners\\n");}' | gcc -x c -o /dev/stdout -)
2009-02-20 06:06:29
User: mrtheplague
Functions: c++ echo gcc
6
/lib/ld-linux.so.2

is the runtime linker/loader for ELF binaries on Linux.

=(cmd) is a zsh trick to take the output for the command "inside" it and save it to a temporary file.

echo -e 'blah' | gcc -x c -o /dev/stdout -

pipes the C source to gcc. -x c tells gcc that it's compiling C (which is required if it's reading from a pipe). -o /dev/stdout - tells it to write the binary to standard output and read the source from standard input.

because of the the =() thing, the compiled output is stashed in a tempfile, which the loader then runs and executes, and the shell tosses the tempfile away immediately after running it.

gcc -Wall -Werror -o prog prog.c || rm -f prog.c