| Navigation |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Linux File Systems Versus Windows-Based File Systems |
|
| |

Although similar in many ways, the Linux file system has some striking differences from file systems used in MS-DOS and Windows operating systems.
Here are a few:
In MS-DOS and Windows file systems, drive letters represent different storage devices (for example, A: is a floppy drive and C: is a hard disk). In Linux, all storage devices are fit into the file system hierarchy.
So, the fact that all of /usr may be on a separate hard disk or that /mnt/rem1 is a file system from another computer is invisible to the user.
Slashes, rather than backslashes, are used to separate directory names in Linux. So,
C:homechris in an MS system is /home/chris in a Linux system.
Filenames almost always have suffixes in DOS (such as .txt for text files or .doc for
word-processing files). Although at times you can use that convention in Linux,
three-character suffixes have no required meaning in Linux. They can be useful for
identifying a file type. Many Linux applications and desktop environments use file
suffixes to determine the contents of a file.

Every file and directory in a Linux system has permissions and ownership associated
with it. Security varies among Microsoft systems. Because DOS and MS Windows
began as single-user systems, file ownership was not built into those systems when
they were designed. Later releases added features such as file and folder attributes
to address this problem.
Creating Files and Directories
As a Linux user, most of the files you save and work with will probably be in your
home directory. Table 2-9 shows commands to create and use files and directories.
Table 2-9
Commands to Create and Use Files
Command Result
cd Change to another current working directory.
pwd Print the name of the current working directory.
mkdir Create a directory.
chmod Change the permission on a file or directory.
ls List the contents of a directory.
The following steps lead you through creating directories within your home direc-
tory and moving among your directories, with a mention of setting appropriate file
permissions:
1. Go to your home director y. To do this, simply type cd. (For other ways of
referring to your home directory, see the “Identifying Directories” sidebar.)
2. To make sure that you got to your home directory, type pwd. When I do this, I
get the following response (yours will reflect your home director y):
$ pwd
/home/chris
3. Create a new directory called test in your home director y, as follows:
$ mkdir test
4. Check the permissions of the director y:
$ ls -ld test
drwxr-xr-x 2 chris sales 1024 Jan 24 12:17 test
This listing shows that test is a directory (d). The d is followed by the per-
missions (rwxr-xr-x), which are explained later in the “Understanding File
Permissions” section. The rest of the information indicates the owner
(chris), the group (sales), and the date that the files in the directory were
most recently modified (Jan. 24 at 12:17 p.m.).
In some Linux systems, such as Fedora Core, when you add a new user, the user is
assigned to a group of the same name by default. For example, in the preceding
text, the user chris would be assigned to the group chris. This approach to
assigning groups is referred to as the user private group scheme. For more infor-
mation on user private groups, see Chapter 4.
Note
For now, type the following:
$ chmod 700 test
This step changes the permissions of the directory to give you complete
access and everyone else no access at all. (The new permissions should read
as follows: rwx------.)
5. Make the test directory your current directory as follows:
$ cd test
Using Metacharacters and Operators
To make efficient use of your shell, the bash shell lets you use certain special char-
acters, referred to as metacharacters and operators. Metacharacters can help you
Identifying Directories
When you need to identify your home directory on a shell command line, you can use the
following:
$HOME — This environment variable stores your home directory name.
~ — The tilde (~) represents your home directory on the command line.
You can also use the tilde to identify someone else’s home directory. For example, ~chris
would be expanded to the chris home directory (probably /home/chris).
Other special ways of identifying directories in the shell include the following:
. — A single dot (.) refers to the current directory.
..— Two dots (..) refer to a directory directly above the current directory.
$PWD — This environment variable refers to the current working directory.
$OLDPWD— This environment variable refers to the previous working directory before
you changed to the current one.
match one or more files without typing each file completely. Operators let you
direct information from one command or file to another command or file.
Using File-Matching Metacharacters
To save you some keystrokes and to be able to refer easily to a group of files, the
bash shell lets you use metacharacters. Anytime you need to refer to a file or direc-
tory, such as to list it, open it, or remove it, you can use metacharacters to match
the files you want. Here are some useful metacharacters for matching filenames:
* — Matches any number of characters.
? — Matches any one character.
[...] — Matches any one of the characters between the brackets, which can
include a dash-separated range of letters or numbers.
Try out some of these file-matching metacharacters by first going to an empty
directory (such as the test director y described in the previous section) and creat-
ing some empty files:
$ touch apple banana grape grapefruit watermelon
The touch command creates empty files. The next few commands show you how to
use shell metacharacters with the ls command to match filenames. Try the follow-
ing commands to see if you get the same responses:
$ ls a*
apple
$ ls g*
grape
grapefruit
$ ls g*t
grapefruit
$ ls *e*
apple grape grapefruit watermelon
$ ls *n*
banana watermelon
The first example matches any file that begins with an a (apple). The next example
matches any files that begin with g (grape, grapefruit). Next, files beginning with
g and ending in t are matched (grapefruit). Next, any file that contains an e in the
name is matched (apple, grape, grapefruit, watermelon). Finally, any file that
contains an n is matched (banana, watermelon).
Here are a few examples of pattern matching with the question mark (?):
$ ls ?e
apple grape
$ ls g???e*
grape grapefruit
The first example matches any five-character file that ends in e (apple, grape). The
second matches any file that begins with g and has e as its fifth character (grape,
grapefruit).
Here are a couple of examples using braces to do pattern matching:
$ ls [abw]*
apple banana watermelon
$ ls [agw]*[ne]
apple grape watermelon
In the first example, any file beginning with a, b, or w is matched. In the second, any
file that begins with a, g, or w and also ends with either n or e is matched. You can
also include ranges within brackets. For example:
$ ls [a-g]*
apple banana grape grapefruit
Here, any filenames beginning with a letter from a through g is matched.
Using File-Redirection Metacharacters
Commands receive data from standard input and send it to standard output. Using
pipes (described earlier), you can direct standard output from one command to the
standard input of another. With files, you can use less than (<) and greater than (>)
signs to direct data to and from files. Here are the file-redirection characters:
< — Directs the contents of a file to the command.
> — Directs the output of a command to a file, deleting the existing file.
>> — Directs the output of a command to a file, adding the output to the end
of the existing file.
Here are some examples of command lines where information is directed to and
from files:
$ mail root < ~/.bashrc
$ man chmod | col -b > /tmp/chmod
$ echo “I finished the project on $(date)” >> ~/projects
In the first example, the contents of the .bashrc file in the home director y are sent
in a mail message to the computer’s root user. The second command line formats
the chmod man page (using the man command), removes extra back spaces (col -
b), and sends the output to the file /tmp/chmod (erasing the previous /tmp/chmod
file, if it exists). The final command results in the following text’s being added to the
user’s project file:
I finished the project on Sat Jan 25 13:46:49 PST 2006
Understanding File Permissions
After you’ve worked with Linux for a while, you are almost sure to get a
Permission denied message. Permissions associated with files and directories in
Linux were designed to keep users from accessing other users’ private files and to
protect important system files.
The nine bits assigned to each file for permissions define the access that you and
others have to your file. Permission bits appear as rwxrwxrwx. The first three bits
apply to the owner’s permission, the next three apply to the group assigned to the
file, and the last three apply to all others. The r stands for read, the w stands for
write, and the x stands for execute permissions. If a dash appears instead of the let-
ter, it means that permission is turned off for that associated read, write, or execute.
Because files and directories are different types of elements, read, write, and exe-
cute permissions on files and directories mean different things. Table 2-10 explains
what you can do with each of them:
Setting Read, Write, and Execute Permissions
Permission File
Directory
Read View what’s in the file. See what files and subdirectories it contains.
Write Change the file’s content, Add files or subdirectories to the directory.
rename it, or delete it.
Execute Run the file as a program. Change to that directory as the current
directory, search through the directory, or
execute a program from the directory.
You can see the permission for any file or director y by typing the ls -ld command.
The named file or directory appears as those shown in this example:
$ ls -ld ch3 test
-rw-rw-r-- 1 chris sales 4983 Jan 18 22:13 ch3
drwxr-xr-x 2 chris sales 1024 Jan 24 13:47 test
The first line shows that the ch3 file has read and write permission for the owner
and the group. All other users have read permission, which means they can view
the file but cannot change its contents or remove it. The second line shows the
test directory (indicated by the letter d before the permission bits). The owner
has read, write, and execute permission, while the group and other users have only
read and execute permissions. As a result, the owner can add, change, or delete
files in that directory, and everyone else can only read the contents, change to that
directory, and list the contents of the directory.
If you own a file, you can use the chmod command to change the permission on it as
you please. In one method of doing this, each permission (read, write, and execute),
is assigned a number — r=4, w=2, and x=1 — and you use each set’s total number to
establish the permission. For example, to make permissions wide open for yourself
as owner, you’d set the first number to 7 (4+2+1), and to give the group and others
only read permission, you’d both the second and third numbers to 4 (4+0+0), so
that the final number is 744. Any combination of permissions can result from 0 (no
permission) through 7 (full permission).
Here are some examples of how to change permission on a file (named file) and
what the resulting permission would be:
# chmod 777 file rwxrwxrwx
# chmod 755 file rwxr-xr-x
# chmod 644 file rw-r--r-
# chmod 000 file ---------
You can also turn file permissions on and off using plus (+) and minus (–) signs,
respectively. This can be done for the owner user (u), owner group (g), others (o),
and all users (a). For example, start with a file that has all permissions open (rwxr-
wxr wx). Run the following chmod commands using minus sign options. The result-
ing permissions are shown to the right of each command:
chmod a-w file r-xr-xr-x
chmod o-x file rwsrwsrw-
chmod go-rwx file rwx------
Likewise, here are some examples, starting with all permissions closed (---------)
where the plus sign is used with chmod to turn permissions on:
chmod u+rw files rw-------
chmod a+x files --x--x--x
chmod ug+rx files r-xr-x---
When you create a file, it’s given the permission rw-r--r-- by default. A director y is
given the permission rwxr -xr-x. These default values are determined by the value of
umask. Type umask to see what your umask value is. For example:
$ umask
022
The umask value masks the permissions value of 666 for a file and 777 for a direc-
tory. The umask value of 022 results in permission for a director y of 755 (r wxr-xr-x).
That same umask results in a file permission of 644 (r w-r--r--). (Execute permissions
are off by default for regular files.)
Time saver: use the -R options of chmod, to change the permission for all of the
files and directories within a directory structure at once. For example, if you
wanted to open permissions completely to all files and directories in the
/tmp/test directory, you could type the following:
Tip
$ chmod -R 777 /tmp/test
This command line runs chmod recursively (-R) for the /tmp/test directory, as
well as any files or directories that exist below that point in the file system (for
example, /tmp/test/hat, /tmp/test/hat/caps, and so on). All would be set
to 777 (full read/write/execute permissions). This is not something you would do
on an important directory on a read/write file system. However, you might do this
before you create a directory structure on a CD-ROM that you want to be fully
readable and executable to someone using the CD-ROM later.
Caution
The -R option of chmod works best if you are opening permissions completely or
adding execute permission (as well as the appropriate read/write permission).
The reason is that if you turn off execute permission recursively, you close off your
capability to change to any directory in that structure. For example, chmod -R 644
/tmp/test turns off execute permission for the /tmp/test directory, and then
fails to change any files or directories below that point.

