Tips for getting to grips with the command line [closed]

When I first migrated from Windows to Ubuntu, by far the most daunting thing I had to do was use the command line.

Typing commands is an alien experience when you've only ever been used to pointing and clicking.

When I talk to new Ubuntu users, they are often uneasy with the idea of talking directly to their computer.

Is there a simple and friendly guide to help new users get acquainted with the command line?

Do you have any tips to make the experience easier or more fun?


Solution 1:

If you are looking for a good guide to learn the command line, my favorite is LinuxCommand.org

The guide will show you the basics of the command line, and will even guide you into writing useful shell scripts.

That said, most user will not need to use the command line for most day to day operations. I do not think that the command line should discourage users from migrating to Ubuntu. But once you learn the power of the command line, you won't be able to live without it!

Solution 2:

Here are some common commands for manipulating the filesystem:

  • cp [src] [dest] - copies src to dest
  • mv [src] [dest] - moves src to dest (also used for renaming)
  • cd [dir] - changes current directory to dir
  • pwd - prints the current directory
  • cat [file] - prints the contents of file to the screen
  • rm [file] - removes a file1
  • rmdir [dir] - removes an empty directory

Prefixing any of the commands with sudo causes the command to be executed as the root user.

1 - don't type sudo rm -rf / as it will erase the filesystem

Solution 3:

1) Tab completion:

A giant time saver. If you are typing a command, you need only type enough of the command to provide an initial segment that can only be extended in a single way and then can press TAB once to expand your initial segment to the entire command. So, for instance, on my system umo TAB expands to umount. (On my system as what initial segments are extendable only in one way is a function of what you have installed, etc.) If you do not type enough to make the completion unambiguous, TAB will not expand, but a second TAB will display a list of possible completions. So, on my system, um TAB TAB yields:

umask       umax_pp     umount      umount.hal

Tab completion also works on paths: cd /home/me/docs/reallylo TAB will, if unique, expand to cd /home/me/docs/reallylongdirname and, if not unique, offer a list of candidate continuations as with um above.

2) man some-command or some-command --help or some-command -h:

If you cannot recall how a command works, you can get documentation right there in the shell. man usually provides the most detail. Usually one or both of the --help and -h arguments to a command provides a short summary.

3) head:

man some-command takes over the terminal and prevents you from entering commands while the man text is displayed. man some-command | head will display the first 10 lines. man some-command | head -n will display the first n lines. In both cases, you get your prompt back, so that you can have the man text on screen as you enter your command.