Commands by ruslan (10)

  • Checks for syntax errors in PHP files modified in current working copy of a Git repository. Show Sample Output


    1
    git status -s | grep -o ' \S*php$' | while read f; do php -l $f; done
    ruslan · 2013-12-14 11:47:54 9
  • The sample command searches for PHP files replacing tabs with spaces. -u NONE # don't use vimrc Instead of retab! one may pass retab! 4 for instance. Look at this http://susepaste.org/69028693 also


    -2
    find $DIR -name *.php -exec vim -u NONE -c 'set ft=php' -c 'set shiftwidth=4' -c 'set tabstop=4' -c 'set noexpandtab!' -c 'set noet' -c 'retab!' -c 'bufdo! "execute normal gg=G"' -c wq {} \;
    ruslan · 2011-04-08 11:42:45 5
  • M - current revision, N - older revision


    1
    svn diff -r M:N file.php | patch -p0
    ruslan · 2011-03-29 04:15:02 6
  • Creates HTML code from PHP source Show Sample Output


    1
    php -s source.php > source.html
    ruslan · 2011-03-10 15:11:35 4

  • 0
    wget http://cmyip.com -O - -o /dev/null | grep -Po '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
    ruslan · 2011-02-28 16:46:14 14
  • Get external IP of the current machine via http://cmyip.com Show Sample Output


    -3
    wget http://cmyip.com -O - -o /dev/null | awk '/\<title/ {print $4}'
    ruslan · 2011-02-15 05:58:30 5
  • in Debian-based systems apt-get could be limited to the specified bandwidth in kilobytes using the apt configuration options(man 5 apt.conf, man apt-get). I'd quote man 5 apt.conf: "The used bandwidth can be limited with Acquire::http::Dl-Limit which accepts integer values in kilobyte. The default value is 0 which deactivates the limit and tries uses as much as possible of the bandwidth..." "HTTPS URIs. Cache-control, Timeout, AllowRedirect, Dl-Limit and proxy options are the same as for http..."


    2
    sudo apt-get -o Acquire::http::Dl-Limit=20 -o Acquire::https::Dl-Limit=20 upgrade -y
    ruslan · 2011-02-14 05:24:49 4
  • This form is used in patches, svn, git etc. And I've created an alias for it: alias diff='diff -Naur --strip-trailing-cr' The latter option is especially useful, when somebody in team works in Windows; could be also used in commands like svn diff --diff-cmd 'diff --strip-trailing-cr'... Show Sample Output


    4
    diff -Naur --strip-trailing-cr
    ruslan · 2011-02-10 14:32:42 5
  • If colordiff utility installed, it is sometimes handy to call this command. Of course, you should create an alias for it. E.g. svndiff.


    1
    svn diff --diff-cmd="colordiff"
    ruslan · 2011-02-10 14:27:55 26
  • The command copies a file from remote SSH host on port 8322 with bandwidth limit 100KB/sec; --progress shows a progress bar --partial turns partial download on; thus, you can resume the process if something goes wrong --bwlimit limits bandwidth by specified KB/sec --ipv4 selects IPv4 as preferred I find it useful to create the following alias: alias myscp='rsync --progress --partial --rsh="ssh -p 8322" --bwlimit=100 --ipv4' in ~/.bash_aliases, ~/.bash_profile, ~/.bash_login or ~/.bashrc where appropriate. Show Sample Output


    17
    rsync --progress --partial --rsh="ssh -p 8322" --bwlimit=100 --ipv4 user@domain.com:~/file.tgz .
    ruslan · 2011-02-10 14:25:22 12

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

Simple server which listens on a port and prints out received data
Sometimes you need a simple server which listens on a port and prints out received data. Example: Consider you want to know, which data is posted by a homepage to a remote script without analysing the html code! A simple way to do this is to save the page to your computer, substitude all action="address" with action="localhost:portnumber", run 'ncat -l portnumber' and open the edited page with your browser. If you then submit the form, ncat will print out the http-protocol with all the posted data.

Find out current working directory of a process

find and delete empty dirs, start in current working dir

Find the package that installed a command

Sort all running processes by their memory & CPU usage
you can also pipe it to "tail" command to show 10 most memory using processes.

Find the package that installed a command

Get each users commit amount

Show git branches by date - useful for showing active branches

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

Tar - Compress by excluding folders
If you give tar a list of filenames, it will not add the directories, so if you don't care about directory ownership or permissions, you can save some space. Tar will create directories as necessary when extracting. This command is limited by the maximum supported size of the argument list, so if you are trying to tar up the whole OS for instance, you may just get "Argument list too long".


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: