Shell programming
-
The file extension is. Sh
Create file vi hello.sh#! /bin/bash Copy the code
-
Add an account userAdd Zhangfei
Set the password to passwd XXX
Enter account su XXX
To delete the account, run userdel -r XXX
Copy the code
Linux
-
Linux root directory /
-
Directory:
Bin: binary file, which is the Linux executable file boot: boot directory dev: device file etc: system configuration file ^ home: user lib: library file media: multimedia MMT: Shared folder opt: optional tool Proc: information about processes root: home directory for super users RUN: information about running processes Sbin: binary system SRV: information about services sys: system files TMP: temporary usr: a user-level directory is similar to a shared data resource "C :/program files" ^ var: information about a variableCopy the code
-
View the current directory: PWD ~ : Home directory of the current user Command format: command [- options][Parameters] The command is case-sensitive, where options and parameters are optional. The options and parameters are separated by Spaces. Ls -a Also displays the hidden directory ls -l(ll) Displays details. Whoami user switch: su XXX root user switch to # user exit su is used with exitCopy the code
-
File operation: Create file named filename :touch filename (the file is black, The directory is blue) Create a file named filename in the dir directory :touch dir/filename echo The command output shows the file echo hello >a.txt Write the string of Hello to a.txt echo hello >>a.txt Write hello to append to a. TXT to view file contents: Cat a.txt Viewing the contents of a file More fileName Viewing the contents of a file in a split screen Back is not supported (Press Enter to split screen, look down the space, and turn a page to exit q less is also available.) head -5 /fileName View the first five lines. Tail -5 /fileName View the next five linesCopy the code
-
Directory operation: Create a common folder: mkdir Directory name Create a multi-level parent folder: mkdir -p directory/directory/directory Move a directory: Mv hello/ a Hello directory :mv a b./ indicates that the current directory is a recursive copy. Cp -r word/ hello (copy word directory to hello directory) Delete files: rm b.txt Delete files: rm -r directory Violent delete: rm -rf (f can stand for false)Copy the code
-
Find./ -name "*.txt" Type of files that can be searched: find./ -type f (search for all files) find./ -type d (Search for all directories) Search for the contents of files: Grep hello b.xt (find hello in b.xt)Copy the code
-
Permission management:
chmodPermission File/directory Specifies the permission information of a file,r read4W to write2 xperform1
Owner (created user), owner group (belonging to that user group), other groups
Add to a.txt file ownerx(Execute permission)chmod u+x a.txt
Add to the a.txt file groupx(Execute permission)chmod g+x a.txt
Add to the a.txt file groupx(Execute permission)chmod o+x a.txt
chmod 664 a.txt
Copy the code -
Process command: ps view the current terminal window in the process of ps - aux: view all the processes in a system (ps - aux | more) ps - ef: view the list of the current process (ppid the parent process) kill process: kill kill 9 specified process number: forced to delete the specified processCopy the code
-
Other commands :ifconfig: Displays information about the current system, including the IP address. Tar ZCVF File name of the compressed file.tar.gz Path 1 Path 2... Gz: decompress the decompress package. Man [Chapter ID] Command/function name: Query the specified command or function (help query)Copy the code
Use the VI tool
-
Vi and vim are text editors based on Linux commands
-
Edit command in command mode:i: Inserts before the current positiona: Inserts after the current positiono: Inserts under the current line
Copy the code -
Shell <br /> Command line mode delete commands :x: delete one character Dw: delete the current word 3DW: delete three words DD: delete the current line 5dd: delete five lines Command line mode change mode :r: replace one character CW: replace one word cc: replace one line C : Replace copy from cursor to end of line command line mode command :yw: copy word YY: copy line dw: cut word dd: cut line P: paste down current line U Undo CTRL + R Cancel undo <br />
Bottom line mode command ::w save to a newfile :w newfile save to a newfile :wq save to exit vi(or zz, or x):q! 1,2, co3 copy rows 1,2, 4,5mo6 move rows 4, Line 5 after line 6 :%s/source string/target string (to implement string replacement for all the first replacements of each line) :%s/source string/target string /g to replace all in each line use the vimtutor command to practice vi command user directory ~ /. Vimrc)Copy the code