Commands using c++ (12)

  • Usage: clfavs username password num_favourite_commands file_in_which_to_backup


    25
    clfavs(){ URL="http://www.commandlinefu.com";wget -O - --save-cookies c --post-data "username=$1&password=$2&submit=Let+me+in" $URL/users/signin;for i in `seq 0 25 $3`;do wget -O - --load-cookies c $URL/commands/favourites/plaintext/$i >>$4;done;rm -f c;}
    suhasgupta · 2009-09-30 16:43:08 24
  • I've been using linux for almost a decade and only recently discovered that most terminals like putty, xterm, xfree86, vt100, etc., support hundreds of shades of colors, backgrounds and text/terminal effects. This simply prints out a ton of them, the output is pretty amazing. If you use non-x terminals all the time like I do, it can really be helpful to know how to tweak colors and terminal capabilities. Like: echo $'\33[H\33[2J'


    17
    for c in `seq 0 255`;do t=5;[[ $c -lt 108 ]]&&t=0;for i in `seq $t 5`;do echo -e "\e[0;48;$i;${c}m|| $i:$c `seq -s+0 $(($COLUMNS/2))|tr -d '[0-9]'`\e[0m";done;done
    AskApache · 2009-11-03 09:12:13 9
  • Requires aria2c but could just as easily wget or anything else. A great way to build up a nice font collection for Gimp without having to waste a lot of time. :-) Show Sample Output


    10
    d="www.dafont.com/alpha.php?";for c in {a..z}; do l=`curl -s "${d}lettre=${c}"|sed -n 's/.*ge=\([0-9]\{2\}\).*/\1/p'`;for((p=1;p<=l;p++));do for u in `curl -s "${d}page=${p}&lettre=${c}"|egrep -o "http\S*.com/dl/\?f=\w*"`;do aria2c "${u}";done;done;done
    lrvick · 2010-05-18 07:38:54 4
  • /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
  • command to decrypt: openssl enc -aes-256-cbc -d < secret.tar.enc | tar x Of course, don't forget to rm the original files ;) You may also want to look at the openssl docs for more options.


    5
    tar c folder_to_encrypt | openssl enc -aes-256-cbc -e > secret.tar.enc
    recursiverse · 2009-07-23 06:03:39 4
  • You can tell GCC to automatically select optimization commands and produce optimized code for the local machine (the one compiling the code), but you can't normally see what switches have been selected and used unless you append a "-v" and pause compilation. Show Sample Output


    5
    cc -march=native -E -v - </dev/null 2>&1 | grep cc1
    manny79 · 2009-08-21 09:47:37 11
  • Avoids creating useless directory entries in archive, and sorts files by (roughly) extension, which is likely to group similar files together for better compression. 1%-5% improvement.


    2
    find . \! -type d | rev | sort | rev | tar c --files-from=- --format=ustar | bzip2 --best > a.tar.bz2
    pornel · 2009-12-20 14:04:39 3
  • First argument: string to put a box around. Second argument: character to use for box (default is '=') Same as command #4962, cleaned up, shortened, and more efficient. Now a ' * ' can be used as the box character, and the variables get unset so they don't mess with anything else you might have. They marked c++ as a function for this command, but I'm not sure why. Must be a bug. Show Sample Output


    2
    box(){ c=${2-=}; l=$c$c${1//?/$c}$c$c; echo -e "$l\n$c $1 $c\n$l"; unset c l;}
    mightybs · 2010-02-26 17:14:52 3
  • Will handle pretty much all types of CSV Files. The ^M character is typed on the command line using Ctrl-V Ctrl-M and can be replaced with any character that does not appear inside the CSV. Tips for simpler CSV files: * If newlines are not placed within a csv cell then you can replace `map(repr, r)` with r Show Sample Output


    1
    python -c 'import sys,csv; c = csv.reader(sys.stdin); [sys.stdout.write("^M".join(map(repr,r))+"\n") for r in c];' <tmp/test.csv | column -s '^M' -t
    pykler · 2010-02-01 14:57:25 7
  • When you need to add another tty device that can automatically start at boot time


    0
    sudo mknod /dev/ttyS4 c 4 68
    0disse0 · 2009-09-05 09:12:44 4
  • Thanks th John_W for suggesting the fix allowing ~/ to be used when saving a directory. directions: Type in a url, it will show a preview of what the file will look like when saved, then asks if you want to save the preview and where you want to save it. Great for grabbing the latest commandlinefu commands without a full web browser or even a GUI. Requires: w3m Show Sample Output


    0
    read -p "enter url:" a ; w3m -dump $a > /dev/shm/e1q ; less /dev/shm/e1q ; read -p "save file as text (y/n)?" b ; if [ $b = "y" ] ; then read -p "enter path with filename:" c && touch $(eval echo "$c") ; mv /dev/shm/e1q $(eval echo "$c") ; fi ; echo DONE
    LinuxMan · 2010-07-13 22:36:38 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

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

force unsupported i386 commands to work on amd64
The above was done using the i386 flashplayer plugin, and was installed on a AMD64 machine running an AMD64 kernel and AMD64 programs. the resulting plugin install ultimately didn't work for swiftfox (but worked for iceweasel) without also covering it with a nspluginwrapper which took a bit of fenangaling to get to work (lots of apt-getting) but it is a nice feature to be able to trick installers that think you need i386 into running on a amd64, or at least attempting to run on amd64. Enjoy

Gets the english pronunciation of a phrase
Usage examples: say hello say "hello world" say hello+world

Generat a Random MAC address
Generate a random MAC address with capital letters

Extract tarball from internet without local saving

Check whether laptop is running on battery or cable
The original proc file doesn't exist on my system.

Install pip with Proxy
Installs pip packages defining a proxy

Track X Window events in chosen window
After executing this, click on a window you want to track X Window events in. Explaination: "xev will track events in the window with the following -id, which we get by greping window information obtained by xwininfo"

dont execute command just add it to history as a comment, handy if your command is not "complete" yet

list files recursively by size

Get the IP address
gives u each configured IP in a seperate line.


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: