1 | 2 | page 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11
The following basic commands are essential to examine and manipulate files and directories of a Linux file system.

Use df -h to see which disk device the current directory resides on. The size of the disk and its available free space is shown. In the following example, two partitions on the same disk (sda) and their current usage is shown.

[brucelee@192.168.224.109 ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 108G 43G 61G 42% /
/dev/sda1 99M 17M 77M 19% /boot
tmpfs 505M 0 505M 0% /dev/shm


You can specify a directory or a particular file to see which disk device it resides on as following.

[brucelee@192.168.224.109 ~]$ df -h /tmp
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 108G 43G 61G 42% /

[brucelee@192.168.224.109 ~]$ df -h 66.150.224.245.us.jpg
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 108G 43G 61G 42% /

[brucelee@192.168.224.109 ~]$ df -h /boot
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 99M 17M 77M 19% /boot


To see the disk usage of a file or directory, use du -h. In the following example, the directory img/ uses 376K while the .jpg file uses 28K of storage.

[brucelee@192.168.224.109 ~]$ du -h img/
376K img/

[brucelee@192.168.224.109 ~]$ du -h 66.150.224.245.us.jpg
28K 66.150.224.245.us.jpg




The Linux file security model is quite robust. It assigns access rights to every file and directory within a Linux file system. Every file is owned by a user and a group that this user belongs to. There is also a third category of users, those that are not the user owner and do not belong to the group owning the file, also known as others. For each category of users, read, write and execute permissions can be granted or denied.

The command ls -l displays file permissions for these three user categories. They are represented by nine characters that follow the first character, which is the file type indicator at the beginning of the file properties line. As seen in the examples below, the first three characters in this series of nine display access rights for the user that owns the file. The next three are for the group owner of the file, and the last three for other users. The permissions are always in the same order: read, write, execute for the user, group and others.

[brucelee@192.168.224.109 ~]$ ls -alh
total 600K
drwxrwxrwt 15 brucelee brucelee 8.0K 2008-11-08 20:44 .
drwxr-xr-x 23 root root 4.0K 2008-10-16 09:42 ..
-rw-r--r-- 1 brucelee brucelee 26K 2008-11-08 19:14 66.jpg
drwxrwxr-x 2 brucelee brucelee 4.0K 2008-11-08 13:30 bugs
drwxrwxr-x 2 brucelee brucelee 144K 2008-11-08 19:45 flash
srwxrwxrwx 1 root root 0 2008-10-16 10:20 mysql.sock


In the above example, the file 66.jpg is a regular file denoted by the symbol hyphen (-). It can be read and modified by its owner (rw). A file with read permission but without write permission is equivalent to a file with the read-only attribute. Since this is a picture file, there is no execute permission (rw-). The file can be read but not modified and executed by the group users and other users (r--). bugs is a directory (file type d) and cannot be modified by other users (no write permission). The file mysql.sock is a socket (file type s). Note that both the file 66.jpg and the directory bugs are owned by the user brucelee. The file mysql.sock is owned by root.
1 | 2 | page 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11