Chapter 7: I Don't know any commands!


Topics covered in this chapter:
The whole Linux command thing: Why have commands?
Some simple commands, you may recognize
Some more commands, plus how to get help on almost any command

The Whole Linux Command Thing: Why Have Commands?

Just as cavemen learned to develop their skills from grunting and groaning to writing meaningful representations on the walls of caves, The computer world started off with (well, if you wanna be accurate, punched cards), the keyboard and the CLI (Command Line Interface). All action that happened on any system would be inherently text. As talked about in Chapter 4, Xerox's PARC research center managed to invent the very first graphical user interface. When Linux first came to be in 1991, most things were still text. True, Windows 3.0 was out, and MacOS had been with us since 1984 but the PC world was still dominated with text. MS-DOS still ran the PC show. Anyone who wanted to use their PC efficiently back in 1991 with a Microsoft machine, would use Windows to run their graphical programs like Aldus PageMaker and Lotus 1-2-3, but they would open an MS-DOS prompt box, or close Windows and drop to DOS, so that they could quickly rename a file or move it from one place to another. Sure, users could even then, click into the File Manager, select the file(s) they wanted to rename or move and drag them to the relevant location, but a lot of people were finding that DOS was still quicker to use if you knew the commands. If you spent a few days learning the basic commands of DOS, you could really use your PC efficiently, coupled with the graphical usefulness of Windows (ahem), you could cut workload down by a good deal. Even today, with Windows Me and 2000 Professional, I still finding myself going to Stargoing to Start>Run and typing in command to access the Dos prompt. To the people who used the PC before the GUI ruled (circa 1995), typing a command even now is sometimes more efficient than using a drag and drop idea.
if you have used Linux or Unix before, imagine this scenario:
You have 300 files in a folder (call it work), and within that folder you have 2 other folders, one called old and one called new. Your task is to separate the files in work to the new and old folder. You must put the files that are older than 1 month into old, and the files less than 1 month into new. In a graphical file manager, you would need to right click each of the 300 files separately to find out their creation date, and then move each of the files one by one into their relevant folder. This operation is seriously time-consuming.
How's about the command-line option: type in one line at the shell, and the files are automatically sorted into each folder, determined by todays date. Sure, you would know that you would have to type 'find /usr -ctime +30 -exec ls -ld {} \;' to get it to happen, but hey, it's still faster than going through 300 files.
There are yet many other reasons that you may want to have a CLI, for example, a User Administrator has 3 dead programs on 3 different workstations across a building. He has two choices: Go run around the building like a headless chicken and kill the programs manually at each workstation, or sit at his desk and telnet into each machine, using the CLI, killing each of the programs, finishing the job 20 times faster. Yes, it is possible to run X over a network, so in theory it is possible to access a remote X display rather than a CLI, but remember, it's not the standard, and if you've got an X display running at 800x600 16bpp, it's pretty chewey on the old network resources that you try to hone. If you start to use Linux a lot, you'll start to find that whilst the CLI is pretty much not needed any more, it's a lot easier just to issue a direct command instead of clicking on a hundred different icons to do something you could do in one command at the CLI.
Another advantage: GUIs are resource hungry. Why chew up megabytes of RAM and high amounts of the CPUs precious time to draw up nice pretty windows, icons and a pointer. Why not just have simple text mode, which the PC finds practically effortless to display and uses almost no ram. The benefits are clear.
A common misconception (I don't know why this is) about Linux is that it is completely text based, and the story could not be further from the truth, but I expect Linux to always hold onto it's console, as it's a highly useful tool, and whilst I probably use it more than your average user will, it's still handy at some points.

Some simple commands, you may rrecognize/U>

GNU/Linux has an awful lot of commands. You can find the files for these commands in folders like /bin and /usr/bin on your Linux box. You'll probably never use them all, but real hackers and stubble faced geeks use them a lot. It all depends on what sorta Linux user you are. If you're going to use Linux, it'll help you to know at least a few basic commands. When I moved to Linux from dare I say it, a Microsoft platform, I had already been an MS-DOS user for many years, and I knew most of the DOS commands, so I found typing commands something less daunting than a CLI virgin would find it. If you know DOS, you'll find that the syntax of DOS commands compared to UNIX commands are very similar, and even some of the commands themselves are the same. Have a look at this comparison table if you can remember any DOS commands:
DOS Command UNIX Counterpart
dir dir or preferablyls
cls clear
type cat
move mv
copy cp
ren / rename mv
echo echo


Some more commands, plus how to get help on almost any command
Here are a few more advanced commands, along with their explanations and one example for each

Command Action Example
chmod Changes permissions for files chmod u=rwx myfile.txt
chown change the owner for a file or folder chown myuser /home/myfile.txt
chgrp change the group owner for a file or folder chgrp mygroup /home/myfile.txt
mv Moves or renames a file mv /home/me/myfile.txt /home/them/
grep searches text for results cat myfile.txt | grep "hello"
ls list the files in a folder ls -l
find finds files or file designators find /home -name "myfile.txt"
mount mounts a drive/block device for use mount /dev/cdrom /mnt/cdrom
ps Show the list of live processes ps ax | more
kill kill a process (running software) by process ID kill -9 12345
tar de facto Unix archiver tar zxvf myarchive.tar.gz
rpm The Red Hat Package manager, used to install, remove, upgrade and query RPM packages. rpm -Uvh mynewpackage.i386.rpm

Important tip:
If you ever need to know how to use a command, or just find out what a command does man (short for manual) is your friend. For example, by typing man ls, a comprehensive guide is given on using the ls command, what it's purpose is and what it's syntax is. For more information on using man, type man man.
There is not a better source for quick, easy to find information on almost every Linux command. The only times when man lets you down, is when you don't know that a command that does a specific purpose exists, thus, you don't know the name of the command, so you don't know what manual page you want to ask man for. For this reason, I have started the lengthy process of creating a commands guide, that is easy to understand, although somewhat less verbose than manual pages themselves.

If you wish to visit the Commands Guide, which *should* list almost every Linux standard shell command, but is currently unfinished. Click HERE.
HOME | LINKS |