Linux Shell Learning-Lecture 1 (Basics)


Introduction

Linux-a free and open source Unix-like OS. As a service OS, it has the characteristics of stability (most prominent), robustness, security, and high performance. Linux Shell is an interface program between the user and the Linux kernel, and is a user program.


1. What kind of Shell?

Common types: Bourne Shell (sh), C shell, Korn Shell.
Bourne-Again Shell (bash) is the most commonly used Shell in Linux systems, C Shell (csh) is more suitable for programming, Korn Shell (ksh) combines the advantages of csh and sh, and supports task control. In addition, there are other Shell types such as ash and zsh.

Two, Linux Shell

1. User classification

Linux divides users into:
1. Super user (root, uid=0): use # as prompt
2. Ordinary user (uid 500-60000): use $ as prompt
3. Pseudo (system) user: not a system service Real users such as bin and shutdown are pseudo users.

2. Commonly used Shell (Bash) commands

tips:
* is a wildcard (commonly used when searching for files);.
represents the current directory;
~ represents the home directory: the home directory of ordinary users is /home/username, the
home directory of root users is /root;
permission classification: rwx (4-2-1 );
User group: each record in /etc/group is divided into four fields, group_name:passwd:GID:user_list

2.1 View files and directories

1. ls -alh lists file names and directories
-a: (all) displays all files, including hidden files;
-l: (list) displays in list form;
-h: (human readable) displays file size
tips: What are hidden files?
For example:
Insert picture description here
the file containing "." and "..." in the above figure
2, cat [option] [finename] -n/-b connection display file content
-n: display line number
-b: only identify non-blank line line number
3 , Head -n/c display the head of the file
-n: print the first n lines, -cd print the first n bytes
4, tail -n/f display the end of the file
-n: print the last n lines,
-f: print the file in real time The newly written line in the log file - often used to monitor log files.
5. Find Find a file or directory. It
can be searched based on permissions, users, user groups, file types, file names, dates, sizes, and other possible conditions.
Example:
A, find the current directory, the file named lsab:
the Find. -Name lsab
-name: case sensitive, iname: case-insensitive
b, find the current directory, when the directory name ljq directory:
. The Find - type d -name ljq
-type: identification type, d: directory, f: file
c. Find all files whose file permissions in the current directory are not 777:
find. -type f! -perm 777
! : Means non (negative), perm: means permission
d, find all executable files in the user's home directory:
find ~ -type f -perm /a+x
Other parameters:
// -group user group, what does -exec action perform Operation,
-mtime time (counted in days), -size file size

2.2 Operating files and directories

1. Touch -a/c/m/r/t to create a file
2. mkdir -p to create a directory
-p: automatically create a parent directory that does not exist yet
3. cp -p/r source dest [source, target] to copy files Or directory
-p: retain the owner, user group, permission, modification time and other information of the source file,
-r recursive copy
4. mv oldname newname to rename the file or directory
5. rm -rf delete file or directory
-f: force delete , Do not prompt the user to confirm before deleting

2.3 Manage file and directory permissions

1. chmod [option] [ugoa] [[±=][rwxug]][,…] file modification permissions
u: owner, g: user group member, o: other users not in the user group, a: all users ,
+: add permission, -: revoke permission, =: only have the corresponding permission.
Example:
only write permission to the owner of the file
chmod u=w xxx.sh
ps: give personnel the permission to modify and execute the configuration file when the corresponding service is deployed
2. chown [-cfhvR] [–help] [–version] user[:group] file… Command to set the file owner and file association group
Example:
a. Set the owner of /var/run/qw.pid to root :
Chown root /var/run/qw.pid
can execute this command with root user authority
3. chgrp [-cfhRv][–help][–version][group][file or directory...] or chgrp [- cfhRv][–help][–reference=<reference file or directory>][–version][file or directory...] Change the group to which the file or directory belongs.
Example:
a. Description: Assign the log2020.log file to the root group
Change to bin group chgrp -v bin log2020.log

to sum up

The above is the learning record of common commands of Linux shell this week. It mainly records the commands commonly used in work (such as: tail -f logs/all.log, ls -alh, cd, cat). If there are any errors, please point out. Commands not mentioned in the article are not recorded because they are not in the above modules (such as ps -ef |grep java), and the corresponding modules will be updated in time when they are learned.

Guess you like

Origin blog.csdn.net/weixin_44158441/article/details/108494545