Linux basic directives and Rights management

Source: Internet
Author: User
Tags chmod

Basic directives
#打印字符串echo hello linux#将file1 和 file2粘合在一起,打印到标准输出流cat file1 file2
Standard input and output
    • Standard input, stdin, i.e. keyboard, mouse input
    • Standard output, stdout, i.e. output to terminal
    • Standard error stream, STDERR, error message for output to terminal
Common commands
# 列出目录下的文件以及详细信息ls -l /home#将file1复制到file2cp file1 file2#将多个文件复制到dir目录cp file1 file2 file3 dir#将file1重命名成file2,如果两者在同一个目录下mv file1 file2#将多个文件移动到dir目录下mv file1 file2 file3 dir# 创建文件file,如果已经存在则更新创建时间touch file#删除文件以及目录下的文件rm filerm -rf /dir#将参数显示到标准输出,还可以输出变量以及echo hello again
Browse Catalogs
    • .Represents the current directory
    • ..That represents the previous level of the directory
# 切到dir目录下cd /dir#创建dir目录mkdir /direcho#打印当前目录下所有at开头的文件名echo#所有包含at的echo# 所有at结尾的# * 通配任意长度的字符串# ? 通配单字符# ‘*‘可以禁止通配符展开,即打印字符(*)本身
Intermediate command
#在passwd文件中匹配root关键字的行, and print to the standard output streamgreproot/etc/passwd#匹配etc目录下所有包含root行的文件greproot/etc/*#-I means case-insensitive match root, such as root,root, etc.grep-I. ROOT/ETC/PASSWD#-v indicates the reverse matching of the passwd file, which prints all rows that do not contain rootgrep-V root/etc/passwd#相当于cat和more的加强版, split screen browse file content Less/usr/share/dict/words# B Front screen, space after a screen, Q quit,/word down search word keywords, word search up word keywords#显示当前目录pwd-P#比较两文件的不同点diffFile1 file2#查看file1文件的格式信息fileFile1Locate the file address named filename in the #/dir directory and print to the terminalFind/dir-name FileName#打印file1的前10行, IF-5, indicates the first 5 rowsHeadFile1#打印passwd文件尾部内容Tail/etc/passwd#排序file1的行, output to standard stream (terminal)SortFile1Sort-r/etc/passwd# Reverse Sort
Basic file system Knowledge Change password
passwd#然后输入一次旧密码,两次新密码即可修改当前用户密码passwd#修改root用户的密码
Dot file

That is, . the file that begins with, hidden by default, is called to ll display

Environment variables and shell variables
STUFF=#给STUFF变量赋值blade,注意等号两边没空格,否则报错echo$STUFF#打印STUFF变量#将变量转成系统环境变量exportSTUFF
    • The most important difference between environment environment variables and shell variables: Shell variables are only available in the current shell, environment variables can be used throughout the system, including some file configuration files. Typically, we often configure $PATH variables
Command path

That is $PATH , a variable, he defines a bunch of directories to separate the directories : . When a terminal types a directive, for example ls , it PATH searches for a directive file under a defined path. If there is more than one directory containing the directive, the first directory will prevail

Some shortcut keys for knocking on the command line
ctrl-b#光标左移ctrl-f#光标右移ctrl-p#上一个指令ctrl-n#下一个指令ctrl-a#光标移到指令开头ctrl-e#移到指令结尾ctrl-u#删除光标到开头的内容ctrl-k#删除光标到结尾的内容ctrl-y#粘贴前面删除的内容
Help documentation
#查看ls指令帮助文档man ls#查看find指令的文档info find#查找带sort关键字的所有指令man -k sort
Instruction type
Type Code type meaning
1 User instructions
2 System kernel functions
3 Lib function library
4 interface, device, driver information
5 Configuration files, mostly under/etc
8 System-level directives for super users
Redirects and pipelines

Redirect: The position of the output stream will be re-changed, commonly used is the standard output stream to a file

#将grep的输出重定向到file1中grep> file1#一般的`>`会清空文件的本身内容在接受输出,使用`>>`会改为追加模式

Pipeline: The output of the previous instruction is the next command input, and the data flows between the instructions as if it flows through a pipe that does not pass through.

# 将grep的输出内容使用sort排序,然后重定向到file1中grep|sort> file1
View, in-action process parameters
    • PID: Process id,process ID
    • TTY: TERMINAL equipment
    • Stat: State, S means sleep,r represents run
    • Time, CPU-intensive
    • Command: Enable the command for this process
Query instructions
# x:当前用户占用的所有进程 ax:系统所有进程 u:更详细的进程信息 w:显示命令行全名#下面的意思为:显示进程名含有keywords的进程ps -aux process_keywords
Finalization process
kill pidkill -term pidkill#暂停进程kill#唤醒进程kill -9 pid
File permissions

The meaning of Drwxr-xr-x

The first column of the file details, in the form of drwxr-xr-x a descriptor that describes a file's permissions, amounts to 10-bit characters

    • 0-bit,-: Denotes file,D: Indicates directory, l : Indicates linked file, etc.
    • 1-3: File owner's permission, R: Read W: Write X: Execute
    • 4-6: Permissions for user groups
    • 7-9: Permissions for other groups
Modify file Permissions
#group other增加读权限chmod go+r file#设置权限为744,即读写操作-读-读chmod 744 file
Value Description Permissions
    • R:4
    • W:2
    • X:1

Therefore, 744 is (4+2+1) ( - 4+0+0) ( - 4+0+0)

Note that if a directory does not have x permission, LS can only view the name of the file he contains, but not the CD in, and can not read his files

Creating Symbolic Links

Symbolic links, or shortcut keys, to create a shortcut key for a directory

#target:目标目录 linkname:连接符号名ln -s target linkname
Compress, archive

Compress : Reduce the footprint by taking the file as a compressed package

#压缩gzip file#解压gunzip file.gz

Archive : Integrate multiple files or folders into one file

# c:创建归档 v:显示细节 f:表示文件,后接文件名tar cvf archive.tar file1 file2...#解压归档文件 x:解压#tar xvf achiver.tar

In fact, compression and archiving in practice can be tar done in one step, such as

#解压tar xzvf file.tar.gz#压缩 归档tar czvf achiver.tar.gz file1 file2...
Linux directory structure
    • Bin: Executables, C-compiled binaries and shell scripts
    • Sbin: Super User executable, system-level instruction
    • ETC: Configuration file
    • LIB: Compiling dynamic link libraries, functions, etc.
    • Home, home directory, theoretically each user has a home below.
    • Dev: Interface Device files
    • Proc and SYS: System information such as process information, etc.
    • var: run-time information, logs, caches, user information, etc.
    • USR: large number of system files, complex
    • Boot: Boot kernel load file
    • Media: Pluggable Device files
    • OPT: third-party software catalog, many systems do not have this directory
USR Directory

Processes and data that store user space

    • Usr/bin and Usr/sbin: Some instructions used by the user
    • Usr/lib: link Library
    • INCLUDE:C's Coax file (*.h)
    • Info: Instruction Document
    • Man: Instruction Document
    • Local: Where the administrator can install the software
Kernel location

System kernel in Vmlinuz or boot/vmlinuz

Super User

By modifying the etc/sudoers file, you can add a normal user with super privileges. This user only needs to tap to sudo perform root privileges

Reference
    • "Proficient in Linux second Edition"

Linux basic directives and Rights management

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.