Log-in Shell:Login via terminalSu-usernameNon-logon Shell:Su USERNAME (switch user with Su, without parameters)Open Command Window under GUIShell scripts executed automatically (using at, crontab, Anacron, etc.)Bash configuration file:Global configuration:/ETC/PROFILE,/ETC/PROFILE.D/*.SH,/ETC/BASHRCPersonal configuration: ~/.BASH_PROFILE,~/.BASHRCProfile class Files: Setting environment variables, running commands or scriptsBASHRC files: Setting local variables, defining command aliasesLog-in Sh
The Shell function returns the value, generally has 3 kinds of ways: Return,argv,echo
1) Return statementThe return value of the Shell function, as in other languages, can be returned through the return statement.Example:
#!/bin/bash-
function mytest ()
{
echo "arg1 = $"
If [$ = 1]; then return
1
else
return 0
Fi
}
echo
echo "MyTest 1"
mytest 1
echo $? # Print return result
e
String-related operations are often involved in the shell batch process. There are a lot of command statements, such as: awk,sed can do various operations of string. In fact, the Shell has a series of operating symbols, you can achieve similar effects, you know, using the internal operator will omit the start of the external program and so on time, so the speed will be very fast.
First, judge read string v
short shell program can list the directory tree, taking advantage of SED's powerful pattern-matching capabilities.The directory tree forms the following:
.
'--SHELLP '
--updates '
--wu-ftpd-2.4
| '--doc |
|--examples
|
'--SRC | | '--makefiles
| '--support | | '
--makefiles |
| '--man
| '--util
script is as follows:
#!/bin/sh
Dtree:Usage:dtree [any directory]
dir=${1:-
1. When the shell script executes the Python script, you need to use the return value of the Python script to determine the command to be executed by the following program
Example: There are two py programs hello.py
Copy Code code as follows:
def main ():
Print "Hello"
If __name__== ' __main__ ':Main ()world.py
def main ():Print "Hello"
If __name__== ' __main__ ':Main ()
Shell
This article collects a bunch of shell scripting tricks, I said, I write a blog mainly to make some learning notes to facilitate their own review, so I will make such an article, there is nothing incomprehensible. About the origin of these techniques, eh, I also forget, may come from Theunixschool, Commandlinefu, cool and igigo.net, of course, there are some of my own experience, tube him, into my brain is my.
0.
in a pair of curly braces, defined as a function, no place to call the function, the code will not be executed, to achieve the same effect as the annotation. Example:
Copy Code code as follows:
Notexce () {
CP./a.txt./b.txt
mkdir-p {1,2,3}/{4,5,6}
echo "OK"
}
But if we need to comment on a large segment of the shell script, if we all add the # in front of each line, which is really not a very comfortable thing for us
I am a new Linux user. Now I need to clean up a download directory of files, in fact, I just want to delete from the ~/download/folder in addition to the following format files so other files:
1.*.iso-All documents in ISO format.2.*.zip-All files in zip format.
How do I delete a particular file in a bash shell based on a linux,os X or unix-like system?
The Bash shell supports rich file pattern matching c
the machine's 1/5/15 minute average load, and then multiply by 100.Shell code:
Copy Code code as follows:
Cpuload= (' cat/proc/loadavg | awk ' {print $1,$2,$3} ')
Load1=${cpuload[0]}
LOAD5=${CPULOAD[1]}
LOAD15=${CPULOAD[2]}
Second, memory acquisition
1). Application uses memoryAcquisition algorithm: Read/proc/meminfo file, (memtotal–memfree–buffers–cached)/1024 to get the number of applications using memory.Shell code:
The shell also has a real debug mode. If there are errors in the script "Strangescript", you can debug this:
Sh-x Strangescript
This executes the script and displays the values of all the variables.
The shell also has a pattern that does not need to execute a script just to check the syntax. You can use this:
Sh-n Your_script
This will return all syntax errors.
Linux/unix
Shell string comparisons, judging whether it's a number
Binary comparison operators, comparing variables or comparing numbers. Notice the difference between the number and the string.
Integer Comparisons
-eq equals, such as: if ["$a"-eq "$b"]
-ne is not equal to, such as: if ["$a"-ne "$b"]
-GT is greater than, such as: if ["$a"-gt "$b"]
-ge is greater than or equal to, such as: if ["$a"-ge "$b"]
-lt is less than, such as: if ["$a"-lt "$b"]
-le is
1. Preface
Almost six months did not write a blog, deserted for a long time, the work of the chores too much, their own more and more lazy. In order to spur their own growth, or adhere to write a blog, record their growth.
2. Introduction to Shell function
Grammar:
Copy Code code as follows:
[Function] funname [()]
{
Action
[Return int;]
}
Description
(1) can be defined with function fun () or directly fun (), without
The first method (Gzexe):
This type of encryption is not a very safe method, but can satisfy the general encryption use, can conceal the password in the script and so on information.It is the use of the system's own Gzexe program, it is not only encrypted, while compressing the file.How to use:
Copy Code code as follows:
Gzexe file.sh
It will be the original unencrypted files back to file.sh~, while file.sh is turned into encrypted files;
The second method (SHC):
Use SH
The content of this section:Keep the specified number of files remaining under the file system
Example:
Copy Code code as follows:
#!/bin/bash
#-------------------------------
#Description: Back Up your files
#site: Www.jb51.net
#-------------------------------
#shell variables
Path_source=/mnt/fifth/shell
Path_backup=/mnt/fifth/backup/shellbackup
path_delete=/mnt/fifth/tmp/rubbish/
1. The problem addressed
When you need to enter many commands at once, for example, to remove files from multiple directories at once
Copy Code code as follows:
CD Dir1
RM file1.temp
Cd.. /.. /dir2
RM-RF Dir3
When you don't bother typing a long command or simply can't remember that long command, such as generating ctags
Ctags--languages=c++--exclude=third_party--exclude=.git--exclude=build--exclude=out-r-F. tags
When you want a shortcut to a button to do repetitive
Many of the shell scripts executed with Cron may take a long time to execute for a variety of reasons, and it is necessary to check whether they are still running while running. This article provides a Linux shell script to check with the command sh ... To execute the shell script. To make a unique check on something else, you can modify the source code a little
I remember last year when I was looking for a job interview, I heard a classmate say that he likes Linux very much, I believe what he said is true, I think the people who like Linux are very happy from the shell script, because it can integrate the various resources on Linux to do great things. Here's a picture crawler that you can share with the next shell script.How to use:Copy the following code, named I
A, Shell conditional statement (if usage)
If statement structure [IF/THEN/ELIF/ELSE/FI]
Copy Code code as follows:
If condition test statement
Then
Action
[Elif condition
Action
Else
Action
]
Fi
If you are not very clear about: conditional test statements, you can refer to: Linux shell logical operators, logical expression of the detailed
The reason for bad interpreter:no such file or directory is the file format problem. This file is written under Windows. Line-wrapping is not the same as UNIX, but under vim if it is not set it is completely invisible.Problem Analysis:1, will be prepared under Windows shell file, uploaded to Linux under the implementation, prompted error.2, error message: Bad interpreter: no file or directory.
Problem Reason:Because the operating system is windows, t
In general, we only need to monitor the program process in the not on it. But this time, the company developed the program, the process is still in, but the deadlock. Lead to a wide range of effects, but even more importantly, do not know where the problem is, or other Test department colleagues to help find, really throw the face of the Victoria.In order to avoid the next encounter such a situation, analysis of the process deadlock phenomenon, found that the deadlock will occupy 100% of the CPU
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.