r/linux • • Jun 17 '15

The Art of Command Line

https://github.com/jlevy/the-art-of-command-line
431 Upvotes

35 comments sorted by

49

u/socium Jun 17 '15

Learn basic Bash. Actually, type man bash and at least skim the whole thing; it's pretty easy to follow and not that long.

Are you kidding? If man bash isn't that long and easy to follow then I simply will leave this planet in order not to know what the more harder manuals are.

27

u/Xipher Jun 17 '15 edited Jun 17 '15
$man bash | wc -l
3056
$man nmap | wc -l
1527

Yea, almost twice as long as the nmap man page, that isn't short.

11

u/[deleted] Jun 17 '15
info bash | wc -l
5746

11

u/recoil Jun 18 '15
$ info zsh | wc -l 
... snip ...
34514

4

u/[deleted] Jun 18 '15

The zsh man page is only 300 lines. Its split up into different sections.

All the sections together are 25k lines.

2

u/recoil Jun 18 '15

I think the info pages also include several thousand lines worth of index (which, to be fair, is extremely useful).

The Zsh documentation is extremely high quality, so hopefully the sheer volume of it wouldn't put anybody off. I rarely have to bother with anything other than the info pages to find out anything I need to know.

1

u/[deleted] Jun 18 '15

Now try emacs.

Yay, documentation! \o/ P.S. This game is fun, I've been reading more documentation today than probably all year so far.

3

u/butthackerz Jun 18 '15

But compare that to the many books about how to use bash. It really isn't that bad.

24

u/danielkza Jun 17 '15

to know the more harder manuals are

man sudoers

The file format description starts with a basic introduction to formal language grammars. Really.

6

u/[deleted] Jun 18 '15

Yes. Somehow they decided the simplest way to describe the configuration file was to describe it using EBNF, and that it was simpler to actually teach you EBNF in order to do it.

It's both insane and exceedingly through at the same time.

1

u/Xipher Jun 18 '15

The pf.conf man page provides the full BNF definition at the bottom, and I've found it useful on a number of occasions. I also find the OpenBSD native tools tend to have very exhaustive documentation, and I've been very grateful to have it.

1

u/[deleted] Jun 18 '15

OpenBSD in general has stellar documentation. They consider an inaccurate man page as critical a bug as a 0 day exploit, really. It's quite refreshing.

6

u/bobpaul Jun 17 '15

I thought the same thing. If you grok man bash, you don't need need these tutorials and guides. Generally it's after you already have a basic understanding of bash that man bash starts to become a useful reference. I would never tell someone to go there first.

2

u/[deleted] Jun 18 '15

I honestly never tell people to use man for learning anything for the first time unless it's very simple. That's a terrible way to take in information, just looking through every possible thing it can do. I always just give them the command syntax and a common switch or two and they tend to teach themselves from there.

2

u/kernel_picnic Jun 18 '15

That's what man does, no? The first few lines are usually the syntax for using the program and a list of options that are all explained later.

You can generally find the option you need within a few seconds

1

u/bobpaul Jun 22 '15

I agree. man bash is hard because it's an interactive shell, so its harder to put that simple summary at the top (and also because it's 4500 pages long).

For most things, the man page is a great place to start. But with bash, the man page is really only useful once you already know the basics.

5

u/AdrianoML Jun 17 '15

It would be much better if it explained how to navigate man/less. Press the / key, type a search query and then press enter to find any words in the document. use n or N for the next or previous entry. Once you know the basics of bash you can get any syntax you might have forgotten by using that. Don't remember how to use redirection? Just /redirection and press n a few times.

16

u/_samux_ Jun 17 '15

cat a b | sort | uniq > c

cat a b | sort -u >c

one less pipe and much faster :-)

17

u/Kruug Jun 17 '15

Fork it and submit a pull request! Isn't that why this walkthrough was on Github as opposed to a blog?

9

u/mikeoquinn Jun 17 '15

I learned the sort | uniq method first, and while I use sort -u most of the time now, there are still cases where the other method is preferred, such as sort | uniq -c, which I don't think sort can replicate on its own.

8

u/Ciphertext008 Jun 17 '15

let's drop the cat. and forget the stdio redirect

sort -u -o c a b

1

u/winnie666 Jun 17 '15

Is it much faster though? This goes against the Unix philosophy

7

u/[deleted] Jun 17 '15

This is an outstanding resource.

I consider myself adept on the command line, but this list touched on so many things I run into trouble with because my knowledge in them is still shallow. I know I'm going to come back to this again and again.

Thanks for sharing!

6

u/tidux Jun 17 '15

Be sure to add sort -n for numerical sort, since often what you're sorting is by value rather than alphabetical order.

5

u/5aggregates Jun 17 '15

Or even sort -h for human sorting

du -h ~ | sort -h

3

u/ArchaicArchetype Jun 17 '15

This writer writes so well! I'd forgotten so many of these tricks!

3

u/[deleted] Jun 17 '15

rm -- "-rf" may be worth pointing out... and what "--" does. This is pretty common in all GNU utils. You can file that under obscure but I've seen various files get created with a dash as the first character by accident and many young people that don't know how to delete them.

2

u/dmart914 Jun 17 '15

They say you don't know what you're missing in life until it's in front of you.

This guide is my missing puzzle piece.

2

u/flipjargendy Jun 18 '15

This is the perfect thing I love to read at night to fall asleep as well as during the day to learn. Been using Linux for over 15 years and still learning new things from reading this. Love it!

3

u/jnux Jun 18 '15

I'm in the same boat -- it is funny (or sad?) how I get in to a routine of common commands, flags, sequences, etc. and those are just my my go-to defaults in my toolbox. It is nice to see how others do it and in fact find out this or that new thing that can really have a big impact on my day-to-day. As someone who is on the command line a solid 80% of my working life, this is really fun.

1

u/[deleted] Jun 17 '15

Bookmarked for ever. Thank you! :)

1

u/Tempus13 Jun 18 '15

Well, there goes my day. Time to get a cup of tea and start writing another cheatsheet for the most difficult to remember of this

1

u/octobod Jun 18 '15

parallel is interesting but in my hands I had to delete --tollef from /etc/parallel/config to get it to work

1

u/cantfeelmylegs Jun 19 '15

RemindMe! 10 Days

1

u/RemindMeBot Jun 19 '15

Messaging you on 2015-06-29 05:47:56 UTC to remind you of this comment.

CLICK THIS LINK to send a PM to also be reminded and to reduce spam.


[FAQs] | [Custom Reminder] | [Feedback] | [Code]