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 10

  • 8
    gcc -dM -E - < /dev/null
    ohe · 2009-10-28 14:13:19 11
  • 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 10
  • /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 48
  • 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 7

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


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

  • 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 4

  • 0
    gcc -E code.c | sed '/^\#/d' | indent -st -i2 > code-x.c
    enikulenkov · 2012-06-18 22:20:33 5
  • 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 7
  • 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 7

  • 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 7
  • 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 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. 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 20
  • 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"

Extract raw URLs from a file
you can also use cut instead of awk. less powerful but probably faster. ;)

drop first column of output by piping to this

Find ulimit values of currently running process
When dealing with system resource limits like max number of processes and open files per user, it can be hard to tell exactly what's happening. The /etc/security/limits.conf file defines the ceiling for the values, but not what they currently are, while $ ulimit -a will show you the current values for your shell, and you can set them for new logins in /etc/profile and/or ~/.bashrc with a command like: $ ulimit -S -n 100000 >/dev/null 2>&1 But with the variability in when those files get read (login vs any shell startup, interactive vs non-interactive) it can be difficult to know for sure what values apply to processes that are currently running, like database or app servers. Just find the PID via "ps aux | grep programname", then look at that PID's "limits" file in /proc. Then you'll know for sure what actually applies to that process.

convert Decimal to IP from stdin
https://stackoverflow.com/questions/10768160/ip-address-converter

Fibonacci With Case
Returns the '$1'th Fibonacci number.

how to export a table in .csv file
Exports the result of query in a csv file

list block devices
Shows all block devices in a tree with descruptions of what they are.

Determine next available UID
Typical usage would be in a script that would want the next open UID in a range (in this case 500-600)

Count opening and closing braces in a string.
This function counts the opening and closing braces in a string. This is useful if you have eg long boolean expressions with many braces and you simply want to check if you didn't forget to close one.


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: