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 am curious to know what trick you use to remember options for various commands? Looking up man pages all the time is time consuming and not so cool!

share|improve this question
2  
Among other things: unix.stackexchange.com/questions/138720/… is handy for creating a customized summary of things I habitually screw up or forget. BTW, the more you read man pages, the more you come to appreciate them. –  goldilocks yesterday
    
I some time feel i am forgetting everything. I was wondering if i am the only one who has hard time remembering all useful options on top of the head..Your suggestion seems like a good solution..Thank you! –  Atul yesterday
    
Use a shell with completion like zsh. –  Stéphane Chazelas yesterday
2  
Reading man pages is very cool... :) –  jasonwryan 23 hours ago
4  
I think this deserves some XKCD: xkcd.com/1168 –  Darkhogg 19 hours ago

6 Answers 6

The trick is simple: You just don't. It's a waste of time and just not necessary. Memorizing command options isn't a particularly useful skill. It's much more important to understand how stuff works in general and to have a vague idea which tools exist in the first place and what you use them for. A very important skill here is to know how to find out about stuff you don't know yet.

Man pages are time consuming? Not so. It's not like you have to read them - at least, not every time - there is a search function. So if I don't remember which cryptic option was the one for hdparm to disable idle timer on some WD disks, I do man hdparm and /idle3 and hey, it was -J. Looking stuff like that up is so quick I don't even remember doing it afterwards.

Imagine someone actually memorizing all of the hdparm options. What a waste of time.

It's fine if you just happen to remember options because you use them frequently. That happens automatically without even thinking about it. But actually consciously spending time on memorizing them... what's that supposed to be good for? A paper test?

share|improve this answer
    
Upvoted: the skill is finding what you need, not rote memory. man hdparm | less -p idle3 is also a handy way to jump to the desired term... –  jasonwryan 21 hours ago
    
I fully agree with this answer, though I think it's worth emphasizing that it is normal to have the few most common options to common programs memorized, just because you use them so often. Like rm -i -f -r, ln -s, df -s -h, cp -r -i, ls -l -h -a, etc. (the list varies from person to person). –  David Z 18 hours ago

Zsh has the run-help function, by default bound to Alth. With this function you can begin typing a command with many or complex options that are difficult to remember, like rsync for example, and then have that command's man page opened. So:

 rsync Alth

read the man page and work out which switches you require, hit q and then you are returned to your command prompt, exactly where you left off, ready to complete the command with the requisite options:

rysnc -azP file dir/

As the wiki notes:

The function can be further customized by defining helper functions of the form run-help-command. There are three such functions available in the standard distribution: run-help-git, run-help-svk, and run-help-svn.
share|improve this answer
    
Similarly bash has bash-complete which will supply a lot of parameter options for a lot of commands. –  ericx 23 hours ago
2  
@ericx "Similarly" might be overstating it a little... Zsh also has completion, this is a step up from that. –  jasonwryan 23 hours ago
    
hey... I've heard folks brag, but I've never tried zsh –  ericx 23 hours ago

Most commands have --help for quick reference, and it is usually enough to remind what was something that I used to know.

That said have a habit of writing --help instead of -h or even -?. You never know what -h is before looking usage output or manual page. In worst case the -h might be short hand for --hazardous-automatic-destruction.

share|improve this answer
2  
...Most commands on GNU systems. commands on Unix systems typically don't have --help. -? needs quoting with zsh, csh, tcsh or fish or if there are files whose name are - followed by a single character in the current directory. -: may be preferable there. –  Stéphane Chazelas 23 hours ago
    
Well.. many non GNU systems has so appalling usage outputs they are pointless to even look. In such case see man pages & best of luck memorizing by hard coz nothing else will work. –  kerolasa 22 hours ago
    
"That said have a habit of writing". Missing word? –  Faheem Mitha 22 hours ago

Using a very long command history, and seaching through it, is very useful.

I basically collect all shell history files, and grep through them.

The results found are in many cases very useful, as it's easy to seach for good keywords.
Searching for a speciffic argument you used, like an URL, you find the related commands and options too. And searching for speciffic options, you may find relevant arguments too.

share|improve this answer

I typically do:

man ${CMD} | grep 'what was I thinking about?'

Or some variation thereof. With some greps you can specify -C/A/B for context, after, and before respectively. If not, nl and sed can be pretty well matched:

man hdparm |                      #hard to forget
nl -bp'idle3' -nln -w1 |          #I had to grep man to put this together
sed -n '/^[0-9]/{N;N;N;s///p}'    #no print until line begins w/ number, next,next,next

           Drive's "idle3" timeout value.  This timeout
            controls how often the drive parks its heads
            and  enters  a  low power consumption state.
            The factory default is  eight  (8)  seconds,
           zero (0) to disable the WD idle3 timer  com‐
            pletely (NOT RECOMMENDED!).

     -k     Get/set  the "keep_settings_over_reset" flag

The same techniques work with --help menus if you have them, but you might need to do a ${CMD} --help 2>&1 | ..filter.. because is a fairly standard practice to print such things to stderr.

Anyway, I guess the moral of the story is, remember at least man and grep. Maybe don't sweat the rest.

share|improve this answer
1  
+1. I often grep man pages when looking for a particular feature, that's pretty handy. –  John WH Smith 10 mins ago

One option I like is to create aliases that have the same or similar options, e.g.

alias rmi='rm -i'
alias rmiv='rm -iv'
alias rmv='rm -v'
alias cpr='cp -r'
alias cprv='cp -rv'

This way you have a nice shortcut that you'll soon remember easily but that will also retain information about the actual option(s) it reflects.

Another approach with aliases is to pick the most common options and make a super short alias that uses them. For instance for ls I nearly always do l and that is because I have:

alias l='ls -alFtrG'

Another option is to just bring in the the options you like to the base command, e.g.

alias ls='ls -F --color=always'

Finally practice, practice, practice and patience. Keep typing common options and you will eventually learn them. The common ones in days, others in weeks and yes some take years to become known to you. Think of that as a treat in that unix programming will continue to entertain you for a long time.

Another option that I like is an alias to make searching my history easier and for that I have two similar aliases:

alias hg='history | tail -200 | grep -i'
alias hga='history | grep -i'

These let me search for uses of a command for instance:

hg ls will show any recent uses of ls from history
hga ls will show all uses of ls from my entire history.

I developed hg after finding that hga tended to show too much.

share|improve this answer
2  
If OP can't remember what rm -iv does, OP probably also won't remember what rmiv does. I don't think it's the hyphen that's the problem. –  tobyink 21 hours ago

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.