Commands by greggster (7)

  • Use vim's diff mode to edit two or more files in one window. The '+diffoff!' turns off diff highlighting when the session is started. Use ctrl+w + ctrl+w to switch between windows. Show Sample Output


    2
    vim -d '+diffoff!' file1 file2
    greggster · 2012-08-30 07:51:41 7
  • Sort lines within vi editor. In this example sort lines 33-61 and lines 4-9 asciibetically. Show Sample Output


    6
    :33,61 !sort
    greggster · 2011-05-06 06:10:05 8
  • rm -rf .* matches ".." and thus one goes up a level and wipes out more than intended. In bash, .??* safely accomplishes what one intends - remove those .files The ? matches most characters except "/", thus .?? does not match ../ and so one is safe. Show Sample Output


    0
    rm -rf .??*
    greggster · 2011-03-11 07:21:58 9
  • When setting up a new aliases file, or having creating a new file.. About every time after editing an aliases file, I source it. This alias makes editing alias a bit easier and they are useful right away. Note if the source failed, it will not echo "aliases sourced". Sub in vi for your favorite editor, or alter for ksh, sh, etc.


    7
    alias va='vi ~/.aliases; source ~/.aliases && echo "aliases sourced"'
    greggster · 2011-03-10 06:41:37 7
  • This is for bash - make an alias - also a good blueprint for making aliases that take arguments to functions. If for Solaris use "-size +${1}000000c" to replace "-size +${1}M" Show Sample Output


    0
    alias big='BIG () { find . -size +${1}M -ls; }; BIG $1'
    greggster · 2011-03-10 06:33:00 7
  • until (ssh root@10.1.1.39 2> /dev/null); do date; sleep 15; done In this case will execute "date" then "sleep 15" until we are able to ssh into server, such as after a reboot Could also be like: until ( ping 10.1.1.39 1> /dev/null); do echo "server 10.1.1.39 is down"; sleep 15; done Show Sample Output


    8
    until (ssh root@10.1.1.39 2> /dev/null); do date; sleep 15; done
    greggster · 2011-03-08 08:42:12 9
  • This is useful for quickly jumping around branches in a file system, or operating on a parellel file. This is tested in bash. cd to (substitute in PWD, a for b) where PWD is the bash environmental variable for the "working directory" Show Sample Output


    7
    cd ${PWD/a/b}
    greggster · 2011-03-03 06:27:12 11

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

Makes you look busy
This makes an alias for a command named 'busy'. The 'busy' command opens a random file in /usr/include to a random line with vim. Drop this in your .bash_aliases and make sure that file is initialized in your .bashrc.

list files recursively by size

Generate random valid mac addresses
Doubt it actually generates valid mac addresses but this version doesn't need any external commands so it runs much faster. Much shorter as well.

List out classes in of all htmls in directory
Lists out all classes used in all *.html files in the currect directory. usefull for checking if you have left out any style definitions, or accidentally given a different name than you intended. ( I have an ugly habit of accidentally substituting camelCase instead of using under_scores: i would name soemthing counterBox instead of counter_box) WARNING: assumes you give classnames in between double quotes, and that you apply only one class per element.

Create a tar archive using xz compression
Compress files or a directory to xz format. XZ has superior and faster compression than bzip2 in most cases. XZ is superior to 7zip format because it can save file permissions and other metadata data.

Insert a line at the top of a text file without sed or awk or bash loops
Yet another way to add a line at the top a of text file with the help of the tac command (reverse cat).

Shows size of dirs and files, hidden or not, sorted.
Enhanced version: fixes sorting by human readable numbers, and filters out non MB or GB entries that have a G or an M in their name.

fast access to any of your favorite directory.
example: -------------------------------------------------------------------------------------------- user@ubuntu:~/workspace/SVN/haystak-repos/trunk/internal/src$ addpi -------------------------------------------------------------------------------------------- Now that directory is in the list of fast access directories. You can switch to it anytime like this: -------------------------------------------------------------------------------------------- user@ubuntu:~$ pi internal` user@ubuntu:~/workspace/SVN/haystak-repos/trunk/internal/src$ -------------------------------------------------------------------------------------------- Please note the backquote ( the symbol that shares its key with ~ in the keyboard ) pi will switch you to that directory. To see the list of all fast access directories you have to say "cat ~/.pi"

List recorded formular fields of Firefox
When you fill a formular with Firefox, you see things you entered in previous formulars with same field names. This command list everything Firefox has registered. Using a "delete from", you can remove anoying Google queries, for example ;-)

know the current running shell (the true)
Return the current shell. It is better than print $SHELL which can sometimes return a false value.


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: