Professional Documents
Culture Documents
Linux File System
Linux File System
Linux File System
With files, you can use less than () signs to direct data to and from files. Here are
the fi le-redirection characters:
■ < — Directs the contents of a file to the command. In most cases, this is the
default action expected by the command and the use of the character is optional;
using
less bigfile is the same as less < bigfile
Ø — Directs the standard output of a command to a fi le. If the fi le exists, the
content of that fi le is overwritten
Ø ■ >> — Directs the output of a command to a fi le, adding the output to the
end of the existing fi le.
Using file-redirection meta characters
●
The following are some examples of command lines where information
is directed to and from fi les:
●
$ mail root < ~/.bashrc
$ man chmod | col -b > /tmp/chmod
●
●
In the fi rst example, the content of the .bashrc fi le in the home
directory is 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 fi le /tmp/chmod (erasing the previous /tmp/chmod fi le, if it exists).
●
The fi nal command results in the following text being added to the
user’s project fi le: I finished the project on Sat Jan 22 13:46:49 PST
2011
Understanding File Permissions and Ownership
●
Permissions associated with fi les and directories in Linux were
designed to keep users from accessing other users’ private fi les and to
protect important system f le
●
The nine bits assigned to each fi le for permissions defi ne the access
that you and others have to your fi le. Permission bits for a regular fi le
appear as -rwxrwxrwx.
Those bits are used to define who can read, write, or execute the fi le.
●
●
Of the nine-bit permissions, the first three bits apply to the owner’s
permission, the next three apply to the group assigned to the fi le, 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 letter, it means that
permission is turned off for that associated read, write, or execute
Understanding File Permissions and Ownership
●
Because files and directories are different types of elements, read, write,
and execute permissions on fi les and directories mean different things.
Read, Write, and Execute Permissions Permission File Directory
●
(i) Read : View what’s in the fi le. See what files and subdirectories it
contains.
(ii) Write: Change the file’s content, rename it, or delete it. Add files or
subdirectories to the directory. Remove fi les or directories from the
directory
(iii)Execute: Run the fi le as a program. Change to the directory as the
current directory, search through the directory, or execute a program from
the directory. Access fi le meta data (fi le size, time stamps, and so on) of
fi les in that director
Understanding File Permissions and Ownership
●
drwxr-xr-x 2 joe 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 fi le 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 permissions
while the group and other users have only read and execute permissions
Directories
●
home—Contains directories assigned to each
regular user with a login account.
●
media—Provides a standard location for
automounting devices
●
lib—Contains shared libraries needed by
applications in /bin and /sbin to boot the system.
Directories
●
misc—A directory sometimes used to automount
filesystems upon request.
●
/opt—Directory structure available to store add-
on application software.
●
proc—Contains information about system
resources.
●
root—Represents the root user’s home directory.
The home directory for root does not reside
beneath /home for security reasons.
Directories
●
sbin—Contains administrative commands and
daemon processes.
●
tmp—Contains temporary files used by
applications.
●
/usr—Contains user documentation, games,
graphical files (X11), libraries (lib),and a variety of
other commands and files that are not needed
during the boot process. The /usr directory is meant
for files that don’t change after installation
●
var—Contains directories of data used by various
applications. In particular, this is where you would
place files that you share as an FTP server (/var/ftp)
or a web server (/var/www). It also contains all
system log files (/var/log) and spool files in /var/spool
(such as mail, cups, and news). The /var directory
contains directories and files that are meant to
change often. On server computers, it is common to
create the /var directory as a separate filesystem,
using a filesystemtype that can be easily expanded.
Comparision between winows and
linux
●
In MS-DOS and ●
In Linux, all storage
Windows filesystems, devices are connected
drive letters represent to the filesystem
different storage devices hierarchy. So the fact
that all of /usr may be
(for example, A: is a on a separate hard disk
floppy drive and C: is a or that /mnt/remote1 is a
hard disk). fi lesystem from another
computer is invisible to
the user.
Comparision between windows and
linux
C:\home\joe
● /home/joe
●
●
Filenames almost Not necessary
●
$ cd doc
●
– /usr/share/doc
●
$ cd
●
$ pwd
– /home/chris
Commands
●
$ cd ~
●
$ pwd
– /home/chris
●
$ cd ~/Music$ pwd
– /home/chris/Music
●
$ cd ../../../usr
●
$ pwd
– /usr
●
TASK
Go to your home directory.
●
●
Create a new directory called test in your home
directory
Check the permissions of the directory
●
$ ls a*
●
– apple
$ ls g*
●
– grape grapefruit
$ ls g*t
●
– Grapefruit
–
Using Metacharacters and
Operators
$ ls *e*
●
– apple
grape grapefruit
watermelon
$ ls *n*
●
– banana watermelon
Using Metacharacters and
Operators
$ ls ????e
●
– apple grape
$ ls g???e*
●
– grape grapefruit
Using Metacharacters and
Operators
$ ls [abw]*
●
$HOME/projects/houses/doors/bifold.txt
●
●
$HOME/projects/outdoors/vegetation/
landscape.txt
Question 3
●
Copy the fi les house1 and house5 to the
$HOME/projects/houses/ directory.
chmod(letters)
●
u->users
●
g->group
●
o->others
●
+->allow permission
●
-->remove permission
●
r->read
●
w->write
●
x->execute
This work is licensed under a Creative Commons
Attribution-ShareAlike 3.0 Unported License.
It makes use of the works of Mateus Machado Luna.