Commands by pykler (19)

  • Gets all kind of info, ifconfig.me rocks ... for just the ip addess you can use ifconfig.me or ifconfig.me/ip Show Sample Output


    9
    curl ifconfig.me/all
    pykler · 2012-05-16 18:22:28 8
  • Will split the std input lines into files grouped by the 5th column content.


    0
    awk -F'\t' '{print $0 >>$5.tsv}'
    pykler · 2012-05-16 18:18:16 3
  • Realtime lines per second in a log file using python ... identical to perl version, except python is much better :) Show Sample Output


    0
    tail -F /var/log/nginx/access.log | python -c 'exec("import sys,time\nl=0\ne=int(time.time())\nfor line in sys.stdin:\n\tt = int(time.time())\n\tl += 1\n\tif t > e:\n\t\te = t\n\t\tprint l\n\t\tl = 0")'
    pykler · 2012-05-15 21:56:46 4
  • locating packages held back, such as with "aptitude hold "


    1
    aptitude search ~ahold
    pykler · 2012-04-29 15:02:32 4

  • 17
    fuser -v 80/tcp
    pykler · 2011-12-16 14:51:34 3

  • 4
    rsync -rv --exclude .svn src/dir/ dest/dir/
    pykler · 2011-11-15 21:42:22 8

  • 4
    lsof -Pn | grep LISTEN
    pykler · 2011-09-29 18:21:51 10
  • An example config file is placed in the sample output along with the command line call to use it. The rsync daemon here is setup on the destination, thus requiring the read only = false flag. Also it uses uid and gid of root, change as required. Show Sample Output


    -3
    rsync --daemon --port 9999 --no-detach -v --config .rsyncd.conf
    pykler · 2011-09-22 20:48:31 3
  • Doesn't work so well if you connect from windows. Linux only sends LF where windows wants CRLF. The alternative command works better with windows, however it uses script and a named pipe.


    4
    bash -i 2>&1 | tee /dev/stderr | nc -l 5000
    pykler · 2010-10-20 18:32:12 3
  • Similar output to using MySQL with the \G at the end of a Query. Displays one column per line. Other modes include: -column Query results will be displayed in a table like form, using whitespace characters to separate the columns and align the output. -html Query results will be output as simple HTML tables. -line Query results will be displayed with one value per line, rows separated by a blank line. Designed to be easily parsed by scripts or other programs -list Query results will be displayed with the separator (|, by default) character between each field value. The default. From inside the command line this can be also changed using the mode command: .mode MODE ?TABLE? Set output mode where MODE is one of: csv Comma-separated values column Left-aligned columns. (See .width) html HTML code insert SQL insert statements for TABLE line One value per line list Values delimited by .separator string tabs Tab-separated values tcl TCL list elements Show Sample Output


    0
    sqlite3 -line database.db
    pykler · 2010-10-09 16:10:19 8
  • Enable readline even if the command line application is not using it. Show Sample Output


    8
    rlwrap sqlite3 database.db
    pykler · 2010-10-09 15:56:08 7
  • Creates a 5 minute flv file, with the given sequence of images and audio with 0.5 fps. The images were created using the following command: for x in `seq 0 300`; do cp ../head.PNG head-`printf '%03d' $x`.png; done You can also inject metadata to seek easier using yamdi as follows: yamdi -i muxed.flv -o video.flv Show Sample Output


    4
    ffmpeg -t 300 -r '0.5' -i head-%03d.png -i ../TvQuran.com__144.mp3 -acodec copy muxed.flv
    pykler · 2010-10-07 16:29:08 3
  • With a lolcat favicon if you access it from your browser Show Sample Output


    -2
    curl icanhazip.com
    pykler · 2010-06-14 18:47:11 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
  • Prints the unique IP Addresses as they arrive from an Apache `access.log` file. The '-W interactive' tells awk to start writing to stdout immediately and not buffer the output. This command builds on the uniq lines without sorting command (http://www.commandlinefu.com/commands/view/4389/remove-duplicate-entries-in-a-file-without-sorting.)


    1
    tail -f /var/log/apache2/access.log | awk -W interactive '!x[$1]++ {print $1}'
    pykler · 2010-01-12 15:23:03 9
  • Calculates the size on disk for each package installed on the filesystem (or removed but not purged). This is missing the | sort -rn which would put the biggest packges on top. That was purposely left out as the command is slightly on the slow side Also you may need to run this as root as some files can only be checked by du if you can read them ;) Show Sample Output


    5
    dpkg --get-selections | cut -f1 | while read pkg; do dpkg -L $pkg | xargs -I'{}' bash -c 'if [ ! -d "{}" ]; then echo "{}"; fi' | tr '\n' '\000' | du -c --files0-from - | tail -1 | sed "s/total/$pkg/"; done
    pykler · 2009-10-12 14:57:54 5
  • Same as the cool matrix style command ( http://www.commandlinefu.com/commands/view/3652/matrix-style ), except replacing the printed character with randomness. The command mentioned is much faster and thus more true to the matrix. However, mine can be optimized, but I wasted ... i mean spent enough time on it already Show Sample Output


    6
    check the sample output below, the command was too long :(
    pykler · 2009-09-29 19:30:10 135
  • Splits the input based on commas and prints it in a nice column format. This would not work for CSV rows that have "," between quotes or with newline characters. Use only simple simple csv files. Show Sample Output


    18
    column -s, -t <tmp.csv
    pykler · 2009-09-24 20:57:32 11
  • Using netcat, usuallly installed on debian/ubuntu. Also to test against a sample server the following two commands may help echo got milk? | netcat -l -p 25 python -c "import SocketServer; SocketServer.BaseRequestHandler.handle = lambda self: self.request.send('got milk?\n'); SocketServer.TCPServer(('0.0.0.0', 25), SocketServer.BaseRequestHandler).serve_forever()" Show Sample Output


    2
    echo foo | netcat 192.168.1.2 25
    pykler · 2009-09-13 01:33:02 4

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

Replicate a directory structure dropping the files

diff files while disregarding indentation and trailing white space
**NOTE** Tekhne's alternative is much more succinct and its output conforms to the files actual contents rather than with white space removed My command on the other hand uses bash process substitution (and "Minimal" Perl), instead of files, to first remove leading and trailing white space from lines, before diff'ing the streams. Very useful when differences in indentation, such as in programming source code files, may be irrelevant

find out how many days since given date
You can also do this for seconds, minutes, hours, etc... Can't use dates before the epoch, though.

Graphically show percent of mount space used
Automatically drops mount points that have non-numeric sizes (e.g. /proc). Tested in bash on Linux and AIX.

Adequately order the page numbers to print a booklet
Useful if you don't have at hand the ability to automatically create a booklet, but still want to. F is the number of pages to print. It *must* be a multiple of 4; append extra blank pages if needed. In evince, these are the steps to print it, adapted from https://help.gnome.org/users/evince/stable/duplex-npage.html.en : 1) Click File ▸ Print. 2) Choose the General tab. Under Range, choose Pages. Type the numbers of the pages in this order (this is what this one-liner does for you): n, 1, 2, n-1, n-2, 3, 4, n-3, n-4, 5, 6, n-5, n-6, 7, 8, n-7, n-8, 9, 10, n-9, n-10, 11, 12, n-11... ...until you have typed n-number of pages. 3) Choose the Page Setup tab. - Assuming a duplex printer: Under Layout, in the Two-side menu, select Short Edge (Flip). - If you can only print on one side, you have to print twice, one for the odd pages and one for the even pages. In the Pages per side option, select 2. In the Page ordering menu, select Left to right. 4) Click Print.

Sort files by date
Show you the list of files of current directory sorted by date youngest to oldest, remove the 'r' if you want it in the otherway.

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

reverse-i-search: Search through your command line history
"What it actually shows is going to be dependent on the commands you've previously entered. When you do this, bash looks for the last command that you entered that contains the substring "ls", in my case that was "lsof ...". If the command that bash finds is what you're looking for, just hit Enter to execute it. You can also edit the command to suit your current needs before executing it (use the left and right arrow keys to move through it). If you're looking for a different command, hit Ctrl+R again to find a matching command further back in the command history. You can also continue to type a longer substring to refine the search, since searching is incremental. Note that the substring you enter is searched for throughout the command, not just at the beginning of the command." - http://www.linuxjournal.com/content/using-bash-history-more-efficiently

Get the list of local files that changed since their last upload in an S3 bucket
Can be useful to granulary flush files in a CDN after they've been changed in the S3 bucket.

print DateTimeOriginal from EXIF data for all files in folder
see output from `identify -verbose` for other keywords to filter for (e.g. date:create, exif:DateTime, EXIF:ExifOffset).


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: