First, the Linux Shell BASIC programming
Video 1
1.1. View your system shell information
$ Cat/etc/shell command to get how many shell programs are in the Linux system
$ echo $SHELL command to see which of the shells you are currently using
1.2. View file information, ls
$ ls-l View file information: File type, file permissions, number of hard links to file, user to which the file belongs, group to which the file belongs, file size, last modified time, file name
1.3. Change file permissions, chmod
Only the root user or the owner of the file can change the permissions of the file
Example: $ chmod u=rwx,g+w,o+r myfile The meaning of this command is to add RWX permissions for the owning user of the MyFile file, add W permissions for other users in the same group, and add R permissions for other users of different groups
Example: $ chmod 644 myfile R:4, W:2, x:1
? What does the S-bit and T-bit outside the RWX permission bit mean specifically?
1.4. Change the file's owner, Chown
Example $ chown owner.group myfile Change the owner of the MyFile to owner, owning group
Example $ chown. Group MyFile Change MyFile's owning group
To change the directory and the owning user/group of all the files in the directory at the same time, use-r, for example Chmod-r owner.group Mydir, if you do not use the-r parameter, you can only change the owning user/group of the directory without affecting other files or directories in that directory.
1.5. Change the file's owning group, CHGRP
Example $ chgrp Group MyFile Change the owning group of MyFile
1.6. View or change the default permissions for the generated files, umask
example, view the default permissions for the generated file $ umask If the output is 022, the user creates a file with the default permission of 644, which is rw-r--r--; the permissions for the created directory are 755, which is rwx-r-xr-x, You can see the rules given in the table below.
Umask |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
File |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
0 |
Directory |
7 |
6 |
5 |
4 |
3 |
2 |
1 |
0 |
example, change the default permissions for the generated file to $ Umask 000, which is changed to 000, and the specific rules refer to the table above.
In fact, the value of Umask is set in/etc/profile this configuration file, for a specific user, you can set their own umask in $home/.profile or $home/.bash_profile
1.7. Symbolic Link, Ln
Hard links, $ ln resource destination
Soft links, $ ln-s resource destination
1.8. Learn the yuanyin of shell scripts
Shell scripting is powerful, for example, for a number of repetitive operations, can completely liberate the individual, so that the computer to do the complex, repetitive, time-wasting, creative work, and we should personally do those innovative work, do not fool to repeat the labor
Basic elements of a 1.9.shell script
#!/bin/bash is the first line of the shell script
# indicates a comment
Variable
Flow control Structure
1.10. Here is an example of a simple shell script, saved as hello.sh
#!/bin/shell# This is a shell script that prints Hello world printchar= the "Hello World" echo $printchar;
First execute the command $ chmod u+x hello.sh, let the file owner have executable permissions. If you do not have executable permissions, you cannot execute this script.
Output command $./hello.sh can execute this shell script
Features of the 1.11.shell
An alias; a pipe; command replacement; redirect; background processing; pattern matching; variables; special characters;
1.12.
Second, the Linux Shell advanced Programming
"Linux Shell Programming" video Learning Notes