Some Linux/Unix commands worth knowing…

It seems like not a day goes by when I don’t run across someone’s blog listing “top 10 Linux commands you must know” or something like it. I get the feeling these are mostly posted by people who switched to Linux recently and want to share the experience. I switched to Linux 12 years ago, so here’s my version of “some Linux (or really Unix…) commands worth knowing”. I’m not going to be more specific than that. They are in approximate order of increasing skill/knowledge/foolhardiness.

  • ls -al
    We all know that ls is the command to list files in a directory. The -l option gives you details, and the -a option lists the “hidden” files that begin with . (period). So ls -al is the standard “power version” of ls.
  • mv/cp/rm
    Move, copy, remove files and directories. Move is also used to rename.
  • <command> –help
    Putting –help after a command usually tells you what arguments it takes. This is something I really really miss when having to use Windows. You can also try -? or -h (or simply nothing). If that fails, try man <command>.
  • find / -iname <filename>
    The equivalent of Windows’ directory search – but without the world’s worst UI. Running it with / (root directory) as the second parameter is liable to spit out some errors because (unless you are root, which you shouldn’t ordinarily be) you won’t be able to read some directories. -iname is probably the most useful option for the newbie – it means do a case-insensitive name match.
  • vi
    You should know just enough to get by, although these days any distro is likely to have nano or something friendlier than vi anyway. You can get by pretty well just knowing: i to start “editing mode” (insert), x to delete a character, dd to delete a line, ESC to stop editing and enter “command mode” again, :q! to quit without saving, ZZ to save and quit.
  • chmod
    A vital command for mucking about with files. 90% of the time you will want chmod 755 <file> and 9.9% of the time you’ll want chmod 644 <file>. The first makes a file executable, the second makes it “normal” (usually to be used if it came from a bizarre place like a Windows filesystem).
  • grep
    A bit overrated. In the sense that one doesn’t often need it as a new user. But the real reason it’s one of the standard tutorial things is that what you really need to know are regexps (regular expressions). Grep can be viewed really just as a way to get familiar with regexps. Learn them and love them.
  • less
    Forget cat and more – for reading text files, just use less. Cat and more you can learn later when you want to do other stuff besides just read files.
  • ps aux | grep <name> and kill
    Useful for when things go wrong. Find a rogue process with ps. Kill it with kill. Job done.
  • Ctrl-Z and bg
    Forgot to add the & on the end of a command and your command prompt didn’t come back? No worries – hit Ctrl-Z and type bg and Bob’s your uncle.
  • kill -HUP
    Useful for restarting a process and/or having it re-read the config files. A good example is when for whatever reason, X fails to start and you are left at a text prompt. So (using your minimal vi knowledge) you quite happily fix up your X config file, but then what? If you are a newbie, chances are you reboot (that being the only way you know to restart X). But probably all you need to do is something like ps aux | grep gdm followed by kill -HUP. And you’re back at a nice graphical login.
  • tar -zxvf <file>
    The standard way to unpack a tarred and gzipped file. The options are: z for zipped, x for extract, v for view (you can leave this out if you like) and f for you guessed it, file. You can also use -jxvf if the file is bzipped rather than gzipped.

That’s a good set of standards to get oneself up and running as a newbie. On the hairier side of things, some other useful commands to know are:

  • lsmod and modprobe
    For listing and loading kernel modules.
  • lspci and lsusb
    For inspecting your hardware.
  • dmesg
    For seeing what went wrong when you just plugged in your iPod.
  • lsof and dd
    Given that practically everything in Unix is abstracted as a file, there is almost nothing you can’t do with the combination of these two absurdly powerful tools.

Leave a Reply