The Terminal


I know, this is the scary part for lots of people. It's okay. We will do this together. The terminal is a small program that enables you to interact with your system through text commands instead of by clicking on GUI objects. Using the terminal instead of the GUI is like using a manual transmission in a car instead of an automatic transmission. Any dedicated car nut will tell you that you can get better performance with a manual transmission. In this case, the performance boost with the terminal comes in the form of getting some tasks done faster.

Most people are afraid of the command line in a terminal because they think that it is complex and that there will be lots of commands to remember. Okay, they are partially right. There are lots of commands to know, but you don't have to memorize them all. You don't have to do every complex task on the command line. You can use the command line when it is convenient for you and ignore it when your task might be more convenient to do in the file manager or a GUI program.

I think that many users fear that they will open the terminal and stare at that blinky cursor, not knowing what to type in. There is a shortcut to memorizing every command that you needand, in this case, to preventing carpel tunnel syndrome. You can use the Tab key for command and file name completion. Begin to type a command that you know the first letter of, and then press Tab:

 [susan@dodongo] $ q <Tab><Tab> 

If there is only one choice for that letter or combination of letters, the one choice will show the first time you press Tab. If there are multiple choices, press Tab twice. You might get output that looks like this:

 qm2ts         qmake3        qt20fix3      qtdoc           quota qm2ts3        qrttoppm      qtconfig      qtrename140 qmake         qt20fix       qtconfig3     qtrename1403 

All the commands that start with a q on my Fedora install were displayed. So, as long as you know what the command starts with, you've got help. Keep in mind that letters such as t or l have more than 100 commands, so try to get the first two or three letters before you press Tab.

UNDER THE HOOD

CHEAT SHEETS

If you feel like you want to learn to use the terminal often, you cankeep a cheat sheet and use the built-in Linux terminal cheat sheet, your command history. While you are learning, it is easy to justkeep a text file in your home directory. When you learn a new command that you might want to use again, copy it to the text file to save it for reference later. Linux also keeps a history of the commands you have used. Open a terminal and type history. The history will scroll down quite a bit, so type in history | less to view the list one screen at a time. Type q to exit the less viewing mode.


Your Command Line Deconstructed

What's all that stuff in front of the cursor in your terminal? Mostly, the information preceding the cursor on the command line is information about who and where you currently are.

 [susan@dodongo] $ 

Reading from left to right: your username "at" your computer's name (this will often be localhost, by default), and then a prompt symbol before the cursor. A $ indicates that you are currently logged in as a regular user. A # indicates that you are logged in as the root user.


Table 2.4. Common Commands for the Terminal

WHAT YOU WANT TO DO

THE COMMAND TO DO IT

View the contents of a directory

ls

Move up one directory

cd ../

Move to another directory

cd [directory name]

Copy a file

cp [current file name] [new file name]

Move or rename a file

mv [old file name/location] [new file name/location]

Delete a file or directory

rm [file name]

rmdir [directory name] (directory must be empty)

rm -rf [directory name] (for a directory that is not empty)

Create a directory

mkdir [directory name]

Run a program

[command] & (Use the & to run the program in the background, keeping your terminal free for other things.)

Find a file

find [file name] (You can use an asterisk [*] as a wildcard character, so find all things that start with an m with m*.)

Show the current directory path

pwd

Install an RPM file

rpm -ivh [package name]

Uninstall an RPM file

rpm -e [package name]

View help for a command

man [command name]

info [command name]

[command name] help

Create a shortcut to a file

ln -s [file linking to] [name of shortcut]

Peek at the contents of a file

cat [file name]

less [file name]

Edit a text file

pico [file name] (if the pico editor is installed)

vi [file name] (vi is a complex text editor, so get familiar with how to use it first. If you get trapped in vi, :q! will get you out.)

Prevent all the output from scrolling right by you

[command] | less When you get long output from a command, run the command again with a pipe (|) and the less command at the end of it.

End any process or command

Hold down Ctrl+C

Become the root user

su (then enter your root password)


