C language read by byte
Fgetc
C language read by line
Fgets
Linux reads file contents
More file names
Cat is the full read
Ps-ef | grep name shows the process by name
C-language string converted to a number (in Stdlib.h)
int atoi (const char *c)
File permissions:
Read Cat text.c
Write VI text.c
10-bit permission characters (file permissions)
-The first bit refers to what type, file-or folder D
The last 9 bits are permissions, the first 3 are permissions to the file owner
The Middle 3 is the user group's permissions to the file
3, representing other users ' permissions on the file
R: Reading (read) Number 4
W: Writes (write) array 2
X: Execute (EXECUTE) Number 1
Add up is 777 rwx
Generally speaking, it's 755.
which chmod
chmod is a tool.
Give yourself additional execution privileges (U stands for yourself)
chmod u+x AA
Add X to group user (G for user group)
chmod g+x AA
Add X to other users (O on behalf of other users)
chmod o+x AA
Reducing permissions IS-
chmod o-x AA
Chmod-r 777 folder name
======================================
Shell Script
if [AAA = ddddd]
Then
Xxoo1
Else
Xxoo2
Fi
File judgment:
-D Directory
-s file length greater than 0, non-empty
-F Regular File
-L Symbolic connection
-u file has suid bit settings
-R Readable
-X execution
Escaping line breaks
Echo-e "abc\n111"
-e This parameter is escaped
Add output to File
echo "Asdad" > Error.log
Append output to File
echo "CCCCCC" > Error.log
Define variables (there can be no spaces when defining variables, and when you want to take the value of a shell variable, you need to precede the variable name with a $ character, and enclose the value in the middle of the assignment with a space)
Err_logfile= ' Asdasdad '
Output variables
$ERR _logfile
Output time:
Date + '%y-%m-%d%h:%m:%s '
Sed reads the first line of content
Sed-n ' 1p ' index.html
Curl commits (-D is with parameters)
Curl-d "Password=123" http://www.jtthink.com/test/update.php
Take the second line of the file (-S is to remove the hint)
Curl Http://www.jtthink.com/test/conf.txt-s | Sed-n ' 2p '
Some commands for judging numbers
-GT is greater than the meaning of large than
-LT is smaller than less than
-eq is equal to Euqal
-ne is not equal to not equal
-ge is greater than or equal to large equal
-le is less than or equal to lesser equal
#是SHELL脚本的注释
==================================================================
New user
Useradd mengfanxin
Change Password
passwd User Name
Delete User (-R is deleted with user's home directory)
Userdel-r Mengfanxin
See which user groups are available
Cat/etc/group
Cat/etc/shadow
cat/etc/passwd
Modify user permissions and properties
Usrmod
Usermod-c ' Hello ' meng//plus notes
Usermod-s/sbin/nologin Meng//default login not operating system
-c< Notes > Modify Notes
-d< Login Directory > Modify the directory where users log on
-e< Validity Period > Modify the expiration date of the account
-f< Buffer days > Modify the number of days after the password expires to close the account
-g< Group > Modify the group to which the user belongs
-g< Group > Modify additional groups to which a user belongs
-l< Account name > Modify user account name
-L Lock the user password to invalidate the password
-s<shell> Modify the shell used by the user when they log in
-u<uid> Modify User ID
-U Unlock password
==================================================================
Lesson 17
grep "Meng"/etc/passwd
ls | grep "Mengfanxin"
grep "Meng"/etc/*
Find Meng in shadow
grep "Meng"/etc/shadow
List folders and files that contain she
ls | grep She
Regular matches the beginning of a
grep ' ^a '/etc/passwd
cat/etc/passwd | grep ' ^shenyi '-C
Use--stdin to enter the 123 into the passwd command.
echo "123" | passwd God--stdin
Delete entire line under VIM
Ctrl+u
Powerful markers
$ #传递脚本的参数个数
$$ the current process ID number for the script to run
$! Process ID number of the last process running in the background
[Email protected] and $ #相同, but use quotation marks and return each parameter in the boot
$? Displays the exit status of the last command. 0 means no error, and any other value indicates an error (or unsuccessful execution)
In the shell, write:
Useradd $USER _name
If [$?-eq 0]This sentence here means the execution of the add user instruction succeeds (judging whether the previous one specifies success)
Then
echo "Succerss"
Else
echo "Faied"
Fi
==============================================================
Lesson 18:
Output to File
echo "AA" >a.txt
Append to File
echo "BB" >b.txt
Mask error (mainly with this 2, and 0 and as if it is a masking error)
echo "BB" 2>/dev/null
Switch to Mengfanxin user
Su-mengfanxin
If this file does not exist, then switch to God user created, and then switch back to Su-god-s is the execution shell
if [!-d/home/god/bin]
Su-god-c "MkDir bin"
echo "Bin is created"
Fi
To perform certain operations, it is best to switch to other users, directly with root, security is too poor.
List processes
Ps-ef
-A List all Processes
-U View the process of making a user (ps-u root)
Generally with PS-EF or Ps-ef | grep xxx
Script hibernation
echo "Start"
Sleep 5
echo "End"
This 5, is stopping for 5 seconds
C-Language sleep:
#include <stdio.h>
int main ()
{
printf ("start\n");
Sleep (5);
printf ("end\n");
}
Compiling gcc me.c-o me
Linux Learning Note 1