Linux System Study Notes: daily use and management

Source: Internet
Author: User
Tags echo display file diff gz file unix domain socket

Linux System Study Notes: Go back to the Linux system environment for daily use and management. Linux is a multi-user operating system that provides excellent support for user management, simple and efficient file systems, and a large number of practical tools to meet the needs of daily work. This article summarizes common Linux commands, user features, and file systems. Commonly used command tools in Linux are abundant, and the number of tools is continuously increasing. Linux's most common Commands include: man view man manual page info view Texinfo document ls display file name or file list, and file-related property information rm delete file cp copy file mv move file, rename lpq lpr lprm print file cat to display text file content, it can be used to splice a file less more split display file head tail display file header and tail sort sorting file content uniq ignore duplicate lines in the file diff compare two files do not open the file, view File Information grep search string echo display text date display date and Time script record session information unix2dos dos2unix Linux text file and Windows text file conversion tar file archive and archive gzip gunzip zcat. gz File compression, decompression and viewing bzip2 bunzip2 bzcat. bz2 File compression, decompression and view which where Is to search for the complete path of commands and so on. apropos whatis searches for keywords in man, briefly describe the complete path of the locate search file. who w {who am I} displays the information of the logged-on user. hostname displays the host name. For most commands, you can use the-h or -- help options to view the help information. information. More detailed help documents are organized on the man manual page. The manual page is generally divided into nine sections: user-level commands and applications. System Call and kernel error code. Library call. Device Drivers and network protocols. Standard file format. Games and demos. Various files and documents. System Management commands. Secret kernel specifications and interfaces are rare. You can use the manpath command to view man's Search Path. You can set the MANPATH environment variable to overwrite the default path, or you can set it in/etc/manpath. config. The manual page is generally compressed in. gz format. $ Manpath/usr/local/man:/usr/local/share/man:/usr/share/manman use the less command to display the manual page, which can be modified by setting the PAGER environment variable. Use the man [sec] name command to obtain the manual page, or use the-k option to search by keyword. Another help document is the Texinfo document, which can be viewed using the info command. The ls and other commands used for path operations are the most common commands. They are used to manage paths such as files and directories. They will be described in detail later in the summary file system. Commands for file operations are generally used for text files. For example, create a file a.txt: $ cat> a.txt # redirect the standard input to the file MondayTuesdayWednesdayThursdayFridaySaturdaySunday ^ C $ cat B .txt # display the file content MondayTuesdayTuesdayThursdayFridaySaturdaySunday $ head-3 a.txt # view the first three lines of MondayTuesdayWednesday $ tail-f a.txt # View files with increasing content, mostly used to view logs ^ C $ sort a.txt # sort FridayMondaySaturdaySundayThursdayTuesdayWednesday $ uniq B .txt # Remove duplicate rows MondayTuesdayThur SdayFridaySaturdaySunday $ diff-u a.txt B .txt # Compare files,-u display different --- a.txt 15:34:00. 340179508 + 0800 ++ B .txt 15:41:12. 404569605 + 0800 @-+ @ Monday Tuesday-Wednesday + Tuesday Thursday Friday Saturday $ file a.txt # contains file information a.txt: ASCII text $ grep-in -- color sat *. txt # search for the serial number.-I is not partitioned into small ones.-ndisplays the line number a.txt: 6: Saturdayb.txt: 6: Saturdaygrep. You can use the-H command to always display the file name for a single file and use-r for recursive search of directories. Several utility tools include several common commands such as echo and date to complete some daily operations. $ Date -- rfc-3339 = s # = date will only show the date 2012-03-08 15:59:57 + compression archive there are many compression tools in Linux, the most commonly used is gzip and bzip2. Generally, files or directories are archived and compressed using tar. They can also be used independently. $ Tar czf unzip tar.gz a.txt B .txt $ tar xzf unzip tar.gz $ tar cjf unzip tar.bz2 a.txt B .txt $ tar xjf unzip tar.bz2 generally names the packages archived through tar and then compressed directly. tar. different from the compressed one. gz and. bz2 file. To determine whether a command exists, you can use the which command to check whether it is in the search path. However, the command On Debian does not show that the user has no execution permission, in this case, whereis can be used to search for a larger range. You can also use locate to search for all types of files in the entire file system. The locate database is usually regularly generated by the updatedb command. $ Which ifconfig # not found, insufficient permissions $ whereis ifconfigifconfig: /sbin/ifconfig/usr/share/man/man8/ifconfig.8.gz $ locate ifconfig/sbin/ifconfig/usr/share/man/de/man8/ifconfig.8.gz/usr/share/man/ fr/man8/ifconfig.8.gz/usr/share/man/man8/ifconfig.8.gz/usr/share/man/pt_BR/man8/ifconfig.8.gz view User Information w and who can view User information in detail and in brief to view user information, who am I: view the identity of the currently logged on user. $ W 16:13:50 up 3: 34, 3 users, load average: 0.00, 0.00, 0.00 user tty from login @ idle jcpu pcpu WHATyeolar pts/0 yeolar-pc.local 1.04 s 1.04 s-bashyeolar pts/1 yeolar-pc.local 0.00 s 0.36 s 0.00 s wyeolar pts/2 yeolar-pc.local 8.00 s 0.38 s 0.08 s sshd: yeolar [priv] $ whoyeolar pts/0 2012-03-08 (yeolar-pc.local) yeolar pts/1 2012-03-08 (yeolar-pc.local) yeolar pts/2 2012 -03-08 (yeolar-pc.local) $ who am iyeolar pts/1 2012-03-08 (yeolar-pc.local) each file and process on your Linux system belongs to a specific user account. Other users cannot access these objects without the permission of the owner. System files and processes belong to root virtual users, also known as Super Users. Linux is a multi-user system. The Division of users and permissions ensures the security of multiple users in Linux. Each file has a owner and a group. The owner of a file specifies the operations that a group member can perform on the file so that some members can share the file. Linux uses numbers to determine the owner and group. The User ID (UID) is mapped to the user name in the/etc/passwd file, and the group ID (GID) is mapped to the group name in the/etc/group file. The text name corresponding to UID and GID is used for your convenience. The owner of a process can send signals to the process or reduce the priority of the process. A process has seven associated IDs, including three UIDs (Real, valid, and saved), three gids (Real, valid, and saved), and one file system UID. The UID of the root account of a Super User is 0. The super user is allowed to perform proper operations on any file or process. Some system calls can only be performed by the Super User. To ensure security, the password of the root account must be at least 8 characters long. In order to perform some system-level operations, it is often necessary to become a root user. It is not good to log on directly with the root account, and the cause of insecurity is increased, in addition, it is impossible to tell who has performed what operations. There are two ways to switch from a common user to a root user. One is to use the su command, and the other is to use the sudo command. The su command without parameters is switched to the root account. Adding the user name as the parameter will switch to the user account. If used, the path will be switched to the user's home directory. Sudo uses the command to be executed as the parameter and runs as root (or another user. In the configuration file/etc/sudoers, set the user authorized to use sudo and the commands allowed to be executed, and use the mongodo command to modify/etc/sudoers. Sudo has a configurable timeout value. Sudo stores a log and saves commands, hosts, users, directories, and time related to command execution. The pseudo-user system also defines several pseudo-users. Generally, they use * to replace their password fields in/etc/passwd, so that they cannot be used for logon. Common examples include bin, daemon, and nobody ). The/etc/passwd file is a list of users that can be identified by the system. During logon, the system queries the file to determine the user's UID and verify the password. Each row is a user with the following fields: user name. Encrypted password or placeholder x. Numeric User ID. Value group ID. User information: full name, office, extension number, residential phone number. Initial working directory. Log on to the shell. The encrypted password is usually stored in the/etc/shadow file, which is called a hidden password system. When this mechanism is used, the password field in/etc/passwd writes x. You can run vipw to edit the file. You can use the pwconv command to make the contents of the shadow file consistent with those of the passwd file. The/etc/group file/etc/group contains the group name and a list of members in each group. Each row is a group with the following fields: group name. Encrypted password or x, which indicates a/etc/gshadow file. Value group ID. List of members separated by commas. The group password is rarely used. Generally, it is set *. Account Management allows you to create and delete users manually. Generally, for convenience, you can use the useradd command to create users. usermod and userdel can be used to modify and delete users. You can use usermod-L user and usermod-U user to lock and unlock the user and prohibit user logon. The passwd command can be used to modify the user's password. Logon account records Linux users logging on to the system in the/var/run/utmp file, and records logon and logout events in the/var/log/wtmp file. The who and last commands read and print records respectively. Common file system types include EXT2, EXT3, and EXT4. Linux also supports the FAT and NTFS types in Windows. There are also some widely used JFS types such as IBM. The/etc/fstab file contains a list of devices corresponding to the file system. Df command to view the file system size. $ Df-h/Filesystem Size Used Avail Use % Mounted on/dev/sda3 78G 3.7G 71G 5%/Use the mount and umount commands to install and uninstall the file system, such: # mount/dev/hda5/users install the file system in/dev/hda5 on the disk partition to the path/users. You can add the new file system to the/etc/fstab file for automatic installation. During the uninstallation, if the kernel indicates that the device is busy, run fuser-mv mpoint to view the processes that are using resources on the file system. Fuser-v file can be used to view specific files. The-k option can be used to kill all troublesome processes. A more powerful alternative is lsof. The fsck command can be used to check and fix file systems. It can be used to fix errors in files and data blocks. In Linux, different files are put in some paths according to the Conventions. Generally, the installer assumes the file location, therefore, the default file tree structure should be maintained as much as possible. /Bin minimum system command/boot kernel and file/dev terminal, disk, and other device items required for Kernel loading/etc key startup files and configuration files/home user's home directory/ library of the lib C compiler and Installation Point of some file systems on the C compiler/media removable media/optional application software package of opt/image of all running processes of proc/root Super User main directory/sbin command for guiding, repairing, or restoring the system/tmp temporary space (delete upon restart) /usr secondary file and command hierarchy/usr/bin most commands and executable files/usr/include compile C program header file/usr/lib Library/usr/local software (written or installed by the user) /usr/local/bin local Executable File/usr/local/etc local system configuration file and command/usr/local/lib local library/usr/local/sbin static Link local system maintenance command/usr/local/sr C/usr/local/* Source Code/usr/man online user manual/usr/sbin secondary system management commands and repair commands/usr/share what is common to multiple systems/usr/ share/man online user manual/usr/src Source Code of non-local software package/var system dedicated data and configuration file/var/log system log file/var/spool offline directory (printers, emails, etc. use) /var/tmp temporary space (retained upon restart) there are 7 file types in Linux: common files, directories, character device files, block device files, sockets, named pipelines, and symbolic links. How to delete symbols in file type ls common file-editor, cp, and other rm directories d mkdir rmdir, rm-r character device file c mknod rm block Device File B mknod rm socket s socket (2) the rm named pipeline p mknod rm symbolic link l ln-s rm common file is a data packet, and Linux does not specify any structure for it. The directory contains references to other files by name. And... represent the directory itself and its parent directory. The file name is stored in its parent directory, rather than in the file itself. Multiple directories can reference a file at the same time and have different names. This type of reference is called a hard link, which is created using the ln command. Linux maintains the Count of links pointing to each file. Hard links cannot be used across file systems. Device Files enable the program to communicate with the system's hardware and peripheral devices. Character device files allow drivers to buffer their input and output. Block device files are used by drivers that process block data I/O, and the kernel caches them. The device file uses two numbers to indicate its features, namely, the primary device number and the secondary device number. The primary device number corresponds to the driver and the secondary device number corresponds to the addressing physical unit. A socket is a method of inter-process communication. The local socket can only be accessed from the local device. It is used by a file system object, also known as a UNIX domain socket. The named pipe is used for inter-process communication on the same host. A symbolic link is also called a soft link. A Symbolic Link is referenced by a file name instead of a hard link. When the kernel finds the path and encounters a symbolic link, It redirects to the path name of The Link storage. File Attributes in a Linux file system, each file has a 16-bit word storage attribute information, including 12-Bit mode bit and 4-bit file type information, the Mode bit is divided into nine permission bits that control the user's read and write permissions and three permission bits related to the executable program. The nine permission bits are divided into three groups, respectively setting the read, write, and execute permissions for users, groups, and others. The other three permission bits are setuid, setgid, and sticky. The number of octal operators is often used to indicate the permission bit. Value permission bit value permission bit 4000 setuid 400 user read permission 40 Group read permission 4 Other Read Permission 2000 setgid 200 User Write Permission 20 group write permission 2 Other Write Permission 1000 sticky bits 100 user execution permissions 10 groups execution permissions 1 Other execution permissions set the setuid and setgid bits for executable files so that the program can access files and processes that the user of the executable program has no permission to access. Set the setgid bit for the directory so that the newly created files in the Directory have the directory group permission, rather than the group of the users who created the files. After the directory is set to sticky, it must be the directory user, file user, or Super User to delete or rename the files in the directory. In the ls-l command, r, w, and x are used to indicate read, write, and execute permissions respectively, setuid, setgid, and sticky bit are represented by S, S, and T at the user, group, and other execution permission limits respectively, and corresponding executable permissions are set in lower case. Other items output by the ls-l command include the number of hard links, users, groups, size, modification date, and path. Use the chmod command to modify permissions and the chown command to change users and groups. $ Chmod 755 dir $ chmod-R u + w dir $ chmod ug = srx, o = file $ chown-R yeolar: yeolar dir hard disk knowledge about hard disks is not described here, you can refer to some reference books. Currently, common hard disk interfaces include PATA (IDE), SATA, and SCSI. SATA is the subsequent Technology of IDE. In Linux systems, the names of SCSI hard disks in the form of sdxn are generally used, and x is a B c... represents different hard disks, and n represents different partitions. The name in the hdxn format represents the IDE and SATA hard disks. The meanings of x and n are the same as those of SCSI hard disks. Use the fdisk command for hard disk partitions. Use commands such as mke2fs and mkswap to create a file system and swap a partition. Use the swapon command to enable swap a partition. Linux hard disk management has two important tools: RAID and LVM. The Linux Kernel provides support for creating soft RAID. Generally, the mdadm command is used. LVM is an optional subsystem. It can be used to group multiple hard disks into a volume group, allocate them as logical volumes, and dynamically change the size of logical volumes. The USB device lsusb command lists the USB devices found in the kernel. The device file used by the kernel indicates that the detected device can view the system log/var/log/kern. log.

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.