Moving, Copying, and Deleting Files
Commands for moving, copying, and deleting files are fairly straightforward. To
change the location of a file, use the mv command. To copy a file from one location
to another, use the cp command. To remove a file, use the rm command. Here are
some examples:
$ mv abc def
$ mv abc ~
$ cp abc def
$ cp abc ~
$ rm abc
$ rm *
Of the two move (mv) commands, the first moves the file abc to the file def in the
same directory (essentially renaming it), whereas the second moves the file abc to
your home director y (~). The first copy command (cp) copies abc to the file def,
whereas the second copies abc to your home directory (~). The first remove com-
mand (rm) deletes the abc file; the second removes all the files in the current direc-
tory (except those that start with a dot).
Note
For the root user, the mv, cp, and rm commands are aliased to each be run with
the -i option. This causes a prompt to appear asking you to confirm each move,
copy, and removal, one file at a time, and is done to prevent the root user from
messing up a large group of files by mistake.
Another alternative with mv is to use the -b option. With -b, if a file of the same
name exists at the destination, a backup copy of the old file is made before the
new file is moved there.
Using the vi Text Editor
It’s almost impossible to use Linux for any period of time and not need to use a text
editor. This is because most Linux configuration files are plain text files that you
will almost cer tainly need to change manually at some point.
If you are using a GUI, you can run gedit, which is fairly intuitive for editing text.
There’s also a simple text editor you can run from the shell called nano. However,
most Linux shell users will use either the vi or emacs command to edit text files.
The advantage of vi or emacs over a graphical editor is that you can use it from any
shell, a character terminal, or a character-based connection over a network (using
telnet or ssh, for example) — no GUI is required. They also each contain tons of
features, so you can continue to grow with them.
This section provides a brief tutorial on the vi text editor, which you can use to
manually edit a configuration file from any shell. (If vi doesn’t suit you, see the
“Exploring Other Text Editors” sidebar for other options.)
Exploring Other Text Editors
Dozens of text editors are available for use with Linux. Here are a few that might be in your
Linux distribution, which you can try out if you find vi to be too taxing.
Text Editor Description
nano A popular, streamlined text editor that is used with many bootable Linuxes
and other limited-space Linux environments. For example, nano is often
available to edit text files during a LInux install process.
gedit The GNOME text editor that runs in the GUI.
jed This screen-oriented editor was made for programmers. Using colors, jed
can highlight code you create so you can easily read the code and spot
syntax errors. Use the Alt key to select menus to manipulate your text.
joe The joe editor is similar to many PC text editors. Use control and arrow
keys to move around. Press Ctrl+C to exit with no save or Ctrl+X to save
and exit.
kate A nice-looking editor that comes in the kdebase package. It has lots of
bells and whistles, such as highlighting for different types of programming
languages and controls for managing word wrap.
kedit A GUI-based text editor that comes with the KDE desktop.
mcedit With mcedit, function keys help you get around, save, copy, move, and
delete text. Like jed and joe, mcedit is screen-oriented.
nedit An excellent programmer’s editor. You need to install the optional nedit
package to get this editor.
If you use ssh to log in to other Linux computers on your network, you can use any editor
to edit files. A GUI-based editor will pop up on your screen. When no GUI is available, you
will need a text editor that runs in the shell, such as vi, jed, or joe.
The vi editor is difficult to learn at first, but once you know it, you never have to
use a mouse or a function key — you can edit and move around quickly and effi-
ciently within files just by using the keyboard.
Starting with vi
Most often, you start vi to open a particular file. For example, to open a file called
/tmp/test, type the following command:
$ vi /tmp/test
If this is a new file, you should see something similar to the following:
“/tmp/test” [New File]
The box at the top represents where your cursor is. The bottom line keeps you
informed about what is going on with your editing (here you just opened a new
file). In between, there are tildes (~) as filler because there is no text in the file yet.
Now here’s the intimidating part: There are no hints, menus, or icons to tell you
what to do. On top of that, you can’t just start typing. If you do, the computer is
likely to beep at you. And some people complain that Linux isn’t friendly.
The first things you need to know are the different operating modes: command and
input. The vi editor always starts in command mode. Before you can add or change
text in the file, you have to type a command (one or two letters and an optional
number) to tell vi what you want to do. Case is important, so use uppercase and
lowercase exactly as shown in the examples! To get into input mode, type an input
command. To star t out, type either of the following:
a — The add command. After it, you can input text that starts to the right of
the cursor.
|
Latest Post
|

