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

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

HTTP GET request on wireshark remotly

Use vim automation to create a colorized html file

cycle through everything sox knows how to read, playing only the first three seconds
I wasted two hours reading the sox documentation and searching on the web for the format of some obscure fscking sound sample, and then finally came up with this. This plays only the first three seconds of your unknown formatted sound file using every one of sox's built-in filetypes. If you don't get an exact match, you may get close. . I could not fit every single type in and keep it under 127 characters, so you will have to replace "..." with the full list obtainable by `$ sox --help` (or try `Show sample output`) . note: /usr/bin/play should be linked to sox on most systems.

kill all foo process
Kill all processes with foo in them. Similar to pkill but more complete and also works when there is no pkill command. Works on almost every Linux/Unix platform I have tried.

List out classes in of all htmls in directory
Lists out all classes used in all *.html files in the currect directory. usefull for checking if you have left out any style definitions, or accidentally given a different name than you intended. ( I have an ugly habit of accidentally substituting camelCase instead of using under_scores: i would name soemthing counterBox instead of counter_box) WARNING: assumes you give classnames in between double quotes, and that you apply only one class per element.

Clean config from # and empty strings

Hide or show Desktop Icons on MacOS
Hides all Files and Folders on the MacOS Desktop. To show files and folders, type "true" instead of "false". "Finder" at the end is case sensitive, "finder" doesn’t work

generate random tone

Show crontabs for all users
This is flatcaps tweaked command to make it work on SLES 11.2


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: