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

    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 2

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

    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 3
  • /lib/ 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

    /lib/ =(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 12
  • doesn't need /dev/null Show Sample Output

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

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

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

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

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

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

    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 1
  • Install Ksuperkey one command in Kubuntu. You must manually add ksuperkey to autostart in System Settings KDE.

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

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

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

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

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

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

What's this? 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

Save your open windows to a file so they can be opened after you restart
This will save your open windows to a file (~/.windows). To start those applications: $ cat ~/.windows | while read line; do $line &; done Should work on any EWMH/NetWM compatible X Window Manager. If you use DWM or another Window Manager not using EWMH or NetWM try this: $ xwininfo -root -children | grep '^ ' | grep -v children | grep -v '' | sed -n 's/^ *\(0x[0-9a-f]*\) .*/\1/p' | uniq | while read line; do xprop -id $line _NET_WM_PID | sed -n 's/.* = \([0-9]*\)$/\1/p'; done | uniq -u | grep -v '^$' | while read line; do ps -o cmd= $line; done > ~/.windows

Mutt - Change mail sender.

exec chmod to subfiles
Using `-exec cmd {} +` causes find to build the command using all matching filenames before execution, rather than once per file.

Outputs a 10-digit random number

Command to logout all the users in one command
It's only to logout all other user's except "root"

Detect illegal access to kernel space, potentially useful for Meltdown detection
Based on capsule8 agent examples, not rigorously tested

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Open (in vim) all modified files in a git repository
For editing files added to the index: $ vim `git diff --name-only --cached` To edit all changed files: $ vim `git diff --name-only HEAD` To edit changed files matching glob: $ vim `git diff --name-only -- '*.html'` If the commands needs to support filenames with whitespace, it gets a bit hacky (see for the reason): $ git diff --name-only -z | xargs -0 bash -c '

Add line number count as C-style comments
I often find the need to number enumerations and other lists when programming. With this command, create a new file called 'inputfile' with the text you want to number. Paste the contents of 'outputfile' back into your source file and fix the tabbing if necessary. You can also change this to output hex numbering by changing the "%02d" to "%02x". If you need to start at 0 replace "NR" with "NR-1". I adapted this from

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

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.


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: