2017-10-23linux basic Knowledge (8) FHS file system

Source: Internet
Author: User
Tags aliases


We look back at the knowledge we learned from the previous section, we know how to get help, internally we can use the Assist command, while external commands us to use man or--help and info, and can view the official own documentation (ReadME, CHANGELOG, INSTALL ), there is the release version of the document and Internet search (Google is recommended), then if we want to see that command in the manual in the chapter, using the Whatis command can be.
In the end, let's summarize the basic commands: We'll start with the Linux file system later in this chapter. As well as introducing bash features.

PWD, CD, LS, echo, date, Clock, Cal, Hwclock, Cat, TAC, file, type, TTY, Halt, Poweroff, shutdown, reboot

First, the Linux file system

We all know that the program after the source code is compiled into a binary program to run, if not dependent on the library file, from the system call interface directly write program, we call it static compilation, that is, the program library file is self-contained, but the program will be very large, because it has the library files are compiled into, The advantage is that you can run directly without relying on the library files on the system. Dynamic compilation, however, relies on the library files on the system to be compiled and run, and the advantage is that it takes up less volume. Then Linux Library compilation is the GLIBC tool, we load the program and memory when it is a process, the user to start a program, is to start through the terminal, which is the terminal-related process, and the terminal is a hardware device, it is associated with a user interface, the other is a terminal-independent process, It is started automatically through the Operation boot process. No man-made participation.

1.1 Hierarchy of operating system components

   before we also talked about the components of the operating system, from a static point of view is the kernel and GPL applications for open source protocols / and below is a list of what data and directories must be stored according to the root of the FHS (filesystem hierarchy Standard), which is the unified adoption standard for each vendor and developer. If not unified, but according to the various manufacturers and developers, it is a painful thing for our users. The hierarchy directory for FHS is as follows:

   /bin: Basic Program Files available to all users;    /sbin: Utility programs for system administrators;    /dev: storing Special device files There are two types of devices: Character devices (linear devices), block devices (random devices),    /ETC: System program configuration files, only static text files;    / Home: General home directory of the central location: General user's home directory by default in this directory with the user name subdirectory,/home/username;   /root: Administrator's home directory; optional;    /lib: Provides a shared library for system startup or application (/bin, /sbin) on the root file system, and a kernel-provided module; libc.so.*: dynamically connected C library; ld*: Runtime linker/Loader ; modules: A directory for storing kernel modules, a path for storing 64-bit shared libraries that are unique to the    /lib64:64 bit system,    /media: mount points for portable devices, CDROM,  floppy;    /mnt: Other file system temporary mount points;    /opt: Installation location of additional applications; optional path;    / SRV: The data provided by the current host for the server;    /tmp: A directory for temporary files stored by programs that generate temporary files; All users can be provided with write operations; special permissions;    / usr:usr hierarchy,  read-only data path for global sharing;bin, sbinlib,  Lib64include:c Language program File share: Command man page and the location of files held by the self-contained document frame; Local: Another level directory; Lock:log:run:spool:tmp   /proc: (Kernel output information is implemented through kernel parameters)     memory-based virtual file system for kernel and process storage of its related information; they have multiple kernel parameters such as Net.ipv4.ip_forward, virtual net/ipv4/ip_forward, stored in/proc/sys/, so its full path is/proc/sys/net/ip_forward;   / The SYS:SYSFS virtual file system provides a better way to access the kernel data than proc, and its main role is to manage Linux devices to provide a unified model interface;

Summary: The Linux kernel has the file system function, and this file system is associated with the kernel, the kernel can access any file through this file system, when necessary to let a program start up, access to its own configuration file, and the kernel is no exception, it is a disk path of a file, But when we partition, these partitions can not be arbitrarily separated and accessed, so everything starts from the root, in the directory below the root find an empty directory, associated with other devices, called mounts (roughly FHS).

Ii. types of files on Linux systems

we are using ls -l command when you can view the details and size of the file or directory, then the leftmost first - is the file type on the system, there are several classes, as shown in the following example:

-: Regular files, i.e. F; d:directory, directory files, b:block devices, block device files, support random access by "block", c:character device, character equipment files, support for "charactor" as units in Line linear access; Major number: The main device ID, which identifies the device type, and then determines the driver to be loaded; Minjor number: The secondary device numbers, which are used to represent different devices in the same type; early in 8-bit binary notation: 0-255 l:symbolic link, Symbol device file; p:pipe, command pipe; s:socket, socket file;

2.1 Basic Commands

2.1.1 Alias command

we now know that the type is divided into internal commands and external commands, the internal command is the shell-embedded command, but the shell command itself is external, but in the shell contains many commands, then the command format we have also said, istype COMMANDIf the builtin is displayed in an internal command, the external display will show the path of the command file, but it is important to note that the command can be aliased, and if the alias can be the same as the original name, it will be hidden at this time toCentOSand theDebianFor example, their RM command is different because in CentOS, the RM command is actually an alias and it isrm="rm -i"is to replace the Rm-i command with the RM command, the-i option is deleted before asking, if you do not include this option, it will be deleted directly,DebianThis alias is not the default. So then how do we replace the command with an alias.
Then get the definition of the available aliases we use directlyaliasto view directly:

# Alias

So how do we define the alias format as follows:

# alias Name=command

It is important to note that this type of alias is only valid for the current shell process (exit is divided into two concepts, one is the termination of time, and the other is the concept of scope termination: shell exits; scope terminates: Refers to the current shell).
To revoke an alias:

# Unalias NAME

2.1.2 Whereis Command

The Whereis command is a binary file that finds the path to the command, as well as the location of the manual page, and its command format is:

# Whereis [OPTIONS] name ...

Common options:

-B: Search only the binary program path;-M: Search only the user manual file path;

2.1.3 which command

The which command is to look up binary files in environment variables, but some commands are displayed by default for aliases.

# which [OPTIONS] [--] programname [...]

Our most commonly used options are:

--skip-alias: Skip aliases;

2.1.4 who command

The WHO command is nothing more than a check that the user is logged in and commands are used as follows:

# who [OPTIONS] ...

The options are as follows:

-B: The time of the system startup;-r: Operating level;

2.1.5 W Command

The W command is the information that displays the directory login user.

Iii. Basic features of Bash

3.1 Historical Orders

when we operate a program in the system or configure a service, if there is an error in which step we do not find, we can look at the historical command to see if the command we are using is correct, So the history command is that the shell process holds the command that this user commits in its session, and the command we use is: history . We can also customize the history function, which can be implemented by environment variables:

Histsize:shell the number of command history bars that the process can retain; Histfile: Files that persist command history;. bash_history Histfilesize: The size of the command history file;

Command usage:

# History [-c] [-D offset] [n] or HISTORY-ANRW [filename] or history-ps arg [arg ...]

Common options:

-C: Empty command history;-D Offset: Deletes the specified command history;-R: Reads the command history from the file to the history list;-W: Appends commands from the history list to the historical file; History #: Displays the most recent # command;

We can also invoke the commands in the History list using the following:

!#: Once again execute the # command in the history list;!! : Executes the last command again;! String: Executes the most recent command in the command history list that starts with a string;

It is important to note that repeated executions of commands sometimes need to rely on idempotent. A simple understanding of idempotent is a particularly high number of repetitive commands.
We can also invoke the last parameter of the previous command, using the following:

Shortcut key: ESC,. and ALT,. (in Linux) string:!$

We can also control how the command history is recorded, ignore duplicates or ignore the beginning of whitespace characters and both, and we can use environment variable Histcontrol to change the values as follows:

Ignoredups: Ignores duplicate commands; Igonresoace: Ignores commands that begin with whitespace characters; Ignoreboth: Both of the above are in effect;

And we give the variable, whether it is an environment variable or a normal variable, we need to note that only the current shell is valid, given a modified variable value is as follows:

Name= ' VALUE '

This article from the "Scorpio Blog" blog, reproduced please contact the author!

2017-10-23linux basic Knowledge (8) FHS file system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.