views:

486

answers:

10

I have recently started moving into the world of Linux development. I wanted to learn some new things and thought bash might be fun. As I learn more about bash programming I have found that there are quite an assortment of useful tools to be used (such as grep, tr, awk, etc.) There are so many that I just do not know which ones are "vital" to learn.

Shell scripting commands depend heavily on the configuration of the system itself, and can change drastically over time, unlike most programming languages (where a core library ships with the language itself and represents the "core" set of commands that a programmer would use when interacting with the outside world). Therefore,

As a modern Linux shell script programmer, which command line tools should I be familiar with?

A: 

Like you mentioned, learn awk, sed and grep. They will be very good friends of yours. Also, very important, learn to use properly a text editor such as vim.

I would also recommend you to get familiar with a good scripting language such as perl or python.

nmuntz
+2  A: 

Try looking at commandlinefu. People come up with all sorts of things there, and you're bound to find examples of stuff which may be useful in the future.

But generally, top used commands, by John are nice as a guidance.

And of course, here be dragons, list of stuff you shouldn't do: deadly ones

ldigas
+1  A: 

you should probably know everything on this list:

http://www.faculty.ucr.edu/~tgirke/Documents/UNIX/linux_manual.html

maybe not everything is essential all the time, but knowing at least a cursory overview of each can help a lot for basic functionality.

Scott M.
+2  A: 

I'd recommend especially that you become familiar with locate, grep and find. sed, awk and vim are next, and around these are cat, less, tail / head, ls (yes, ls!), and the many ways in which bash can help you.

Especially about Bash: beware of bashisms!

Adriano Varoli Piazza
+2  A: 

You should know some console-based text editor. pico might suffice. I myself am a vi guy, though emacs is also acceptable. (Though I will recommend vi: that is a de-facto standard on nearly any platform of unix, and things like grep/sed behave very similar to vi.)

Others:

screen: extremely useful when you don't have a gui or don't want to/can't open up many terminal windows or PuTTY sessions. Allows you to have multiple shell sessions open, and you can toggle between them (and many other things.

top: good for monitoring processes/cpu usage/memory usage

watch: runs a command every "n" seconds and displays its output. eg, watch -n 1 "ls -aio" executes "ls -aio" ever 1 second.

rascher
+1 for mentioning screen. For remote sessions, screen is invaluable.
Adriano Varoli Piazza
+2  A: 

Depends on what you're doing, obviously, but I get a lot of mileage out of find, grep, rsync, and ssh. The simple ones are useful, too: cat, tail, wc, ps. There's a lot you can do with a for loop, too, and wildcard syntax is essential. For example,

  $ for i in {app,web}{01,02}; do ssh $i date; done

That will ssh into hosts app01, app02, web01, and web02 and execute the date command on each one.

jcrossley3
Hey -- that trick with for is cool!
staticsan
+1  A: 

perl, xargs, lsof, find, grep, bash, tar, gzip, tr, tail, diff, patch, and bc.

And everything that is in SUS2 (Single UNIX Specification).

Chas. Owens
+1 for tar, gzip, diff, bc
rascher
+4  A: 
  • Compressing and uncompressing various archives.
  • Using the man pages
  • alias is always helpful
  • as mentioned by others sed & grep (RegEx is good to know in general), sort, head, tr, cut
  • echo & printf (their differences and when to use what)
  • Getting the return value (not as useful but still handy when writing scripts) via $?
  • top, ps, kill, how to background/foreground/suspend a process

The important thing is combining the many tools that exists and where most become extremely useful. Using man whenever you are stuck is probably the most important thing.

nevets1219
good point, I forgot about man, it is so easy to forget the basics.
Chas. Owens
I don't think it is that we forget the basics, it's sometimes so obvious we don't mention it. Sometimes you just do it without thought and assume everyone would as well.
nevets1219
A: 

Don't worry about the commands directly. Rather when you find yourself struggling with something try a few quick Google and man page searches and see how you can improve what you're trying to do right then and there. Keep it relevant and you will get more useful results.

David Plumpton