Sometimes you need to do things in the terminal as the root user. You don't have to log out of your desktop manager and log back in to work as root. The terminal is your shortcut.

1.

Open a terminal.

2.

Type the command, su.

3.

Enter your root password.

You are now logged into the terminal as the root user, with all the permissions and danger that go with the privilege. Be as careful as you can be when you are logged in as the root user; I have just handed you the loaded gun of Linux. Don't delete anything unless you are absolutely sure that you don't need it. Don't change anything unless you know what you are doing. Root access in the terminal is great for things such as installing new programs, but don't go nuts with the power.

Konsole and GNOME Terminal

Program Info

Fedora/GNOME menu

Konsole: No main menu choice for Konsole, but use the command konsole to open it from the GNOME terminal.

GNOME Terminal: System Tools > Terminal

Mandrake/KDE menu

Konsole: System > Terminals > Konsole

GNOME Terminal: No main menu choice for GNOME Terminal, but use the command gnome-terminal to open it from Konsole.


Both Konsole and the GNOME Terminal are very simple programs, as shown in Figure 2.15. You basically just open each, and you are ready to go. The options for preferences mainly pertain to how your terminal looks. Both of these terminal programs are called X Terminals. They are virtual terminals that enable you to run commands. You can also press Ctrl+Alt+F1 through F6 to access other, full-screen terminals. Hold down Ctrl+Alt+F7 to return to X, your graphical screen.

Figure 2.15. KDE's terminal program, Konsole.


More Terminal Help

The Linux command line comes with its own help manual for youin fact, two or three of them. These aren't the most user-friendly help files in the world, but they give you the information you need. You have the man command, the help switch, and the info command.

 man [command name] [command name] help info [command name] 

Not all commands have a help display or an info file. More commands have man files than any of the other options available to you. The man files are all arranged similarly for each command, but they can be cryptic for new users. Read down the file, and you will see the proper use syntax for the command, a description, and then long sections about the various switches (additions to a command, usually one letter, preceded by a hyphen), and other references for the command.


The layout of both Konsole and the GNOME Terminal is as basic as it can get. There is a menu bar, a toolbar that shows buttons or tabs, and the main terminal itself. You can open new terminals in tabs or in multiple windows. As a terminal command line newbie, start with one tab in one window, use some of the basic commands we have talked about, and don't be afraid. While you are logged in using the terminal as your regular user, you cannot break anything that is all that important. To avoid making a mistake that you cannot undo, pay attention to each step you take. There's always Topic 1, "What Are You Getting Into?" to go back to for a fresh install if you really mess up.

TOOL KIT 2.3

Write Dirty Linux Poetry in the Terminal

Want proof that the command line is fun? Well, there are lots of Linux commands that, when strung together, make me feel like a dumb, giggly third grader who has just discovered the word fart. Let's string together some commands and see if we can get in trouble.

1.

Use these real, umm, suggestive Linux commands to start with:

  • man

  • finger

  • mount

  • sleep

  • unzip

  • touch

  • strip

  • grep

  • more

  • make

2.

Put them together with file names to see what you can come up with. I made a file named man to use. Here is a conversation between my computer, Dodongo, and myself. I submit it as an existential modern poem.


"Lookin' for a Man in All the Wrong Terminals," by Susan

 $ man request 

: No manual entry for request

 $ make man 

: make: *** No rule to make target `man'. Stop.

 $ touch man : ... $ talk dirty > man & ; kill -9 %1 

: [1]+ Stopped talk dirty >man

 $ unzip man* > stripMan 

: unzip: cannot find man*, man*.zip or man*.ZIP.

 $ man sleep | grep mount 

: sleep - delay for a specified amount of time

 $ man sleep! && finger man 

: No manual entry for sleep!

: Login name: man In real life: ???

 $ echo "your apathy slays my tortured consciousness" > man : ... $ write man 

: write: man is not logged in

 $ halt man 

: halt: must be superuser.

 $ echo "i end the abyss of pain"  && echo "end" 




Linux Desktop(c) Garage
Linux(R) Desktop Garage
ISBN: 0131494198
EAN: 2147483647
Year: 2006
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net