|
-
14/08 – A Summary of Cd Dvd Burning Currently Available for Linux
-
14/08 – Web Browsers for Linux
-
14/08 – Linux Administration System
-
14/08 – Linux and Unix Email Clients
-
14/08 – Backup for Linux Systems
-
10/07 – Created to Copy and Essentially Clone with CloneIT
-
09/07 – Linux: Keystrokes for Navigating Command Lines
-
09/07 – Using the Linux Shell
-
09/07 – Starting with Linux
-
07/07 - News and features List of Linux and BSD Distributions
-
20/04 - Gnome Toaster a Cd recordingr frontend for X/Gtk
-
17/04 – TCDR, a dialog-based console frontend for mkisofs, cdrecord, cdrdao, cdparanoia
-
10/04 – HacBurn, a script written in Perl to aim in writting Cds
-
05/04 – Phaser, a frontend to Cdrecord with the aim of making Cd burning under Linux easier
-
16/03 – BurnCDDA console frontend per Cdrecord, mpg123, oggdec, mppdec, flac
-
15/03 – Gobuntu 8.04 Hardy Heron alpha 6 released
|
 |
Linux Links
|
|
|
|
|
|
|
|
|
|
| |
Today, there have been 134 visits (233 hits) on this page!
|
|
|
|
|
|
|
|