| Getting Started with Linux - Lesson 6 |
|---|
Frequently Used Shell Commands
If you install a window manager like KDE, you can copy, delete, move
and rename files by way of a graphic user interface like Konqueror. But as I
mentioned before, shell commands are pretty standard in Linux, so we're going
to teach you the ones that you're most likely to use. You can use them both in
text mode or in your x-terminal when you're in graphics mode.
'cd' command
To show the student the basic uses of the 'cd' command The first command you'll
use is 'cd'. We talked about this in a previous lesson, so let's review the
basics.
'cd' means 'change directory'.
Typing: cd /[directory name] will get you into one of the main
directories in Linux.
Typing cd .. will get you out of it.
Typing cd without the / and a sub-directory name will get into that subdirectory.
Remember, you don't have to type the whole name
Typing: 'cd' and the first letter or letters of a directory and the TAB key
will complete it for you. Then all you have to do is press enter.
If you type just:
cd
you'll go back to your home directory
The 'ls' command
To show the student the various variations of the 'ls' command 'ls' is another
command that we've discussed a bit before. Let's go into some more detail.
Typing 'ls' will list the contents of a directory with just
information about file names.
You can use 'ls a*' to list the names of all the files that begin with
the letter 'a' and so on down through the alphabet. Please do not use the
cuneiform alphabet unless you're from ancient Mesopotamia.
Normally we'll want to add on some parameters (those -[letter]
combinations) so that we'll get some more detail
Using 'ls -l'
To show the student how to get some more detail with 'ls -l'
'ls -l' will get you a detailed listing of the directory like this.
| -rw-r--r-- | 1 bob | users | 103824 |
Jul 10 12:01 | waikiki.jpg |
The first part, those letter, are file permissions. We'll go into that in a
later lesson. That basically shows what you and others are allowed to do with
the file, like read it, modify it or make nasty comments about it.
The next one shows that you've got 1 file. The next one that it belongs to you,
'bob'. The next one represents that Linux, not only recognizes users, but also
groups of users. We'll go into that in the next course. The numbers are the
size of the file in bytes. You have the date and when it was created or
modified or copied there. Lastly, you have the name of the file, waikiki.jpg,
which is obviously your important tax records.
'ls -l' will give you a detailed listing in alphabetical order, starting with
any file that begins with a number, then any file that begins with a capital
letter and then any normal file that begins with a lowercase letter. So if you
have a file '007_secrets.txt' that'll be the first one you see.
Other parameters with 'ls'
Now let's add some more parameters on
'ls -l -t' will give you a listing according to the time with the newest
ones appearing first in the list. You don't need to separate the parameters
either. 'ls -l -t' and 'ls -lt' are the same thing. If you want
the oldest to appear first, try:
'ls -ltr'
The 'r' is for reverse order.
There are a couple of parameters in capitals that you may want to use. 'ls
-lS' will list your files from biggest to smallest. 'ls -lSr' will
reverse this order.
'ls -lX' will list files according to type in alphabetical order. If you
have any that end in *.zip, then those will be last. If you want those to be
first, now you know: 'ls -lXr'
There is also a parameter that will help you if you want to find out more about
these commands or any others. 'ls --help' will give you details of all the
possible variations for this command.
The 'file' command
File is an interesting little command. MS-DOS got us all used to the idea that
a file had to have an extension (file.extension- like 'novel.txt') that told us
what kind of a file it was. In Linux, it's 50/50. You don't have to do that if
you don't want. In MS-DOS, programs end in '.exe', in Linux, they don't have to
and probably won't.
Linux is also color coded, as you know, so once you get used to the colors,
you'll know what the file is about. Let's say your friend Tony, the one with
the magic markers, sends you a file he says is really neat. It's attached to an
e-mail message and it says 'stuff'. You can see what type of file it is by
typing:
'file stuff'
You may see something like this:
'stuff: ASCII text'
This means that the file contains plain text. It's probably some jokes or his
favorite chili recipe.
If you don't know what some particular file contains and you're curious about
it, you can use this command to get some information about the file.
'more' and 'less'
To introduce the student to these commands 'more' is a command that you can use
to read, for example, what's written in that 'stuff' file that Tony sent you.
You would type 'more stuff' to see the jokes.
Press the 'q' key to stop viewing the file
It's useful for this, but not really ideal. We'll talk more about 'more' in
this lesson when we use it in combination with other commands
'less' is better for viewing files. You can scroll back up to see the whole text if you want. You can't do that with 'more'. 'less' is more than 'more', if you get my meaning.
type 'less stuff' to see Tony's jokes again
Again, press the 'q' key to stop viewing the file
[Previous] [Next]
|