Indispensible Unix commands

The first lab session of my Computer Science course consisted primarily of learning the following Unix commands: pwd, ls, cd, cp, mv, rm, mkdir, chmod, more, man. Although I’ve been using nothing but Windows throughout my career – from Windows 95 to 2000 to XP – these commands have proven to be indispensible for those occasions when I need to remotely administer a Linux box.

Let’s go through them one by one.

You log in to a Linux server and all you get is a dollar sign and a cursor. The first thing you want to know is: where am I? So you want to print the working directory:

pwd

Then you want to list all the contents of the current directory in a long listing format:

ls -al

To get around, you change directory:

cd /another/directory

Then, to copy a file from one directory to another:

cp /some/directory/somefile.txt /another/directory

To move it instead:

mv /some/directory/somefile.txt /another/directory

There is no command to rename, you just move it:

mv oldname.txt newname.txt

To remove a file:

rm filename.txt

To remove a directory and its contents recursively:

rm -r dirname (use with extreme caution!)

To make a directory:

mkdir dirname

To change the mode of a file or directory to make it writeable by everyone:

chmod ugo+rwx file_or_directory

ugo+rwx means, for (user, group, others), add (read, write, execute) permissions. Use the minus sign instead of the plus sign to remove permissions. ugo and rwx can be used in any combination, e.g., go-w.

Finally, to get to know more about the contents of a file:

more filename.txt

Press space to scroll to the next page, and q to quit. (Note: less is better than more. With less, you could go both backwards and forwards.)

Finally: when in doubt, consult the manual!

man command

Update 13 February 2009

See also Commands that you must know in Linux… by dirn.name.

Related Posts:

  • No Related Posts

5 Comments

  1. and i want to add about vi command..it’s a must !! as well as other commands such as ps, grep, netstat, ping, traceroute, sudo, scp, ifconfig, who and other commands

  2. Thats a great list, I’m just getting into Unix so that will come in handy.

  3. Here is the Ying to your Yang: http://www.thegeekstuff.com/2009/02/four-useless-linux-commands/

    Nice post, straight to the point.

  4. Nice Blog, Thanks for the simple Unix commands… I all of a sudden got some interest in learning some unix commands on my MAC after i went through your above post… :)

Trackbacks/Pingbacks

  1. [...] again. So to read the file, you can go to second tab and open it there by using less (thanks Rizal) [...]

Leave a Comment



  • recently written