Debian GNU/Linux: Guide to Installation and Usage by John Goerzen and Ossama Othman (best fiction books of all time TXT) π
You may wonder why would people spend hours of their own time writingsoftware and carefully packaging it, only to give it all away. The answersare as varied as the people who contribute.
Many believe in sharing information and having the freedom to c
Read free book Β«Debian GNU/Linux: Guide to Installation and Usage by John Goerzen and Ossama Othman (best fiction books of all time TXT) πΒ» - read online or download for free at americanlibrarybooks.com
- Author: John Goerzen and Ossama Othman
- Performer: -
Read book online Β«Debian GNU/Linux: Guide to Installation and Usage by John Goerzen and Ossama Othman (best fiction books of all time TXT) πΒ». Author - John Goerzen and Ossama Othman
tac usrdoc/copyright/GPL | tr G Q | less You could get the same effect using temporary files and redirection, for example:
tac usrdoc/copyright/GPL > tmpfile tr G Q < tmpfile > tmpfile2
less < tmpfile2
rm tmpfile tmpfile2
Clearly a pipeline is more convenient.
Filename Expansion Often you want a command to work with a group of files. Wildcards are used to create a filename expansion pattern: a series of characters and wildcards that expands to a list of filenames. For example, the pattern etc* expands to a list of all6.2 the files in /etc.
is a wildcard that can stand for any series of characters, so the pattern etc will expand to a list of all the filenames beginning with etc.
This filename list is most useful as a set of arguments for a command. For example, the /etc directory contains a series of subdirectories called rc0.d, rc1.d, etc. Normally to view the contents of these, you would type the following:
ls etcrc0.d etcrc1.d etcrc2.d etcrc3.d ls etcrc4.d etcrc5.d etcrc6.d etcrcS.d This is tedious. Instead, you can use the ? wildcard as shown here: ls etcrc?.d
etcrc?.d expands to a list of filenames that begin with rc, followed by any single character, followed by .d.
Available wildcards include the following: *
Matches any group of 0 or more characters.
?
Matches exactly one character.
[β¦]
If you enclose some characters in brackets, the result is a wildcard that matches those characters. For example, [abc] matches either a, or b, or c. If you add a ^ after the first bracket, the sense is reversed; so [^abc] matches any character that is not a, b, or c. You can include a range, such as [a-j], which matches anything between a and j. The match is case sensitive, so to allow any letter, you must use [a-zA-Z].
Expansion patterns are simple once you see some concrete examples: *.txt
This will give you a list of all filenames that end in .txt, since the * matches anything at all.
*.[hc]
This gives a list of filenames that end in either .h or .c.
a??
This gives you all three-letter filenames that begin with a.
[^a]??
This gives you all three-letter filenames that do not begin with a.
a*
This gives you every filename that starts with a, regardless of how many letters it has.
More on Files In section 5.2 on page [*], we covered moving and renaming files with mv, copying them with cp, removing them with rm, removing directories with rmdir, and creating directories with mkdir. This chapter will cover some more aspects of working with files.
Permissions GNU and Unix systems are set up to allow many people to use the same computer, while keeping certain files private or keeping certain people from modifying certain files. You can verify this for yourself. Log in as yourself, i.e. NOT as root.
whoami
This verifies that you are not root. Then enter the following command: rm etcresolv.conf
You should be told Permission denied. etcresolv.conf is an essential system configuration file; you arenβt allowed to change or remove it unless youβre root. This keeps you from accidentally messing up the system, and if the computer is a public one (such as at an office or school), it keeps users from messing up the system on purpose.
Now type ls -l etcresolv.conf.
This will give you output that looks something like this: -rw-r-r-1 root root 119 Feb 23 1997 etcresolv.conf The -l option to ls requests all that additional information. The info on the right is easy: The size of the file is 119 bytes; the date the file was last changed is February 23, 1997; and the fileβs name is etcresolv.conf. On the left side of the screen, things are a little more complicated.
First, the brief, technical explanation: The -rw-r-r-is the mode of the file, the 1 is the number of hard links to this file (or the number of files in a directory), and the two roots are the user and group owning the file, respectively.
So that was cryptic. Letβs go through it slowly.
File Ownership
Every file has two owners: a user and a group. The above case is a little confusing because thereβs a group called root in addition to the root user. Groups are just collections of users who are collectively permitted access to some part of the system. A good example is a games group. Just to be mean, you might create a group called games on your computer and then set up your system so that only people in a games group are allowed to play games.
Hereβs a more practical example. Consider a case in which youβre setting up a computer for a school. You might want certain files to be accessible only to teachers, not students, so you put all the teachers in a single group. Then you can tell the system that certain files belong to members of the group teachers, and that no one else can access those files.
Letβs explore groups on the system. First, you can use the groups command at the shell prompt. This will show you a list of the groups to which you belong. Hereβs an example:
$ groups
system-wide configuration!permissions!file ownershipusername dialout cdrom floppy audio Itβs likely that youβre a member of only one group, which is identical to your username. However, root can add you to other groups. The above example shows a person that is a member of five groups.
less etcgroup
This file lists the groups that exist on your system. Notice the root group (the only member of this group is the root user), and the group that corresponds to your username. There are also groups like dialout (users who are allowed to dial out on the modem) and floppy (users who can use the floppy drive). However, your system is probably not configured to make use of these groups. Itβs likely that only root can use the floppy or the modem right now. For details about this file, try reading man group.
ls -l /home
This command shows you that every userβs directory is owned by that user and that userβs personal group.
Tip: If you just installed Debian, you may be the only user. You can use the adduser command to add more users to the system.
Mode
In addition to being owned by one user and one group, every file and directory also has a mode, which determines whoβs allowed to read, write, and execute the file (and run it, if itβs a program). There are a few other things also determined by the mode, but theyβre advanced topics so weβll skip them for now.
The mode looks like this in the ls output: -rw-r-r-. For now, weβll consider nine of these parts: those that control read, write, and execute permissions for the user owning the file, the group owning the file, and others (everyone on the system, sometimes called world).
In the mode line, the first βelementβ gives the file type. The - in this case means itβs a regular file. If it was d, weβd be looking at a directory. There are also other possibilities too complex to go into here; for details, see section 13.2.2 on page [*].
The remaining nine elements are used to display the fileβs mode. The basic 9 bits (read, write, and execute for user, group, and other) are displayed as three blocks of rwx.
So if all permissions are turned on and this is a regular file, the mode will look like this: -rwxrwxrwx. If it was a directory with all permissions turned off for others and full permissions for user and group, it would be drwxrwxβ.
Table 7.1: Permissions in Linux +ββββββββββββββββββββββββββ+
| Code | Name | Allows for Files | Allows for Directories |
|ββ+βββ+βββββββββ+βββββββββββ-|
| r | read | Examine contents of file | List contents of directory |
|ββ+βββ+βββββββββ+βββββββββββ-|
| w | write | Modify file | Add or remove files in directory |
|ββ+βββ+βββββββββ+βββββββββββ-|
| x | execute | Run as a command | Access files in directory |
+ββββββββββββββββββββββββββ+
Table 7.1 describes the meaning of the read, write, and execute permissions for both files and directories.
Directory modes can be a little confusing, so here are some examples of the effects of various combinations:
rThe user, group, or other with these permissions may list the contents of the directory, but can do nothing else. The files in the directory canβt be read, changed, deleted, or manipulated in any way. The only permitted action is reading the directory itself, that is, seeing what files it contains.
rwβ
Write permission has no effect in the absence of execute permission, so this mode behaves just like the above mode.
r-x
This mode permits the files in a directory to be listed and permits access to those files. However, files canβt be created or deleted. Access means that you can view, change, or execute the files as permitted by the filesβ
own permissions.
-x
Files in this directory can be accessed, but the contents of the directory canβt be listed, so you have to know what filename youβre looking for in advance (unless youβre exceptionally good at guessing). Files canβt be created or deleted.
rwx
You can do anything you want with the files in this directory, as long as itβs permitted by the permissions on the files themselves.
Directory write permission determines whether you can delete files in a directory. A read-only file can be deleted if you have permission to write to the directory containing it. You canβt delete a file from a read-only directory even if youβre allowed to make changes to the file.
This also means that if you own a directory you can always delete files from it, even if those files belong to root.
Directory execute permission determines whether you have access to files -
and thus whether file permissions come into play. If you have execute permissions to a directory, file permissions for that directory become relevant. Otherwise, file permissions just donβt matter; you canβt access the files anyway.
Permissions in Practice
This section goes through a short example session to demonstrate how permissions are used. To change permissions, weβll use the chmod command.
cd; touch myfile
There are a couple of new tricks here. First, you can use ; to put two commands on one line. You can type the above as: $ cd
$ touch myfile
or as:
$ cd; touch myfile
Either way the same thing will end up happening.
Recall that cd by itself returns you to your home directory. touch is normally used to change the modification time of the file to the current time. But it has another interesting feature: If the file doesnβt exist, touch creates the file. So youβre using it to create a file to practice with. Use ls -l to confirm that the file has been created and notice the permissions mode:
$ ls -l
-rw-r-r-1 user user 0 Nov 18 22:04 myfile Obviously the time and user/group names will be different when you try it.
The size of the file is 0, because touch creates an empty file. -rw-r-r-is the default permissions mode on Debian.
chmod u+x myfile
This command means to add (+) execute (x) permissions for the user (u) who owns the file. Use ls -l to see the
Comments (0)