Linux file system, System Management class commands, bash basic features

Source: Internet
Author: User
Tags syslog temporary file storage touch command

File systems for Linux
Root file System (ROOTFS) root Fileysystem

LSB,FHS (Filesystem heirache Standard) file system hierarchy criteria such as:/etc,/usr,/var,/root,/home,/dev/boot: Boot file directory, kernel file (vmlinuz), Boot loader (bootloader,grub) is stored in this directory,/bin: Basic command for all users, cannot be associated to a separate partition, OS startup is the program that will be used,/sbin: The basic command of the management class, can not be associated to a separate partition, OS startup is the program used LIB: Basic shared library file, and kernel module file (/lib/moudules);/lib64: Dedicated to the secondary shared library file on x86_64 system;/etc: Configuration file directory (plain text file);/home/username: Normal User home directory/ Root: Administrator's home directory;/media: Portable mobile device mount point, (CDROM, USB)/MNT: Temporary file system mount point;/dev: Device files and special file storage location; b:block device random access devices C:character Devi    Ce linear access Device/OPT: The installation location of a third-party application;/SRV: Data used by services running on the system;/tmp: Temporary file storage location/usr:universal shared,read-only data Bin: An application that guarantees the full functionality of the system; the header file of the SBIN:LIB:LIB64:INCLUDE:C program (header files); Share: structured independent data such as Man,doc Loca     L: Installation location of third-party applications; bin, Sbin, Lib, lib64, etc, share/var:variable data files, cache: application cache data directory; LIB: application state information data; Local: Dedicated to storing mutable data for applications under/usr/local; Lock: Lock file log: Logging directory and file opt: dedicated to storing variable data for applications under/OPT; run: Data in the running process; PID File spool: Application Data Pool tmp: Save the temporary data generated between the system two reboots/proc: used to output kernel and process information related to the virtual file system;/sys: Used to output hardware on the current systemDevice-related information about the virtual file system/selinux:security Enhanced Linux,selinux related security policy and other information storage location 

Components of an application on Linux:
Binaries:/bin,/sbin,/usr/bin,/usr/sbin,/usr/local/bin,/usr/local/sbin
Library files:/lib,/lib64,/usr/lib,/usr/lib64,/usr/local/lib,/usr/loacl/lib64
Configuration files:/etc,/etc/directory,/usr/local/etc
Help files:/usr/share/man,/usr/share/doc,/usr/local/share/man,/usr/loacl/share/doc

File types for Linux
-(f): ordinary documents;
D: Catalog file
B: Block device
C: Character device
L: Symbolic link file, only means soft link;
P: Pipeline File
S: Socket file, socket;

System Management Class Commands:
Shutdown or restart
Halt, Poweroff shut down the machine
Reboot restart

选项:-f:强制,不调用shutdown;-p:切断电源shutdownshutdown [option]... time [message]选项:-r:reboot 重启;-h:halt 关机 ;-c:cancel 取消关机或重启time时间表示法:now:立刻,0亦可表示现在+m:相对时间表示法,从命令提交开始多久之后,例如:+3;hh:mm:绝对时间表示法,指明具体时间,24小时制;用户登录信息查看命令:whoami:显示当前登录有效用户[[email protected] ~]# whoamirootwho:系统当前所有的登录会话:[[email protected] ~]# whoroot     pts/1        2018-03-21 11:25 (192.168.152.1)root     pts/2        2018-03-21 14:15 (192.168.152.1)w:系统当前所有的登录会话及所做的操作[[email protected] ~]# w 14:18:12 up  2:57,  2 users,  load average: 0.00, 0.00, 0.00USER     TTY      FROM              [email protected]   IDLE   JCPU   PCPU WHATroot     pts/1    192.168.152.1    11:25    2:53m  0.02s  0.02s -bashroot     pts/2    192.168.152.1    14:15    0.00s  0.01s  0.00s w

The basic features of bash:
(1) Command history
History
Environment variables:
Histsize: The number of records in the command history;
[Email protected] ~]# echo $HISTSIZE
1000

Histfile: Command History file
[Email protected] ~]# echo $HISTFILE
/root/.bash_history

Histfilesize: The number of history records in a command history file
[Email protected] ~]# echo $HISTFILESIZE
1000

