Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am taking a test soon and I would like to know useful commands on Linux for a programmer. Some examples are string, strace, top, free, df, mount, cat, head, tail, whoami, touch. What are others?

I am a complete novice. Those are all the commands I know along with groupadd, useradd, chmod, chown, ls, rm, mkdir and echo. That is all I know.

share

migration rejected from stackoverflow.com May 18 at 11:28

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by Mokubai May 18 at 11:28

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is not about computer hardware or software, within the scope defined in the help center." – Mokubai
If this question can be reworded to fit the rules in the help center, please edit the question.

19 Answers 19

Well, I checked the history of my commands, and here is what I found:

=> sed 's/[;|][[:space:]]*/\n/g' .bash_history | awk '{print $1}' | sort | uniq -c | sort -nr | head -n 20
   1725 ssh
   1480 ls
   1125 cd
    494 vim
    471 grep
    425 cat
    378 mplayer
    294 sudo
    285 rm
    241 psql
    230 perl
    175 scp
    171 svn
    148 /sbin/ifconfig
    133 man
    121 bc
    120
    118 find
    110 ps
    109 sort

Some of these are work oriented (perl, psql), or environment oriented (sudo, mplayer).

As for "programmer" commands, the list that I would recommend to master is:

  • awk
  • cat
  • cut
  • find
  • grep
  • head
  • nc
  • nl
  • ps
  • sed
  • sort
  • strace
  • tac
  • tail
  • tcpdump
  • uniq

If you're working in a Unix environment, then learning ssh is definitely a good idea (i.e. it doesn't end up as only "ssh somewhere" or "ssh somewhere some_command", learn about port (or net) forwarding and most importantly: keys and ssh-agent).

share

That depends on the type of programmer you are.

For C/C++:

nm, ar, objdump, ranlib, ld, ldd, readelf, elfcmp

For Bash/SH:

awk, sed, grep (or ack), find, xargs, test

For most languages:

diff, patch

But a couple people have well stated that man and apropos are truly useful.

share

The first one you must master is man, and learn "man -k *keyword*" to find relevant man pages.

A few years ago, I wrote up a simple guided path Learning Linux/Unix with man(1) for a few people working for me who were new to Linux. You might also find this helpful.

share
1  
man -k ?= apropos, does anyone use apropos anymore? – KFro Sep 17 '09 at 21:48

These are important to me:

  • grep, to look for code
  • sed, to replace stuff
  • diff and patch

For checking & stripping symbols:

  • nm
  • strip
share
    
In addition to diff and patch, look into diffstat and the patchutils like filterdiff. – retracile Sep 18 '09 at 1:51

vim and make.

share
    
You mean emacs? :D (Really, I prefer vim .) – Lucas Jones Sep 17 '09 at 20:25

sed and awk and also, ctrl+r to reverse look up past commands.

share
    
+1 for ctrl+r, I didn't knew that! – Andrea Ambu Sep 17 '09 at 21:02

I once used pmap to locate a nasty memory leak I couldn't find with valgrind.

share
  • du - disk usage
  • !grep - will look for and execute grep in bash history (you can change for any string searched)
  • slocate / locate - quick find file or directory
  • editor: joe, nano or others
share

If you are serious about programming, I would recommend learning a version-control system. Which version-control system is a whole other Holy War but the basic concepts are transferable between them.

share

Here is a pretty big list of commands with short description.

share

Commands I use daily are:

  • grep
  • find
  • chmod
  • chown
  • man

There's also a few apps you should know in case there's no GUI:

  • vi
  • ssh
share
  • apt-get : to install development packages
  • tail : to inspect /var/log files
  • fuser : to get mapping between a process and a port (easier to kill zombies)

etc.

share

These aren't really specific to Linux/Unix anymore, but I wonder how I lived without:

  • sed
  • grep
  • perl (for more complex automated editing)
  • less
  • tail (looking at log files as they are added to)
share
    
tail -f to be a bit more specific. – Richard Marquez Sep 17 '09 at 22:06

Two more: man and apropos.

share
    
whatis is a good complement to this. – Lucas Jones Sep 17 '09 at 20:36

If you like to learn from other people's source code, learn more about svn, git.

share
  • Study the man page for your shell. Read it repeatedly.
  • Learn awk for quick text processing tasks.
  • Nobody has mentioned sort yet.
  • Get comfortable in a text editor (Vim/Emacs)
  • Learn a scripting language (Ruby/Python/Perl are the usual suspects)
share

Asking for useful commands will help you expand your knowledge for real world applications. But it won't help too much for an upcoming test. A well designed test will likely explore the nuances that only experience can tell you.

Example: if you need to use strace, then you probably know most of the other commands that would appear on this list. If you don't, but still need strace, then what you really need is someone else to help you disect the strace output.

share

lsof

It lists open files, including network sockets. It can very useful when debugging.

share