1

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?

2
  • Looks like a duplicate of this question: stackoverflow.com/questions/1576/… Commented Apr 21, 2009 at 1:48
  • 1
    Edited, in an attempt to differentiate this from the previous question (should be a sufficient difference between "programmer using the OS" and "programmer scripting the shell") Commented Apr 21, 2009 at 1:58

9 Answers 9

4
  • 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.

Sign up to request clarification or add additional context in comments.

4 Comments

good point, I forgot about man, it is so easy to forget the basics.
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.
In 1995, it would (perhaps) have been appropriate to include alias on a list of things to know for interactive use of a shell. It was never appropriate for scripting, and in the modern world is not even appropriate for interactive use.
I agree that 'alias' is probably not great for scripting (portability and whatnot) but if portability is not a major concern it's still something that happens fairly common. Sometimes aliases are exported and sourceed for scripts too.
2

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!

Comments

2

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.

Comments

2

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

Comments

2

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, and memory usage

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

1 Comment

+1 for mentioning screen. For remote sessions, screen is invaluable.
1

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.

Comments

1

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

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

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.