Hackosis is an Open Blog. You Can Participate.

  • 09
  • Apr

Shell-FuShell-Fu is a place for everyone to store those hard to remember *nix commands.

This is so simple yet very useful.

Some of my favorites:

Running a second command with the same arguments as the previous command, use ‘!*’ to repeat all arguments or ‘!:2′ to use the second argument. ‘!$’ uses the final argument.

$ cd /home/user/foo

cd: /home/user/foo: No such file or directory

$ mkdir !*

mkdir /home/user/foo

Make a whole directory tree with one command
Use the -p option to mkdir and make all parent directories along with their children in a single command.

mkdir -p tmp/a/b/c

This is a simpler password generator.

/dev/urandom tr -dc A-Za-z0-9_ | head -c8

Do you have any tips for *nix command line? Let us know in the comments.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Related Posts


Tags: ,

Like this post? Subscibe to the RSS feed.


7 Comments

  1. meathive Says:

    The site’s sweet - I post one-liners on my site occasionally just because I know I’ll forget them. I added a Bash variant for the Caesar encryption and the /dev/tcp socket connection trick.

    Bash Rot-13 encryption:
    $ cat file|tr A-Za-z N-ZA-Mn-za-m

    Bash Rot-47 encryption:
    $ cat file|tr ‘!-~’ ‘P-~!-O’

    #!/bin/bash
    exec 3/dev/tcp/kinqpinz.info/80
    echo -e “GET / HTTP/1.1\nHost: kinqpinz.info;\nConnection: close\n\n”>&3
    cat <&3

  2. jon Says:

    Repeat a mistyped command with a correction:
    $ mkdri blah
    bash: mkdri: command not found
    $ ^dri^dir
    mkdir blah

  3. Peter Lowe Says:

    The password generator in the post won’t work - it should actually be something like:

    $ tr -dc A-Za-z0-9_ < /dev/urandom | head -c8

    meathive, please collect your Useless Use of Cat award at the podium!

    And finally, as a bash tip related to jon’s comment showing how to repeat commands with corrections, this:

    $ shopt -s cdspell

    enables a feature in bash that will automatically correct directory names that you spell incorrectly when using cd. eg:

    [jem:pgl]:~ $ cd public_htlm
    public_html
    [jem:pgl]:~/public_html $

    Hooray for bash.

  4. Kyle Brandt Says:

    To get the last argument of the previous command you can use the keyboard shortcut Escape and then Period:
    ‘ESC’ + ‘.’
    Also for the same result
    ‘Alt’ + ‘.’
    ‘Alt’ - ‘_’ #At same time
    Pressing this multiple times will cycle through the last argument of previous commands. This is a readline shortcut.

  5. [Shell-Fu]$: almacén online de comandos útiles y extremos Says:

    [...] | Hackosis Enlace | [...]

  6. Tecnologia » Blog Archiv » [Shell-Fu]$: almacén online de comandos útiles y extremos Says:

    [...] | Hackosis Enlace | [...]

  7. meathive Says:

    Peter, I love awards!

Leave a Comment