Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm following through a tutorial and it mentions to run this command:

sudo chmod 700 !$

I'm not familiar with !$. What does it mean?

share|improve this question
4  
It's generally safe to try to echo something if you're not sure what it'll do. –  Shadur Aug 29 '13 at 7:17
4  
@Shadur, not always. echo $(rm -rf /) –  cjm Aug 30 '13 at 3:20
    
@cjm Unless you're on a really old system, you'll need the --no-preserve-root option in there, and if you see the words "no preserve" in a program you better think real carefully about what it does. –  WChargin Sep 2 '13 at 13:14
    
@WChargin Be very careful assuming that "really old" and "not Linux/not using GNU coreutils" are the same thing; they aren't. –  Chris Down Nov 1 '13 at 8:31

1 Answer 1

up vote 29 down vote accepted

Basically, it's the last argument to the previous command.

!$ is the "end" of the previous command. Consider the following example: We start by looking for a word in a file:

grep -i joe /some/long/directory/structure/user-lists/list-15

if joe is in that userlist, we want to remove him from it. We can either fire up vi with that long directory tree as the argument, or as simply as vi !$ Which bash expands to:

vi /some/long/directory/structure/user-lists/list-15

(source; handy guide, by the way)

share|improve this answer
6  
Nice. Good to know. Also, good thing there's Stack Exchange. It's hard to search Google for something like !$ –  Andrew Aug 29 '13 at 5:27
4  
BTW, on the command line, you can insert the last argument of the previous command by insert-last-argument, usually bound to M-.. –  choroba Aug 29 '13 at 6:25
    
@Andrew please remember to accept this if it answers your question. Accepting and upvoting rather than posting comments are how thanks are expressed on the SE network, see here for the "official" stance. –  terdon Aug 29 '13 at 11:18
1  
@Andrew FYI, I searched Google for "bash bang dollar" and got decent results, including this link as the third listing. –  WChargin Aug 29 '13 at 13:14
1  
@terdon I tried to accept the answer last night, but it was so fast that I was forced to wait to accept it. –  Andrew Aug 29 '13 at 14:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.