history-d #: Delete command history in the # command
[Email protected] ~]# history
1 history
2 ls
3 CD
4 history
[Email protected] ~]# history-d 2
[Email protected] ~]# history
1 history
2 CD
3 History
4 history-d 2
5 history

History-c: Emptying the command history;
History #: Show the most recent # command
[Email protected] ~]# history
1 history
2 ls
3 CD
4 history
[[Email protected] ~]# history 2
4 history
5 History 2

History-a: Manually append the current session buffer's command history to the command history file;

To invoke a command in history:
! #: Repeat section # command
[Email protected] ~]# history
1 history
2 ls
3 CD
4 history
[Email protected] ~]#!2
Ls
Anaconda-ks.cfg Desktop Install.log Install.log.syslog scsrun.log

!! : Executes the previous command repeatedly
[Email protected] ~]# history
1 history
[[email protected] ~]#!!
History
1 history
2 history

! String: Repeatedly executes a command that begins with a string
[Email protected] ~]# history
1 history
2 ls
3 CD
4 history
[Email protected] ~]#!l
Ls
Anaconda-ks.cfg Desktop Install.log Install.log.syslog scsrun.log

Call the last parameter of the previous command:
! $
Esc.
ALT +.

Control how the Command history is recorded:
Environment variable: Histcontrol
Ignoredups ignores repeated commands, successive and identical parties are duplicates;
Ignorespace: Ignores all commands that begin with whitespace;
Ignoreboth: Compatible with both of these features

(2) Command completion
Bash execution command: Bash searches for a file named after the given command name from the left and right, based on the path defined by the PATH environment variable, the command to be executed the first time it is found;
Direct completion: Tab, the user given a string with only a single corresponding command;
The command that starts with the string given by the user is not unique, then the tab is given a list;

(3) Path completion
Takes the user-given string as the beginning of the path and searches for the file name at the beginning of the specified string, under its specified ancestor directory
If unique, the direct complement
Otherwise, tab again, give the list;

(4) Command line expansion
~: Expand to the user's home directory
~username: Expand the home directory for the specified user
{}: Can host a comma-delimited list and expand it to multiple paths
Examples are as follows:
/tmp/{a,b}=/tmp/a,/tmp/b
/tmp/{tom,jerry}/hi=/tmp/tom/hi,/tmp/jerry/hi

(5) Execution status result of the command
Success or failure

bash使用特殊变量$?保存最近一条命令的执行状态结果0:成功1-255:失败[[email protected] ~]# cat /etc/issueRed Hat Enterprise Linux Server release 5.7 (Tikanga)Kernel \r on an \m[[email protected] ~]# echo $?0[[email protected] ~]# catt /etc/issue-bash: catt: command not found[[email protected] ~]# echo $?127[[email protected] ~]# cat /etc/issueecat: /etc/issuee: No such file or directory[[email protected] ~]# echo $?1程序执行有两类结果:程序的返回值;程序的执行状态结果;

Directory Management class Commands:
Cd,pwd,ls

