Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 46 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
46
Dung lượng
1,39 MB
Nội dung
The three triads are read as follows: ߜ The first triad consists of the second, third, and fourth characters in the long format file listing. This triad sets the permissions for the user, or owner, of the file. (Owners are discussed in the “Beware of owners” sec- tion, later in this chapter.) ߜ The second triad consists of the fifth, sixth, and seventh characters in the long format file listing. This triad sets the permissions for the group that is assigned to the file. (Groups are discussed in the “Hanging out in groups” section, later in this chapter.) ߜ The third triad consists of the eighth, ninth, and tenth characters in the long format file listing. This triad sets the permissions for other, or everyone who isn’t the file’s owner or a member of the owning group. Although each triad is often different from the others, the internal structure of each one is made up in the same way. Focus specifically on how to read one triad before looking at the set of them together. Each triad includes three characters: ߜ The first character is either an r or a dash. The r stands for read permis- sion. If r is set, the triad allows the entity it stands for (user, group, or other) to view the directory or file’s contents. ߜ The second character is either a w or a dash. The w stands for write per- mission. If w is set, the triad allows the entity it stands for to add or edit items to, or in, this directory or file. ߜ The third character is either an x or a dash. The x stands for execute permission. If x is set, the triad allows the entity it stands for to run programs contained in this directory or to run the particular program in this file. In all cases, if the dash sits in place of r, w, or x, the triad doesn’t allow the entity the read, write, or execute permission. The following sections describe owners and groups in more detail. Beware of owners You may have noticed by now that I talk a great deal about owners (users) and groups in Linux. Every file and directory has both of these components: a user from the /etc/passwd file that’s assigned as its owner and a group from /etc/group assigned as the group. Although an everyday user probably doesn’t need to change file ownerships often, the root user does so regularly. If you add the file comments, for exam- ple, to /home/tom while you’re logged on as the superuser (another term for the administrator, who is the person who owns the root account), root owns that file. The user tom can’t do anything with it unless you have set the last 212 Part III: Getting Up to Speed with Linux 16_579371 ch10.qxd 12/27/04 8:33 PM Page 212 triad’s permissions to allow the other folks (those who aren’t the file’s owner or in the specified group) to read and write to the file. But this method is a pretty sloppy way of doing things because the whole idea of permissions is to reduce access, not to give everyone access. Instead, remember to change the file’s owner to the user tom. You do this with the chown (change owner) com- mand. For example, by typing chown tom comments, root changes the own- ership over to tom. Then tom can work with this file and even change its permissions to something he prefers. Hanging out in groups Groups are more interesting to work with than owners. You use groups to allow the root user to assign to multiple users the ability to share certain file system areas. For example, in many versions of Linux, all users are added to a group named users (SuSE does this, for example). Then, rather than a long format file listing such as the one shown in earlier in this chapter, you may see the following: total 20 drwx 2 dee users 4096 Jul 29 07:48 . drwxr-xr-x 5 root root 4096 Jul 27 11:57 -rw-r r 1 dee users 24 Jul 27 06:50 .bash_logout -rw-r r 1 dee users 230 Jul 27 06:50 .bash_profile -rw-r r 1 dee users 124 Jul 27 06:50 .bashrc -rw-rw-r 1 dee users 0 Jul 29 07:48 lsfile In other distributions (such as Fedora) a unique group is created for every user, which is why the earlier listings showed the owner and group items as identical ( dee dee). Comprehending file types The first letter in any long format file listing tells you which type of file you’re dealing with. In Table 10-1, I list the types you’re likely to run into. Table 10-1 Linux File Types Label Type Description - Regular file The item is an everyday file, such as a text file or program. b Block device The item is a driver (control program) for a storage medium, such as a hard drive or CD-ROM drive. (continued) 213 Chapter 10: Manipulating Files and Directories 16_579371 ch10.qxd 12/27/04 8:33 PM Page 213 Table 10-1 (continued) Label Type Description c Character device The item is a driver (control program) for a piece of hardware that transmits data, such as a modem. d Directory The item is a container for files, also referred to as a folder in some operating systems’ lingo. In addition to this, you find lots more different file types out there in the Linux world. By types, I’m not referring to extensions, such as .exe or .doc. Linux sees everything within its file system — even directories and hardware like your monitor — as “files.” As a result, assigning a type to a file is merely a Linux machine’s way of keeping track of what’s what. The main thing Windows users in particular want to know when they move to Linux is how to recognize programs. Rather than looking for files with partic- ular extensions (like .exe) programs have (or need to have) an executable permission set so the system knows they are allowed to run. You can view or set this permission for a file by going to the Nautilus or Konqueror section and looking up how to do so. 214 Part III: Getting Up to Speed with Linux 16_579371 ch10.qxd 12/27/04 8:33 PM Page 214 Chapter 11 Checking Out the Linux Filesystem In This Chapter ᮣ Discovering the root directory and subdirectories ᮣ Discerning partitions from directories ᮣ Adding removable media to the filesystem ᮣ Caring for your filesystem ᮣ Accessing shared files on Windows computers I have an existential map. It has “You are here” written all over it. — Steven Wright O ne of the most frustrating things about learning a new operating system can be figuring out where it keeps files. Rather than keep all important system files in a single directory, such as the C:\Windows direc- tory in Microsoft Windows, Linux follows the lead of its Unix cousins and spreads things out a bit more. Although the Linux and Windows setups involve different methods, they are both logical, though it may not feel that way until you understand where to look. Another issue you come across is adding new media — hard drives, floppy disks, CD-ROMs, DVD-ROMs, zip disks, and more — to the existing filesystem. In this chapter, I focus on how the filesystem is organized and other handy topics, such as how to access data on a floppy disk. (In Chapter 10, you can find hints on how to do this when looking through the file managers.) Introducing the Linux Filesystem Linux may be all by itself on your hard drive, or maybe it’s sharing your hard drive with another operating system, such as Microsoft Windows. All the hard drive space you allocated for Linux during the installation process 17_579371 ch11.qxd 12/27/04 8:36 PM Page 215 is the majority of your Linux filesystem. Because you’re running your own Linux machine, you need to be familiar with how it’s put together — especially the sections that are dangerous to mess with! Meet the root directory Everything in the Linux filesystem is relative to the root directory, which is referred to as / and is the file-system base, a doorway into all your files — don’t confuse this with the root user, which is the system administrator. The root directory contains a mostly predictable set of subdirectories. Each dis- tribution varies slightly, but certain standards exist to which they all con- form. The standards keep us all sane. If you’re interested in these standards, go to www.pathname.com/fhs and look at the latest version of the rules. Rather than flood you with everything at once, I start by talking about the base directories, meaning the items you find in /. Table 11-1 lists what you might find in this base location. (This list can vary some from distribution to distribution.) An asterisk (*) at the end of a description indicates that you shouldn’t mess with this directory unless you have a really good reason because it contains files that are very important to the functioning of your system. Table 11-1 Standard / Contents in Linux Directory Contains /bin Essential commands that everyone needs to use at any time* /boot The information that boots the machine, including your kernel* /dev The device drivers for all the hardware that your system needs to interface with* /etc The configuration files for your system* /home The home directories for each of your users /lib The libraries, or code that many programs (and the kernel) use* /media A spot where you add temporary media, such as floppy disks and CD-ROMs; not all distributions have this directory /mnt Another spot where you add temporary media, such as floppy disks and CD-ROMs, along with networked drives and other items you aren’t permanently adding to your filesystem 216 Part III: Getting Up to Speed with Linux 17_579371 ch11.qxd 12/27/04 8:36 PM Page 216 Directory Contains /opt The location that some people decide to use (and some pro- grams want to use) for installing new software packages, such as word processors and office suites /root The superuser’s (root user’s) home directory /sbin The commands the system administrator needs access to* /srv Data for your system’s services (the programs that run in the background)* /tmp The place where everyone and everything store temporary files /usr A complex hierarchy of additional programs and files /var The data that changes frequently, such as log files and your mail Some of these directories have some equally important subdirectories, which I cover in the upcoming sections. Meet the /etc subdirectories Although the exact subdirectories that exist in /etc can change from distrib- ution to distribution, the following two are fairly standard: ߜ The /etc/X11 directory contains configuration details for the X Window System (X), which runs your Graphical User Interface (GUI). See Chap- ter 15 for more on the GUI. ߜ The /etc/opt directory contains configuration files for the programs in the /opt directory, if you decide to use it. An important addition in Fedora is /etc/sysconfig, which contains configu- ration information for the services that start at boot time, including things like your networking. Meet the /mnt and /media subdirectories You may or may not have any subdirectories in /media or /mnt by default (and you may not have both of these directories at the same time). Typically, however, you do have the following: ߜ The /mnt/floppy or /media/floppy directory is used for adding a floppy disk to your filesystem — instead of the word floppy, you might see fd0 instead. 217 Chapter 11: Checking Out the Linux Filesystem 17_579371 ch11.qxd 12/27/04 8:36 PM Page 217 ߜ The /mnt/cdrom directory is used for adding a CD-ROM to your filesys- tem in some distributions, and others use /media/cdrom (or /media/ dvd , /media/cdrecorder, and so on, depending on what type of hard- ware you have). In the “Adding Media to Your Filesystem” section, later in this chapter, I show you how to add these items for each of the distributions. Meet the /usr subdirectories The /usr directory is often referred to as its own miniature filesystem hierar- chy. This directory has lots of important or interesting subdirectories, as shown in Table 11-2. An asterisk (*) at the end of a description indicates that you need to leave that directory alone unless you have good reason to mess with it — after you gain lots of experience with Linux and know exactly what changes you need to make — so that you don’t accidentally alter something your system needs in order to function correctly. An important thing to remember about this segment of the filesystem is that many advanced Linux users often use /usr to store programs that can be shared with other machines. Table 11-2 Standard /usr Subdirectories Subdirectory Contents /usr/X11R6 The files that run the X Window System (the wireframe for your GUI)* /usr/bin The commands that aren’t essential for users but are useful* /usr/games The games that you install on your system, except for those that you can choose to place in /opt /usr/include The files that the C programming language needs for the system and its programs* /usr/lib The code used by many of the programs in this /usr sub- hierarchy* /usr/local The programs and other items that you want to keep locally, even if you’re sharing everything else in /usr /usr/sbin The commands that aren’t essential for administrators but are useful* 218 Part III: Getting Up to Speed with Linux 17_579371 ch11.qxd 12/27/04 8:36 PM Page 218 Subdirectory Contents /usr/share The information that you can use on any Linux machine, even if it’s running incredibly different hardware from what this one is running* /usr/src The source code that you use to build the programs on your system Finding CDs and More in Your GUI Chapter 10 covers how to use the file managers that come with the distribu- tions covered with this book (and most other Linux desktop-based distribu- tions, for that matter) — Nautilus and Konqueror. In this section, I take a look at how to use these tools to find your way around the filesystem. Some distri- butions make this process more intuitive than others, mostly due to tons of handy shortcuts that mean you have to know less of what’s happening under the hood — a pretty handy thing for desktop users. Navigating the filesystem in Fedora Because Fedora’s default GUI is GNOME (see Chapter 6), which is different from all the other distributions discussed in this book, you use Nautilus (see Chapter 10) to find your way around. Some things are made pretty easy for you: ߜ When you insert a data CD-ROM or DVD-ROM, an icon may or may not appear on your desktop. If it doesn’t appear, double-click the Computer icon and then the drive’s icon within the Nautilus window in order to access the CD-ROM’s or DVD-ROM’s contents and add an icon to your desktop. You can later remove these items by right-clicking and choos- ing Eject from the shortcut menu. ߜ When you plug in a USB storage device such as a keychain, Fedora auto- matically adds an icon onto your desktop for that item, which you can double-click to open. Once you’re finished working with the USB device, close all of the windows that were using it, right-click its icon on the desktop, and choose Unmount. Now it’s safe to remove the keychain. ߜ When you insert a music CD, Fedora opens a music player and begins playing it. ߜ When you insert a video DVD, Fedora is not configured to auto-run its contents. See Chapter 18 for more on watching DVDs. 219 Chapter 11: Checking Out the Linux Filesystem 17_579371 ch11.qxd 12/27/04 8:36 PM Page 219 To turn on or off auto-run or auto-loading for these various items, from the main menu, choose Preferences➪Removable Storage. If you shut off auto-loading for something, you can access a device’s contents from any Nautilus window by choosing Places➪Computer and double-clicking the appropriate icon in there. This action adds an icon onto your desktop as well. ߜ When you insert a blank CD or DVD writeable or re-writeable, Fedora opens Nautilus to the CD/DVD Creator window. (You can find out more about burning in Chapter 18.) ߜ When it comes to floppies, the computer can’t reliably detect that a floppy was put into the drive. So, put the floppy into the drive and then, from any Nautilus window, choose Places➪Computer➪Floppy to access its contents and add a floppy icon on your desktop. To remove the floppy, right-click the floppy icon on your desktop or in your Nautilus Computer window and then choose Unmount Volume. Wait until the floppy drive light is off before removing the floppy. ߜ If you want to access a network drive from Windows or that someone has set up on another Linux computer, double-click the Computer icon on your desktop (or choose Places➪ Computer) from any Nautilus window) and then double-click the Network icon. This action lets you browse through your network to the computers that are offering files. ߜ If you want to access part of your Linux filesystem, double-click the Computer icon on your desktop (or choose Places➪ Computer) from any Nautilus window) and then double-click the Filesystem icon. ߜ If you want to access something on one of your hard drives that isn’t part of your Linux installation (maybe a Windows drive). For the last option listed, follow these steps: 1. Open a command line terminal. See Chapter 14 if you’re not sure how to do so. 2. Type su - to become the root (administrative) user. 3. Type fdisk -l to see all your hard drives and partitions. If you’re looking for a Windows partition, then you can find it right here. Ignore the items that have text similar to Windows 95 Ext’d; they’re not really a data partition. Anything that has NTFS or FAT32 or VFAT is a Windows partition and is what you’re interested in. If you’re looking for a Linux partition (maybe you have more than one distribution installed on your system), then you want the ones that have the word Linux in their description and not the word swap. 220 Part III: Getting Up to Speed with Linux 17_579371 ch11.qxd 12/27/04 8:36 PM Page 220 4. If you need to access an NTFS partition, see Chapter 12 for how to use yum to add NTFS support. You can search to see whether you have NTFS support in your current set of yum repositories by typing yum search ntfs. If no matches are found, then you may need to add another repository. 5. When you think you know what partition you want to try, type mount -t type /dev/partition /mnt to add it to your filesystem, where type is the filesystem type as shown in Table 11-3 and partition is the letter and number combination you saw in fdisk (such as hde2). So, for example, after adding NTFS support, you might type mount -t ntfs /dev/hde2 /mnt . Once you do so, you can find all of that parti- tion’s contents under the /mnt directory. Table 11-3 Common Filesystem Types Type Description ext2 “Older” Linux filesystem type ext3 “Newer” Linux filesystem type, used by default in Fedora and Red Hat, among others ntfs “Newer” Windows filesystem type, started with Windows NT and commonly used in Windows XP reiserfs Another “newer” Linux filesystem type, used by default in Mandrake and SuSE, among others vfat “Older” Windows filesystem type, such as FAT32 and MS-DOS 6. Browse as you need to. You may find that you have read-only access to your NTFS partition and can’t change anything on it. 7. When you’re finished, type umount /mnt to remove the partition’s contents from your filesystem. The preceding steps work for all distributions, except for Step 4. You just need to find out how your distribution handles NTFS. Navigating the Filesystem in Knoppix Knoppix is another distribution that makes things as easy as possible, with a few little bumps along the way. When your system starts up, it automatically 221 Chapter 11: Checking Out the Linux Filesystem 17_579371 ch11.qxd 12/27/04 8:36 PM Page 221 [...]... Checking Out the Linux Filesystem Formatting Disks A floppy disk, USB keychain, and any other small(ish) storage device often comes as a blank slate or formatted for Windows or Macintosh use (most often these days they come formatted for Windows) If the item is a blank slate, no computer can use it for anything You can actually just use the item in Windows format with no problem, or you can format — change... programs they’re comfortable with no matter what operating system they’re on Table 12-1 Potential Formats for Downloaded Files Extension Meaning Program(s) Involved bz Older form of bz2 bzip, bunzip bz2 Extensive Linux and Unix compressed file bzip2, bunzip2 deb Not a file to “open;” see the “Installing New Software” section, later in this chapter apt gz Typical compressed file for Linux and Unix gzip,... lists the mounted partitions and media in addition to some statistics about them You may, for example, see something like the following: Filesystem /dev/hde2 /dev/hde1 none /dev/hdf3 Size 54G 99M 506M 54G Used Avail Use% Mounted on 27G 24G 54% / 6. 0M 88M 7% /boot 0 506M 0% /dev/shm 39G 13G 76% /mnt/FC1 2 Look for an item with /boot in the right column If you find one, great Proceed to Step 3 Otherwise,... format — change its base setup — for Linux (The handy thing about leaving it as a Windows disk is that you can then use it to share things with Windows users) To format a floppy, place the floppy into your floppy drive and do the following: ߜ Fedora: Choose Applications➪System Tools➪Floppy Formatter ߜ Knoppix: Right-click the floppy icon on the desktop and choose Actions➪Format Floppy Disk ߜ Linspire:... choose Format You may have to click the Floppy item first to open its contents before you can format it Typically, the defaults are what you’ll want to choose If you want to format the disks for Linux, use the Linux Native (ext2) format To share disks with Windows users, choose DOS (FAT) Another setting you may want to choose is Thorough rather than Quick Care and Feeding of Your Filesystem Regardless... first part For example, if you’re archiving the Files folder, then the suggested name might be Files.tar.gz If you wanted to use Files100305.tar.gz for the actual name, you would just add the date into the existing name 6 Click OK The archive is created Updating Your Software In the last couple of years, updating your operating system and software in Linux has become easier and easier Each Linux distribution... that item is for; then click View Advisory to see why the update is available 13 When you’re ready to proceed, click Forward The system makes sure that all dependencies are met, and then the Retrieving Packages dialog box appears Two progress bars, one for individual packages and one for the total set of downloads, show you how much longer you have to go When the downloads are finished, the Forward button... available 14 Click Forward when the download is done The Installing Packages dialog box appears The system now installs all the updates it just grabbed and then offers you the Forward button when you’re done 15 Click Forward when the installation is complete The All Finished dialog box appears 16 Click the Finished button, and you’re done 239 240 Part III: Getting Up to Speed with Linux Sometimes this... you well in return Fortunately, Linux does some of it automatically for you If your machine fails to reboot If your machine didn’t shut down cleanly (a nice euphemism meaning that it either crashed or you shut the power off without properly telling the machine to shut down, as discussed in Chapter 5), the system checks the filesystem if 229 230 Part III: Getting Up to Speed with Linux necessary at... this case, the user created three partitions for Linux The first IDE drive is a single partition, allocated for the root partition The second IDE drive is broken into two partitions The first was given /usr; and the second, /var If you move around the filesystem, you can’t tell (and don’t need to know) which of these directories is on which drive The prompt, for example, doesn’t change based on which . you allocated for Linux during the installation process 17_579371 ch11.qxd 12/27/04 8: 36 PM Page 215 is the majority of your Linux filesystem. Because you’re running your own Linux machine,. with Linux 17_579371 ch11.qxd 12/27/04 8: 36 PM Page 228 Formatting Disks A floppy disk, USB keychain, and any other small(ish) storage device often comes as a blank slate or formatted for Windows. they come formatted for Windows). If the item is a blank slate, no computer can use it for anything. You can actually just use the item in Windows format with no problem, or you can format — change