catalogue
1. Knowledge introduction 2. The production process of linux operating system 3. linux advantages 4. linux architecture 5. linux kernel and distribution 6. File system and directory structure 7. Terminal and common commands 8. Disk command 9. File command 10. Other common commands 11. Case explanation
1. Knowledge introduction
windows Desktop system/Server side linux Server side mac/unix android/ios Desktop system: mainly for mass users, with the principle of beauty and ease of use, and a graphical interface. Server side: if you know the small black window for debugging using the command line, you will know what the server side is.
Just bought back computer: only hardware;
Hardware: mainly including CPU,Memory, motherboard, hard disk drive, optical disk drive, various expansion cards, connecting cables, power supply, etc; External devices include mouse, keyboard, etc.
Only after installing the operating system and application software can the computer world become rich and colorful;
Hardware only (bare metal) Operating system software: windows system Application software: qq,WeChat
What is the role of the operating system? Why not install "application software" directly on the hardware and install an operating system?
The operating system can provide disk management, memory management and resource scheduling to avoid chaos.
What is linux?
1)Linux The operating system is an open source operating system, which is mainly used on the server side. 2)be based on posix and unix Multi user, multitasking, multithreading and multithreading cpu Operating system. 3)Linux Inherited UNIX The design idea with network as the core is a multi-user network operating system with stable performance.
2. The production process of linux operating system
1) What are the GPL terms?
2) linux Author: Linus
Note: the reason why linux is called linux is the combination of linus and unix.
3. linux advantages
- 1) Time sharing, multi-user and multi task operating system;
- 2) Most network protocols support and convenient remote management;
- 3) Powerful memory management and file system management;
- 4) A large number of available software and free software;
- 5) Excellent stability and safety;
- 6) Good portability and flexibility;
- 7) There are many manufacturers to choose from;
4. linux architecture
5. linux kernel and distribution
Linux Kernel: the kernel establishes the communication platform between computer software and hardware. The kernel provides system services, such as file management, virtual memory and device I/O,Process management, etc. "The software calls the kernel, and the kernel operates the hardware" Kernel version: it is the heart of the system and the core used to run programs and manage hardware. The kernel manages computer hardware through system calls, and terminal commands are used to detect whether the system calls are correct, It makes it more convenient to call computer hardware. System call is mainly to facilitate the program to indirectly access the computer hardware. Distribution: the distribution includes Linux Kernel, the distribution is Linux Build a set of applications on the kernel, including desktop management program, video player program and so on. because Linux The kernel has realized the interaction with the computer hardware, so the distribution version can be accessed with the computer hardware through the system call of the system kernel, which greatly shortens the opening time The time of sending the system.
Release:
6. File system and directory structure
1) File system: determine how files are stored and managed
Windows : NTFS(FAT16 FAT32) Linux: centos5 : ext3 file system centos6 : ext4 file system centos7 : xfs file system
2) Linux file system description
① Everything in linux is a file.
② The name of the directory or file shall not exceed 255 characters in length. The file or directory is composed of the following characters:
- Upper case letters (A-Z), lower case letters (A-Z), numbers (0-9)
- Underscore (), period (.), comma (,)
- Note: files and directories are case sensitive.
③ The Linux file system does not have an extension. Adding an extension just helps us distinguish what different files represent, and the real type of the file (file or directory) is determined by [content in the file].
④ Directory structure
The tree structure is as follows:
Note: do not delete or add the secondary directory under / (root directory).
Suggestions for use:
7. Terminal and common commands
1) Terminal: provides user and kernel interaction tools.
2) [format of command] in Linux
3) Examples of commands
[root@image_boundary ~]# ls -l anaconda-ks.cfg -rw------- 1 root root 1598 Sep 17 15:57 anaconda-ks.cfg
4) Common commands
Here are linux commands for you. Daquan baby website: http://man.linuxde.net/
8. Disk command
1) cd command: Directory switching
cd Relative path/Absolute path. Use relative path or absolute path to switch to a directory; cd . Indicates the current path; cd .. Return to the previous level directory; cd ~ if it is root User, that is, switch to root User's home directory[/root]; If it is an ordinary user, it is to switch to the home directory of an ordinary user[/home/Ordinary user name]; cd / Return directly to"/"Root directory; cd - Return to the previous operation directory;"(This works well)"
The operation is as follows:
[root@image_boundary ~]# cd / [root@image_boundary /]# cd home [root@image_boundary home]# cd ../usr [root@image_boundary usr]# cd - /home [root@image_boundary home]# cd .. [root@image_boundary /]# pwd / [root@image_boundary ~]# su hadoop [hadoop@image_boundary root]$ cd ~ [hadoop@image_boundary ~]$ pwd /home/hadoop
2) pwd: displays the current working directory
[root@image_boundary /]# pwd / [root@image_boundary /]# cd ~ [root@image_boundary ~]# pwd /root [hadoop@image_boundary ~]$ pwd /home/hadoop
3) ls command: viewing directory contents
- -l: Show details
- -a: View hidden content. (show files that start with.)
- -a: View hidden files. (show those files starting with. Except that. And...) are not displayed. Note:. Indicates the current folder... Indicates the upper level folder "
- -h: Show in a friendly way (the file ends with K, M...)
- -R: Show all files recursively.
- Common combination operations: ls -l can be simplified to ll. ll -h displays the specific information of the file and displays it in a friendly way.
The operation is as follows:
[root@image_boundary ~]# ls -l can be written as ll total 108 -rw-r--r--. 1 root root 9 Sep 17 19:10 aa.txt~ -rw-------. 1 root root 1598 Sep 17 15:57 anaconda-ks.cfg [root@image_boundary ~]# ls -lh can be written as ll -h total 108K -rw-r--r--. 1 root root 9 Sep 17 19:10 aa.txt~ -rw-------. 1 root root 1.6K Sep 17 15:57 anaconda-ks.cfg
4) du command: check the disk space used by each file and directory. (I don't know how to use it at present)
- -a: Show everything
- -h: Show in a friendly way
- -s: Count the total space occupied by all files
- du -h: recursively displays the occupied space of the current folder and its subfolders.
- du -h a.txt: displays the space occupied by the specified file a.txt.
- du -h aa: displays the space occupied by the specified folder aa.
- du -sh: displays the space occupied by files in the current folder
The operation is as follows:
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb [root@image_boundary Desktop]# du -sh 28K .
5) df command: viewing disk usage
- -h: Show in a friendly way
- -a: Display all file systems;
- Note: "df -h is used to display the usage of disk space and the amount of disk space remaining."
The operation is as follows:
[root@image_boundary Desktop]# df -h file system Capacity used available used% Mount point Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_image-lv_root 35G 3.6G 30G 11% / tmpfs 931M 296K 931M 1% /dev/shm /dev/sda1 477M 42M 411M 10% /boot /dev/sr0 3.7G 3.7G 0 100% /media/CentOS_6.9_Final
9. File command
1) mkdir: create directory
- -p: Create directory recursively
The operation is as follows:
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb [root@image_boundary Desktop]# mkdir cc [root@image_boundary Desktop]# ll total 12 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb drwxr-xr-x. 2 root root 4096 Oct 15 20:21 cc # If you don't write - p, an error will be reported. [root@image_boundary Desktop]# mkdir dd/ee mkdir: cannot create directory `dd/ee': No such file or directory # The - p parameter means that a directory is generated recursively. # Create a recursive directory dd/ee. [root@image_boundary Desktop]# mkdir -p dd/ee [root@image_boundary Desktop]# cd dd [root@image_boundary dd]# ll total 4 drwxr-xr-x. 2 root root 4096 Oct 15 20:22 ee
2) touch: creating files
[root@image_boundary Desktop]# ll total 16 drwxr-xr-x. 2 root root 4096 Oct 15 20:02 aa drwxr-xr-x. 2 root root 4096 Oct 15 20:05 bb drwxr-xr-x. 2 root root 4096 Oct 15 20:21 cc drwxr-xr-x. 3 root root 4096 Oct 15 20:22 dd [root@image_boundary Desktop]# cd cc [root@image_boundary cc]# ll total 0 [root@image_boundary cc]# touch sum.txt [root@image_boundary cc]# ll total 4 -rw-r--r--. 1 root root 0 Oct 15 20:28 sum.txt
3) File: view file types
- -b: Do not display the file name, only the file type.
The operation is as follows:
"file File name: it can display whether it is a file or a directory" [root@image_boundary ~]$ file aa aa: directory [root@image_boundary cc]# ll total 0 -rw-r--r--. 1 root root 0 Oct 15 20:28 sum.txt "View the type of the current folder(This means cc): folder" [root@image_boundary cc]# file . .: directory "If sum.txt No content in, display empty" [root@image_boundary cc]# file sum.txt ./sum.txt: empty "If sum.txt Content in, display sum.txt File type" [root@image_boundary cc]# file sum.txt ./sum.txt: ASCII text [root@image_boundary cc]# file -b sum.txt ASCII text
4) rmdir: delete empty directory
- -p: Delete empty directory recursively
The operation is as follows:
"Note the difference between the following two commands" rmdir dd/ee/ff Indicates deletion dd below ee The following is an empty directory ff. rmdir -p dd/ee/ff Indicates simultaneous recursive deletion dd/ee/ff These three directories.
5) rm: delete a file or directory
- rm file name
- -i: Ask. (this is the default. If you don't write it, it means you want to ask.)
- -r: Recursive deletion.
- -f: Force deletion (no prompt for deletion).
- "The following command: use with caution!!! Unless you really know what you're doing."
- rm -rf directory / file
The operation is as follows:
[root@image_boundary bb]# ll total 12 -rw-r--r--. 1 root root 149 Oct 15 20:00 a.txt -rw-r--r--. 1 root root 95 Oct 15 20:02 b.txt -rw-r--r--. 1 root root 138 Oct 15 20:02 c.txt [root@image_boundary bb]# rm a.txt rm: remove regular file `a.txt'? n [root@image_boundary bb]# ll total 12 -rw-r--r--. 1 root root 149 Oct 15 20:00 a.txt -rw-r--r--. 1 root root 95 Oct 15 20:02 b.txt -rw-r--r--. 1 root root 138 Oct 15 20:02 c.txt [root@image_boundary bb]# rm a.txt rm: remove regular file `a.txt'? y [root@image_boundary bb]# ll total 8 -rw-r--r--. 1 root root 95 Oct 15 20:02 b.txt -rw-r--r--. 1 root root 138 Oct 15 20:02 c.txt "rm -rf bb Will delete bb All directories and files under the directory are not asked and merciless. Do not use this command easily" [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 20:53 bb drwxr-xr-x. 2 root root 4096 Oct 15 20:30 cc [root@image_boundary Desktop]# rm -rf bb [root@image_boundary Desktop]# ll total 4 drwxr-xr-x. 2 root root 4096 Oct 15 20:30 cc
6) cp: copy files or directories
- Note: after a file or directory is copied, the original file or directory still exists.
- cp source file (directory) destination file (directory)
- -i: Hint.
- -r/-R parameter: this parameter must be used when copying directory.
- -r/-R: recursively copy directories.
- -f parameter: used when setting up a cluster and modifying the time zone
- -f: Overwrite the existing target file without prompting.
① If the same file is copied to the same directory, it needs to be renamed; Otherwise, an error will be reported.
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:00 aa drwxr-xr-x. 3 root root 4096 Oct 15 21:00 bb [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# ll total 4 -rw-r--r--. 1 root root 21 Oct 15 21:00 sum.txt -rw-r--r--. 1 root root 0 Oct 15 20:59 sum.txt~ "The current directory sum.txt File, copy to the current directory." "If the file name is not modified, an error will be reported." [root@image_boundary aa]# cp sum.txt sum.txt cp: `sum.txt' and `sum.txt' are the same file "After modifying the file name, no error will be reported." [root@image_boundary aa]# cp sum.txt sum1.txt [root@image_boundary aa]# ll total 8 -rw-r--r--. 1 root root 21 Oct 15 21:04 sum1.txt -rw-r--r--. 1 root root 21 Oct 15 21:00 sum.txt -rw-r--r--. 1 root root 0 Oct 15 20:59 sum.txt~
② Copy the same file to different directories without changing its name;
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:04 aa drwxr-xr-x. 3 root root 4096 Oct 15 21:00 bb "take aa Under directory sum.txt Files, copying to bb Under the directory, you do not need to modify the name." [root@image_boundary Desktop]# cp aa/sum.txt bb/ [root@image_boundary Desktop]# cd bb [root@image_boundary bb]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:01 bbb -rw-r--r--. 1 root root 21 Oct 15 21:07 sum.txt
③ Recursively copy the things in bb directory (including both files and directories) to aa directory.
"Since the directory is copied, the parameter must be used[-r/-R]" [root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:52 aa drwxr-xr-x. 3 root root 4096 Oct 15 21:07 bb "take bb Copy directory to aa Directory." "Note: parameters must be used when copying directories-r perhaps-R" [root@image_boundary Desktop]# cp -r bb aa/ [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# ll total 4 drwxr-xr-x. 3 root root 4096 Oct 15 21:53 bb -rw-r--r--. 1 root root 0 Oct 15 20:59 sum.txt~
7) mv: move a file or directory
- -i: Hint.
- -f: Force movement.
- -u: The new overwrites the old and moves when it does not exist.
① To move the same file to the same level directory, you must modify the file name, which is equivalent to renaming.
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 21:55 aa drwxr-xr-x. 2 root root 4096 Oct 15 21:54 bb [root@image_boundary Desktop]# mv bb/sum.txt bb/sum1.txt
② Move the same file to a different directory. If no new file name is specified, the effect is equivalent to moving.
- This operation is only equivalent to moving sum.txt to aa directory.
[root@image_boundary Desktop]# mv bb/sum.txt aa/
③ You can move the same file to different directories without changing the file name.
- If a new file name is specified, the effect is equivalent to move + rename.
[root@image_boundary Desktop]# mv bb/sum.txt aa/sum.txt "hold bb Under directory sum.txt Files, moving to aa Directory and rename to sum1.txt. " [root@image_boundary Desktop]# mv bb/sum.txt aa/sum1.txt
8) head/tail: displays several lines at the beginning or end. The default is 10 lines
- -n: Specify the number of rows;
- head: view all contents in the file;
- tail: view all contents in the file;
- head -n: view the first n rows of data;
- tail -n: view the last n rows of data;
- "The following parameter will be used in planning tasks."
- "In the hadoop cluster, it is used when viewing log files."
- tail -f: view new additions;
The operation is as follows:
[root@image_boundary Desktop]# ll total 8 drwxr-xr-x. 2 root root 4096 Oct 15 22:35 aa drwxr-xr-x. 2 root root 4096 Oct 15 22:30 bb [root@image_boundary Desktop]# head -3 aa/sum.txt aaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbb ccccccccccccccccc [root@image_boundary Desktop]# tail -3 aa/sum.txt mmmmmmmmmmmmmmmmm nnnnnnnnnnnnnnnnn ooooooooooooooooo
9) cat/tac: view file contents
- -n: Displays the file line number. (this is commonly used by cat)
- cat: view all contents in the file, and you are looking at it.
- tac: view all the contents of the file, upside down.
The operation is as follows:
[root@image_boundary Desktop]# cat -n aa/sum.txt 1 1 2 2 3 3 4 4
cat has a powerful operation with EOF command:
10) more: split screen display, one screen at a time
- q key: exit the more command.
- Space key: displays the next screen of text.
- Enter: displays only the next line of text.
- h key: display the help screen with relevant help information.
- b key: display the content of the previous screen.
11) less: page up and page down to browse the contents of the file
- q key: exit the less command.
- G: Skip to end of file
- gg: skip to the first line of the file
- Press e key: scroll up one line
- Press y key: scroll down one line
The operation is as follows:
less -N aa/sum.txt This parameter displays the number of lines of file content
The results are as follows:
12) echo: output string or variable
-e: Handle special symbols. eg: Yes-e,Will put\n As a newline, otherwise it won't. echo $PWD : Absolute path of output variable ">Indicates overwriting the contents of the source file" echo aa > a.txt ">>Indicates append to the end of the source file" echo aa >> a.txt
The operation is as follows:
[root@image_boundary Desktop]# echo "aa\nbb" aa\nbb [root@image_boundary Desktop]# clear "-e Parameter that enables the system to recognize special characters" [root@image_boundary Desktop]# echo -e "aa\nbb" aa bb [root@image_boundary Desktop]# echo -e "aa\tbb" aa bb ================================================== "echo $PWD Indicates the absolute path of the current folder, which is very useful." [root@image_boundary Desktop]# echo $PWD /root/Desktop [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# echo $PWD /root/Desktop/aa [root@image_boundary aa]# cd ../bb [root@image_boundary bb]# echo $PWD /root/Desktop/bb ================================================= [root@image_boundary Desktop]# echo -e '666\n888' > ./aa/aa.txt [root@image_boundary Desktop]# echo -e 'Chinese' > >. / AA / aa.txt
13) ln: create hard and soft links
- Hard link is similar to [copy];
- Soft connection is similar to [create shortcut] (common);
- Create a hard link for f1 f2: ln f1 f2
- Create a soft link (also known as symbolic link) for f1 f3: ln -s f1 f3
The operation is as follows:
[root@image_boundary Desktop]# ll total 4 drwxr-xr-x. 2 root root 4096 Oct 15 23:28 aa "Create a file test.txt" [root@image_boundary Desktop]# cd aa [root@image_boundary aa]# touch test.txt "Creating a hard link is equivalent to copying the file" [root@image_boundary aa]# ln test.txt test "Creating a soft connection is equivalent to creating a shortcut to the file" [root@image_boundary aa]# ln -s test.txt s_test [root@image_boundary aa]# echo "I am a student" >> test.txt [root@image_boundary aa]# cat s_test I am a student [root@image_boundary aa]# cat test I am a student "Delete source file test.txt after" [root@image_boundary aa]# rm -rf test.txt "The soft link file (shortcut) disappears" [root@image_boundary aa]# cat s_test cat: s_test: No such file or directory "But the hard link (copy) will not disappear" [root@image_boundary aa]# cat test I am a student
14) alias: View aliases for some commands
- "The meaning of defining aliases is that aliases can be used to replace some combined commands and reduce code typing;"
- View alias: alias
- Define alias: alias la ='ll -a '
- Cancel alias: unalias la
The operation is as follows:
[root@image_boundary Desktop]# alias alias cp='cp -i' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' alias mv='mv -i' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
10. Other common commands
clear or ctrl+l : Clear screen history : Display history code command su : Switch users. $Ordinary users;#Administrator root user hostname : Display host name sudo : with root Execute the command once with user permission (I don't quite understand this at present) exit : Exit the current login status. Currently, ordinary users switch to root user;Currently root The user switches to the normal user. who : Displays which users are currently logged into the system | : The pipe character indicates that the output of the previous command is used as the input of the following command.
11. Case explanation
The operation is as follows:
"First, create these three folders;" [root@image_boundary Desktop]# mkdir myFile [root@image_boundary Desktop]# mkdir myPic [root@image_boundary Desktop]# mkdir backup [root@image_boundary Desktop]# ll total 16 drwxr-xr-x. 2 root root 4096 Oct 15 23:36 aa drwxr-xr-x. 2 root root 4096 Oct 15 23:57 backup drwxr-xr-x. 2 root root 4096 Oct 15 23:56 myFile drwxr-xr-x. 2 root root 4096 Oct 15 23:56 myPic "Respectively in myFile,backup Create one separately a.txt;" [root@image_boundary Desktop]# cd myFile [root@image_boundary myFile]# touch a.txt [root@image_boundary myFile]# cd .. [root@image_boundary Desktop]# cd backup [root@image_boundary backup]# mkdir a.txt "delete backup This folder and its contents;" [root@image_boundary Desktop]# rm -rf backup "Moving the same folder to the same level directory is equivalent to modifying the name;" [root@image_boundary Desktop]# mv ./myFile ./File "take File Under directory a.txt Files, moving to myPic Directory;" [root@image_boundary Desktop]# cp ./File/a.txt ./myPic/