Mkdir,rmdirmkdir [Options]/path/to/somewhere-p: No error when present, and can automatically create the required directories, recursively created by hierarchy [[email protected] tmp]# ls-ltotal 16drwx------2 root root 4096 Mar 19:49 gconfd-rootsrwxr-xr-x 1 root root 0 Mar 19:04 mapping-root-rw-r--r--1 ro OT root 1580 Mar 22:01 passwddrwxr-xr-x 2 root root 4096 Mar 14:57 tom[[email protected] tmp]# mkdir-p tom[[em Ail protected] tmp]# mkdir-p x/y/z[[email protected] tmp]# tree xx '--y '--z-v: Show details [[Email prote CTED] tmp]# mkdir-v marymkdir:created directory ' Mary '-M MODE: Specify permissions directly when creating a directory [[email protected] tmp]# mkdir-m 755 abc[ [email protected] tmp]# ls-dl abcdrwxr-xr-x 2 root root 4096 Mar 15:02 abctree: View the hierarchical structure of a directory-D: Show only directories, files are not displayed [[            Email protected] tmp]# tree-d/tmp/tmp |--ABC |--gconfd-root |--Mary |--Tom '--X    '--y '--z-l level: Specifies the number of levels displayed [[email protected] tmp]# tree-l 2/tmp/tmp |--ABC |--gconfd-root |--MappinG-root |--Mary |--passwd |--Tom '--X '--y-p pattern: Shows only the path with the specified pattern match rmdir: delete empty directory Rmdi    R [option] ... directory ...-V: Show details [[email protected] tmp]# rmdir-v Mary rmdir:removing directory, Mary -P: Recursive Delete empty directory exercise: 1, how to create/tmp/x/y1,/tmp/x/y2,/tmp/x/y1/a,/tmp/x/y1/b,/tmp/x/y2/a,/tmp/x/y2/b[[email protected] ~ ]# mkdir-pv/tmp/x/{y1,y2}/{a,b}mkdir:created directory '/tmp/x ' mkdir:created directory '/tmp/x/y1 ' mkdir:created dire Ctory '/tmp/x/y1/a ' mkdir:created directory '/tmp/x/y1/b ' mkdir:created directory '/tmp/x/y2 ' mkdir:created directory '/ tmp/x/y2/a ' mkdir:created directory '/tmp/x/y2/b ' 2, how to create X_m, Y_m, X_n, y_n[[email protected] ~]# mkdir-v/tmp/{x,y} _{m,n}mkdir:created directory '/tmp/x_m ' mkdir:created directory '/tmp/x_n ' mkdir:created directory '/tmp/y_m ' mkdir: Created directory '/tmp/y_n ' 3, how to create/tmp/bin,/tmp/sbin,/tmp/usr,/tmp/usr/bin,/tmp/usr/sbin[[email protected] ~ ]# Mkdir-pv/tmp/{bin,sbin,usr/{bin,sbin}}mkdir:created directory '/tmp/bin ' mkdir:created directory '/tmp/sbin ' mkdir:created directory '/tmp/usr ' mkdir:created directory '/tmp/usr/bin ' mkdir:created directory '/tmp/usr/sbin ' text File View class commands: Cat, TAC more, less, tail, head more and more [option ...]        [File ...] -D: Show page turn and exit prompt +#: Locate on line # starts to show less than less [option ...]    [File ...] Head head [option ...]        [File ...] -C #: Specify get before # bytes [[[email protected] ~]# head-c 5/tmp/passwd Root:-N #: Specify get before # line [[Email&nbs        P;protected] ~]# head-n 3/tmp/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin        Daemon:x:2:2:daemon:/sbin:/sbin/nologin-#: Specify get before # line [[[email protected] ~]# head-3/tmp/passwd        Root:x:0:0:root:/root:/bin/bash Bin:x:1:1:bin:/bin:/sbin/nologin Daemon:x:2:2:daemon:/sbin:/sbin/nologin Tail tail [option ...]            [File ...] -C #: Specify get # bytes [[email protected] ~]# tail-c 5/tmp/passwd           Tom.            -N #: Specifies to get the previous # line [[[email protected] ~]# tail-n 3/tmp/passwd I am Tom.            I am Tom.        I am Tom.        -#: Specify get before # line [[email protected] ~]# tail-3/tmp/passwd I am Tom.        I am Tom.        I am Tom. -F: Keep track of new additions to the file; Timestamp management tool touch file: Metadata metadata, Data View file status: Stat [[Email protec Ted] ~]# stat/tmp/passwd File: '/tmp/passwd ' size:1580 blocks:8 IO Bloc   k:4096 regular file device:fd00h/64768d inode:1336933 links:1 Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) access:2018-03-21 15:35:58.000000000 +0800 Modify: 2018-03-20 22:01:10.000000000 +0800 change:2018-03-20 21:58:31.000000000 + 8,003 timestamps: AC Cess time: Access times, Atime read file contents Modify time: Modified, mtime change file contents changetime: Change Time, CTime metadata changed touch command: touch [option ...]            [File ...]  -a:only atime-m:only mtime-t specific time [[CC]YY]MMDDHHMM.SS [email protected] ~]# Touch            -a-t 201803211540.10/tmp/passwd [[email protected] ~]# touch-m-t 201803211541.10/TMP/PASSWD [[email protected] ~]# stat/tmp/passwd File: '/tmp/passwd ' size:1580 Bloc Ks:8 IO block:4096 Regular file device:fd00h/64768d inode:1336933 links:1 Acc ESS: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) access:2018-03-21 15:40:10.000000000 +08            XX modify:2018-03-21 15:41:10.000000000 +0800 change:2018-03-21 15:45:00.000000000 +0800 -C: If the file does not exist, it is not created

Linux file system, System Management class commands, bash basic features

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.