The first lab session of my Computer Science course consisted primarily of learning the following Unix commands:
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:
Then you want to list all the contents of the current directory in a long listing format:
To get around, you change 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:
To remove a directory and its contents recursively:
rm -r dirname (use with extreme caution!)
To make a directory:
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.
rwx can be used in any combination, e.g.,
Finally, to get to know more about the contents of a file:
Press space to scroll to the next page, and q to quit. (Note:
less is better than
less, you could go both backwards and forwards.)
Finally: when in doubt, consult the manual!
Update 13 February 2009
See also Commands that you must know in Linux… by dirn.name.