Commands using gcc (17)

  • 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


    10
    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
    SNDR · 2013-02-17 21:31:04 9

  • 8
    gcc -dM -E - < /dev/null
    ohe · 2009-10-28 14:13:19 8
  • outputs a f=220Hz guitar string sound (fifth string A) needs ALSA


    7
    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
    tehdog · 2013-06-28 14:52:53 9
  • /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. Show Sample Output


    6
    /lib/ld-linux.so.2 =(echo -e '#include <stdio.h>\nint main(){printf("c one liners\\n");}' | gcc -x c -o /dev/stdout -)
    mrtheplague · 2009-02-20 06:06:29 46
  • doesn't need /dev/null Show Sample Output


    4
    gcc -dM -E - <<<''
    bucciarati · 2009-10-28 14:26:56 3
  • Lists all macros and their values defined by gcc. Show Sample Output


    3
    gcc -dM -E - </dev/null
    slower · 2013-09-30 15:08:34 6

  • 2
    gcc -dM -E - < /dev/null
    lucasrangit · 2012-04-27 17:37:50 3
  • another one


    0
    echo | gcc -dM -E -
    Byung · 2011-05-09 09:59:24 3

  • 0
    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
    Mozai · 2011-06-27 12:54:02 3

  • 0
    gcc -E code.c | sed '/^\#/d' | indent -st -i2 > code-x.c
    enikulenkov · 2012-06-18 22:20:33 4
  • Something I pulled off 4chan, it plays a tune.


    0
    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
    r0nd0n · 2013-01-09 21:48:23 6
  • Install Ksuperkey one command in Kubuntu. You must manually add ksuperkey to autostart in System Settings KDE.


    0
    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
    FadeMind · 2013-04-17 07:12:46 6

  • 0
    vim test.c && gcc -x c -o a.out test.c && ./a.out && rm a.out test.c
    ari2015 · 2013-09-08 15:09:09 6
  • 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. Show Sample Output


    -3
    alias cstdin='echo "Ctrl-D when done." && gcc -Wall -o ~/.stdin.exe ~/.stdin.c && ~/.stdin.exe'
    taliver · 2009-11-19 16:38:51 4
  • 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. Show Sample Output


    -5
    gcc -x c -o /tmp/out - -lgmp <<< '#include <stdlib.h> ... SEE SAMPLE OUTPUT FOR FULL COMMAND
    hank · 2009-09-10 02:10:46 8

  • -6
    gcc -Wall -Werror -o prog prog.c || rm -f prog.c
    devoid · 2009-02-05 17:26:51 19
  • Compile *.c files with "gcc -Wall" in actual directory, using as output file the file name without extension.


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

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

Router discovery

Insert an element into xml
This inserts an element as last child under /breakfast_menu/food in simple.xml. xml used - http://www.w3schools.com/xml/simple.xml

Calculate days on which Friday the 13th occurs (inspired from the work of the user justsomeguy)
Friday is the 5th day of the week, monday is the 1st. Output may be affected by locale.

Extract audio stream from an video file using mencoder
This command extracts the audio stream of the video in $file and stores it in a file where the original suffix is changed to .mp3

Show IP Address in prompt --> PS1 var
when working with many machines in a computer lab need to know the IP addr is very large, this is a simplistic solution to make things easier

Recursive grep of all c++ source under the current directory
I like this better than some of the alternatives using -exec, because if I want to change the string, it's right there at the end of the command line. That means less editing effort and more time to drink coffee.

Extract tar.gz file with original permission
-x, --extract, --get extract files from an archive -p, --preserve-permissions, --same-permissions extract information about file permissions (default for superuser) -f, --file=ARCHIVE use archive file or device ARCHIVE -v, --verbose verbosely list files processed

Display packages and versions on Debian/Ubuntu distrib
Need admin right to run dpkg-query

display a smiling smiley if the command succeeded and a sad smiley if the command failed
you could save the code between if and fi to a shell script named smiley.sh with the first argument as and then do a smiley.sh to see if the command succeeded. a bit needless but who cares ;)

find largest file in /var
find largest file in /var


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: