Each file on your system is represented by an inode: an inode contains all the information about the file. Each inode is linked into the filesystem by one or more hard links. Hard links contain the name of the file, and the inode number. The inode contains the file itself, i.e., the location of the information being stored on disk, its access permissions, the type of the file, and so on. The system can find any inode once it has the inode number.
A single file can have more than one hard link. What this means is that multiple filenames refer to the same file (that is, they are associated with the same inode number). However, you can't make hard links across filesystems: all hard references to a particular file (inode) must be on the same filesystem. This is because each filesystem has its own set of inodes, and there can be duplicate inode numbers between filesystems.
A symbolic links (also called symlinks) is a special file that “points to” a hard link on any mounted filesystem. When you try to read the contents of a symlink, it gives the contents of the file it's pointing to rather than the contents of the symlink itself. Since directories, devices, and other symlinks are types of files, you can point a symlink at any of those things.
A symlink pairs one filename with a second filename, while a hard link pairs a filename with an inode number.
Some important differences are:
For this reasons, it is usually preferred to use symlinks instead of hard links:
ln -s target_path symbol_path
References:
Each file has 3 security groups:
The command chown changes the owner of a file:
chown user:group file
| number | letters | meaning |
|---|---|---|
| 0 | — | no permission |
| 1 | –x | execution |
| 2 | -w- | writing |
| 3 | -wx | writing and execution |
| 4 | r– | reading |
| 5 | r-x | reading and execution |
| 6 | rw- | reading and writing |
| 7 | rwx | reading, writing and execution |
The command chown changes the permission for a file:
chmod xyz file
Another common needs is just to {add|remove} a {read|write|execute} permission to a file for all the security groups.
chmod {+|-}{r|w|x} file
Historically, when set, it instructed the operating system to retain the text segment of the program in swap space after the process exited. This sped up subsequent executions by allowing the kernel to make a single operation of moving the program from swap to real memory. Thus, frequently-used programs like editors would load noticeably faster. Currently, this behavior is only operative in HP-UX, NetBSD, UnixWare, and Mac OS X.
The most common use of the sticky bit today is on directories. When the sticky bit is set, only the item's owner, the directory's owner, or the superuser can rename or delete files. Without the sticky bit set, any user with write and execute permissions for the directory can rename or delete contained files, regardless of owner. Typically this is set on the /tmp directory to prevent ordinary users from deleting or moving other users' files.
The sticky bit can be set using the chmod command and can be set using its octal mode 1000 or by its symbol t. For example, to add the bit on the directory /usr/local/tmp, one would type chmod +t /usr/local/tmp. Or, to make sure that directory has standard tmp permissions, one could also type chmod 1777 /usr/local/tmp.
| Extraction | |
|---|---|
| type | command |
| tar.gz or tgz | tar xzf archive.tar.gz |
| tar.bz2 | tar xjf archive.tar.bz2 |
| bz2 | bunzip2 archive.bz2 |
| zip | unzip archive.zip |
du -h | tail -n 1
List information about the FILEs in the current directory:
ls
Change the current directory to DIR. The variable $HOME is the default DIR.
cd [DIR]
pwd
TODO: which, whereis, find, slocate
Find files that contain a text string:
grep -nr "text to find" *
TODO: vi, more, less, and most
TODO: cat and echo
TODO: touch and mkdir
TODO: cp and mv
TODO: rm and rmdir
| Directory | Functionalities |
|---|---|
| / | This is the root directory. This is where the whole tree starts. |
| /bin | This directory contains executable programs which are needed in single user mode and to bring the system up or repair it. |
| /boot | Contains static files for the boot loader. This directory only holds the files which are needed during the boot process. |
| /dev | Special or device files, which refer to physical devices. |
| /etc | Contains configuration files which are local to the machine. Some larger software packages, like X11, can have their own subdirectories below /etc. Site-wide configuration files may be placed here or in /usr/etc. Nevertheless, programs should always look for these files in /etc and you may have links for these files to /usr/etc. |
| /home | On machines with home directories for users, these are usually beneath this directory, directly or not. The structure of this directory depends on local administration decisions. |
| /lib | This directory should hold those shared libraries that are necessary to boot the system and to run the commands in the root filesystem. |
| /mnt | Is a mount point for temporarily mounted filesystems |
| /proc | This is a mount point for the proc filesystem, which provides information about running processes and the kernel. |
| /sbin | Like /bin, this directory holds commands needed to boot the system, but which are usually not executed by normal users. |
| /tmp | This directory contains temporary files which may be deleted with no notice, such as by a regular job or at system boot up. |
| /usr | This directory is usually mounted from a separate partition. It should hold only sharable, read-only data, so that it can be mounted by various machines running Linux. |
| /usr/bin | This is the primary directory for executable programs. Most programs executed by normal users which are not needed for booting or for repairing the system and which are not installed locally should be placed in this directory. |
| /usr/include | Include files for the C compiler. |
| /usr/lib | Object libraries |
| /usr/local/include | Include files for the C compiler not installed through a standard Debian dev package |
| /usr/local/lib | Object libraries not installed through a standard Debian dev package |
| /usr/sbin | This directory contains program binaries for system administration which are not essential for the boot process, for mounting /usr, or for system repair. |
| /usr/share | This directory contains subdirectories with specific application data, that can be shared among different architectures of the same OS. Often one finds stuff here that used to live in /usr/doc or /usr/lib or /usr/man. |
| /usr/src | Source files for different parts of the system, included with some packages for reference purposes. Don't work here with your own projects, as files below /usr should be read-only except when installing software |
| /usr/src/linux | This has always been the traditional place where kernel sources were unpacked. This was important on systems that /usr/include/linux was a symlink here. You should probably use another directory for building the kernel now. |
| /var | This directory contains files which may change in size, such as spool and log files. |
| /var/backups | This directory is used to save backup copies of important system files. |
| /var/lock | Lock files are placed in this directory. The naming convention for device lock files is LCK..<device> where <device> is the device's name in the filesystem. The format used is that of HDU UUCP lock files, i.e. lock files contain a PID as a 10-byte ASCII decimal number, followed by a newline character. |
| /var/log | Miscellaneous log files. |
| /var/run | Run-time variable files, like files holding process identifiers (PIDs) and logged user information (utmp). Files in this directory are usually cleared when the system boots. |