5

In linux command cd, after make a dir, I can use "cd !!:1" to enter it, but what exactly does !!:1 mean, I can't search it by google, because it include special chars.

Eric
  • 22,183
  • 20
  • 145
  • 196
  • 1
    The double exclamation repeats the previous command. I would guess that the :1 pulls the second part of the previous command, as opposed to the entire thing—but I don't know that with certainty. – Pete Scott Jun 27 '14 at 03:03

2 Answers2

5

That will change directory to the first argument of the previous command

For example

% ls foo bar
% cd !!:1

is equivalent to

% ls foo bar
% cd foo

Also !!:0 gives you the actual command (less arguments), !!:2 the second argument, !!:$ the last argument, and !! the whole command line.

Bull
  • 11,771
  • 9
  • 42
  • 53
3

!! is short hand for the previous command. The :1 goes to the second parameter in the command, which in your previous command was the directory name.

One of my favorite command-line shortcuts is sudo !!

Blake G
  • 581
  • 7
  • 24