📄 0320-0322.html
字号:
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311623:SAMS TEACH YOURSELF LINUX IN 24 HOURS:Handling Files</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311623 //-->
<!-- TITLE=SAMS TEACH YOURSELF LINUX IN 24 HOURS //-->
<!-- AUTHOR=BILL BALL, STEPHEN SMOOGEN //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=21 //-->
<!-- PAGES=0313-0328 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0317-0319.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0323-0325.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-320"><P>Page 320</P></A>
<P>The preceding example used the -c option to check the disk for any bad blocks, and the
-L option to give the floppy a name. In order to see what's going on, it also used the
-v (verbose mode) option. The mke2fs command will automatically determine the size of your
floppy, check it using the badblocks command, found under the
/sbin directory, and then create your Linux filesystem. You might also want to use the
-m option with a value of 0 to have the most room available, and specify the high-density floppy device (by default,
mke2fs will reserve five percent of the filesystem for the root operator), as follows:
</P>
<!-- CODE SNIP //-->
<PRE>
# mke2fs -m 0 /dev/fd0H1440 1440
</PRE>
<!-- END CODE SNIP //-->
<P>As a final step, you can mount the floppy, using the
mount command, and then check the floppy's size, for example:
</P>
<!-- CODE //-->
<PRE>
# mount -t ext2 /dev/fd0 /mnt/floppy
# df /dev/fd0
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/fd0 1390 13 1377 1% /mnt/floppy
</PRE>
<!-- END CODE //-->
<P>Knowing how to format floppy drives is important. If you're only interested in
DOS floppies, you'll want to explore the mtools package, discussed next.
</P>
<H3><A NAME="ch21_ 8">
The mtools Package
</A></H3>
<P>The mtools package is a set of programs you can use in just about any operation on
MS-DOS floppies. These utilities include
</P>
<UL>
<LI> mattrib—Change file attributes
<LI>mbadblocks—Floppy testing program
<LI> mcd—Change directory command
<LI> mcheck—Check a floppy
<LI> mcopy—Copy files to and from disk
<LI> mdel—Delete files on disk
<LI> mdeltree—Recursively delete files and directories
<LI> mdir—List contents of a floppy
<LI> mformat—Format a floppy
<LI> minfo—Categorize, print floppy characteristics
<LI> mkmanifest—Restore Linux filenames from floppy
<LI> mlabel—Label a floppy
<LI> mmd—Create subdirectory
<LI> mmount—Mount floppy
</UL>
<A NAME="PAGENUM-321"><P>Page 321</P></A>
<UL>
<LI> mmove—mv command for floppy files, directories
<LI> mpartition—Make DOS filesystem as partition
<LI> mrd—Delete directories
<LI> mren—Rename a file
<LI> mtoolstest—Test mtools package installation
<LI> mtype—Types a file
<LI> mzip—Zip/Jaz drive utility
<LI> xcopy—Copy one directory to another
</UL>
<P>This hour doesn't cover all these utilities, but from the list, you should be able to see
that the most often used will be the mformat, mdir,
mcopy, and mdel commands. The mformat command will format nearly any type of floppy device. One nice feature of this package of
software is that you don't have to remember the specific names of floppy devices, such as
</P>
<P>/dev/fd0, and can use the (possibly) familiar A: or B: drive designators. For example, to
format a floppy in your drive A:, you would use
</P>
<!-- CODE SNIP //-->
<PRE>
# mformat a:
</PRE>
<!-- END CODE SNIP //-->
<P>This will automatically format your disk. After the
mformat command has finished, you can copy files to and from the disk with the
mcopy command, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# mcopy *.txt a:
</PRE>
<!-- END CODE SNIP //-->
<P>This will copy all files ending in .txt to your disk. To copy files from your disk, just
reverse the arguments (in DOS form) to the mcopy command:
</P>
<!-- CODE SNIP //-->
<PRE>
# mcopy a:*.txt
</PRE>
<!-- END CODE SNIP //-->
<P>This will copy all files ending in .txt to the current directory, or a directory you specify.
To see what is on the disk, use the mdir command, for example:
</P>
<!-- CODE //-->
<PRE>
# mdir a:x*.*
Volume in drive A has no label
Directory for A:/
xena msg 8708 11-21-1997 12:14p xena.msg
xgames msg 2798 11-21-1997 12:14p xgames.msg
xrpm msg 3624 11-21-1997 12:14p xrpm.msg
3 file(s) 15 130 bytes
1 067 008 bytes free
</PRE>
<!-- END CODE //-->
<P>To label the disk, you can use the mlabel command, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# mlabel a:
Volume has no label
Enter the new volume label : LINUX
</PRE>
<!-- END CODE SNIP //-->
<A NAME="PAGENUM-322"><P>Page 322</P></A>
<P>To delete files on your disk, use the mdel command:
</P>
<!-- CODE SNIP //-->
<PRE>
# mdel a:*.txt
</PRE>
<!-- END CODE SNIP //-->
<P>This will delete all files ending in .txt on the disk in the a: drive.
You've learned the basic operations, but you can also mount your disk. For details, see the
mmount manual page, along with the mount command manual page. Now that you know how to manage
different filesystems, the next section covers how to manage your files.
</P>
<H3><A NAME="ch21_ 9">
Managing File Ownership and Permissions
</A></H3>
<P>Managing files in Linux means more than moving files around the file system or keeping
</P>
<P>files grouped by similar behavior or topic. You can change which user or group owns a
file or directory, and whether or not you, your group, or others can read, write, or execute
(run) your files.
</P>
<P>The chmod (change access permissions) command, found under the
/bin directory, is used to give or take away permission of groups or others to your files. Before you can begin
to use the chmod program, you should understand Linux files and how Linux handles
file permissions. In Hour 4, "Reading and Navigation Commands," you learned how to
get a long-format directory listing using the -l option with the
ls (list) command. This option shows the mode and permissions flags of files, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# ls -l book/*doc
-rw-r--r-- 1 bball bball 78073 Nov 16 19:58 book/24hr06or.doc
-rw-r--r-- 1 bball bball 52287 Nov 16 19:57 book/24hr11or.doc
</PRE>
<!-- END CODE SNIP //-->
<P>The mode and permissions flags for directories and files is listed in the first column,
and consists of a sequence of 10 letters. The first letter tells you the type of file.
</P>
<H4><A NAME="ch21_ 10">
Understanding Linux File Types
</A></H4>
<P>There are at least eight file types in Linux, but these are the four most common ones:
</P>
<UL>
<LI> b—Block device
<LI> c—Character device
<LI> d—Directory
<LI> l—Symbolic link
</UL>
<P>You'll usually find block and character devices under the
/dev directory. Your modem or printer port on your PC will probably be a character device, whereas your floppy drive
is a block device, for example:
</P>
<!-- CODE SNIP //-->
<PRE>
# ls -l /dev/lp0 /dev/cua1 /dev/fd0
crw-rw---- 1 root uucp 5, 65 Dec 31 1979 /dev/cua1
brw-rw---- 1 root disk 2, 0 Sep 15 23:48 /dev/fd0
</PRE>
<!-- END CODE SNIP //-->
<P><CENTER>
<a href="0317-0319.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0323-0325.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -