1. Find
Find Pathname-options [-print-exec-ok]
Let's take a look at the parameters of the command:
Pathname the directory path found by the Find command. For example, use. To represent the current directory, and/to represent the system root directory.
The-print find command outputs the matched file to standard output.
The-exec find command executes the shell command given by this parameter to the matching file. The corresponding command is in the form of ' command ' {} \; Note the space between {} and \; and there are no spaces between two {}.
Note that there must be a semicolon ending.
0) The-ok and-exec function the same, except that the shell command given by the parameter is executed in a more secure mode, and before each command is executed, a prompt is given to let the user determine whether to execute
Find. -name "DataFile"-ctime-1-exec ls-l {} \; Locate the file named Datafile*, and create a file that is actually within 1 days, and then display their details.
Find. -name "DataFile"-ctime-1-exec rm-f {} \; Locate the file named Datafile*, and create the files that are actually within 1 days, and then delete them.
Find. -name "DataFile"-ctime-1-ok ls-l {} \; The only difference between the two examples and the above is that-ok will prompt the user for more security when each file is executed.
Find. -name "DataFile"-ctime-1-ok rm-f {} \;
1) Find. -name is based on file name lookup, but the file name is case sensitive.
Find. -name "datafile*"
2) Find. -iname is based on file name lookup, but the file name is not case sensitive.
Find. -iname "datafile*"
3) Find. -maxdepth 2-name Fred finds the file named Fred, where the directory depth of the Find search is 2 (from the current directory), where the current directory is considered the first layer.
4) Find. -perm 644-maxdepth 3-name "datafile*" (indicates a permission of 644, the search directory depth is 3, the name is datafile* file)
5) Find. -path "./rw"-prune-o-name "datafile*" lists all files that are not in the./RW and its subdirectories under the file name datafile*.
Find. -path "./dir*" lists all files that conform to the dir* directory and their directories.
Find. \ (-path "./d1"-o-path "./d2" \)-prune-o-name "datafile*" lists all files that are not in./d1 and D2 and their subdirectories under the file name datafile*.
6) Find. -user Ydev Find all files that belong to the master user Ydev.
Find. ! -user Ydev Find all the files that belong to the main user not Ydev, note the space between and-user.
7) Find. -nouser find all files that are not owned by the main user, in other words, the primary user may have been deleted.
8) Find. -group Ydev Find all files that belong to the main user group Ydev.
9) Find. -nogroup find all files that are not part of the main user group, in other words, the primary user group may have been deleted.
(Ten) Find. -MTIME-3[+3] Find files that modify the data time within 3rd [].
Find. -MMIN-3[+3] Find files that modify data time within 3 minutes [].
Find. -ATIME-3[+3] Find files that have access time within 3rd [].
Find. -AMIN-3[+3] Find files that have access time within 3 minutes [].
Find. -CTIME-3[+3] Find files that modify the status time within 3rd [].
Find. -CMIN-3[+3] Find files that modify the status time within 3 minutes [].
One) find. -newer Eldest_file! -newer Newest_file Find out when the file changed between Eldest_file and Newest_file.
Find. -newer file to find all files that are newer than the change time of file
Find. ! -newer file finds all files that are older than the change time of file
) Find. -type d Find files with file type directory.
Find. ! -type d Find files with a file type other than directory.
B-block device files.
D-Directory.
C-character device file.
P-Pipeline file.
L-Symbolic link file.
F-Normal file.
) Find. -size [+/-]100[c/k/m/g] represents a file with a length equal to [greater than/less than] 100 blocks [byte/k/m/g].
) Find. -empty find all empty files or empty directories.
) Find. -type F | Xargs grep "ABC"
The difference between using Xargs and-exec is that-exec may start a new process for each file that is searched for-exec operations, and Xargs is done in one process and is more efficient.
2. Crontab:
The file format is as follows (each column is separated by a space):
1th column min 1~59
2nd Hour 1~23 (0 = midnight)
3rd Liege 1~31
4th Column Month 1~12
5th Column Week 0~6 (0 = Sunday)
6th List of commands to run
Time-sharing day and month command to run
21* * */apps/bin/cleanup.sh
The above example indicates that the/apps/bin directory is running at the cleanup.sh of 21:30 per night.
4 1,10,22 * */apps/bin/backup.sh
The above example shows the backup.sh in the 1, 10, and 22nd 4:45 runs of the/apps/bin directory.
1 * * 6,0/bin/find-name "core"-exec rm {} \;
The above example shows that 1:10 runs a find command every Saturday and Sunday.
0,30 18-23 * * */apps/bin/dbcheck.sh
The above example shows that the dbcheck.sh in the/apps/bin directory runs every 30 minutes from 18:00 to 23:00 every day.
0 * * 6/apps/bin/qtrend.sh
The above example shows the 11:00pm running the/apps/bin directory qtrend.sh every Saturday.
-u user name.
-e Edit the crontab file.
-l lists the contents of the crontab file.
-R Delete the crontab file.
The cron execution script named <username> is automatically saved in the/var/spool/cron/directory.
Cron is a scheduled task, and when the task starts, it is generally a new shell restart, so it is cumbersome to use the information of the login configuration file, especially the environment variables.
The general use of this problem is as follows:
0 2 * * * (su-username-c "Export lang=en_us; /home/oracle/yb2.5.1/apps/admin/1.sh "; ) >/tmp/1.log 2>&1
If you intend to execute more than one statement, they should be split with semicolons. Note: The above statement must be executed under root account.
3. Nohup:
Nohup Command &
If you are running a process and you feel that the process will not end when you exit the account, you can use the Nohup command. This command can continue to run the appropriate process after you exit the account.
Nohup is the meaning of not hanging (no hang up).
4. Cut:
1) Cut General format: cut [options] file1 file2
The-c list specifies the number of cut characters.
The-f field specifies the number of clipping fields.
-d Specifies a field delimiter that differs from the Space and tab keys.
-C is used to specify the clipping range as follows:
-c1,5-7 cuts the 1th character, then the 5th to the 7th character.
-c2-clipping 2nd to last character
-c-5 clipping from the beginning to the 5th character
-c1-50 the first 50 characters of the cut.
The-f format is the same as-C.
-f1,5 Clipping 1th field, 5th field.
-f1,10-12 cuts the 1th field, the 10th field to the 12th field.
2) How to use:
cut-d:-f3 Cut_test.txt (based on ":" As the delimiter, returning data from Field 3) *field is calculated starting from 0.
cut-d:-f1,3 Cut_test.txt (based on ":" As delimiter, returning data from Field 1 and 3)
cut-d:-c1,5-10 cut_test.txt (return 1th and 第5-10个 characters)
5. Sort:
1) Sort the contents of the file, the default delimiter is a space, if custom needs to use the-t selection, such as-t:
2) After splitting with delimiters, the first field is 1 in 0,awk
3) The specific usage is as follows:
SORT-T: Sort_test.txt (the default is based on the first field and the delimiter between the field is ":")
SORT-T:-R sort_test.txt (the default is based on the first field in reverse order, the delimiter between the field is ":")
SORT-T: +1 sort_test.txt (sorted based on the second field, the delimiter between the field is ":")
Sort +3n Sort_test.txt (sorted based on the third field, where N option tip is "numeric" sort)
Sort-u sort_test.txt (removes duplicate rows from the file and sorts based on the entire row)
Sort-o output_file-t: +1.2[n] Sort_text.txt (based on the second field, starting with the second character of the field, where N is the "numeric" sort and outputs the result to output_file)
Sort-t:-M +0 filename1 filename2 (after merging two files in order based on first field)
6. Pgrep and Pkill:
Find and kill the specified process, their options and parameters are exactly the same, here is just an introduction to Pgrep
/> Sleep 100&
+
/> Sleep 100&
1001
/> Pgrep Sleep
+
1001
/> pgrep-d: Sleep #-D defines delimiters between multiple processes and uses newline if not defined
1000:1001
/> Pgrep-n Sleep #-n indicates that if the program has more than one process, find the latest.
1001
/> Pgrep-o Sleep #-O indicates that if the program has more than one process, look for the oldest.
+
/> pgrep-g root,oracle Sleep #-G indicates that the process's group ID will be considered in the list of groups after-G
+
1001
/> pgrep-u root,oracle Sleep #-U indicates that the process's effetive user ID in the group list after-U is considered
+
1001
/> pgrep-u root,oracle Sleep #-U indicates that the process's real user ID in the group list after-U is considered
+
1001
/> Pgrep-x Sleep #-X indicates that the process name must match exactly, and the above examples can be partially matched
+
1001
/> Pgrep-x SLE
/> Pgrep-l Sleep #-L will not only print the PID, but also print the process name
Sleep
1001 Sleep
/> PGREP-LF Sleep #-F is commonly shared with-L, which will print the parameters of the process
Sleep
1001 Sleep
/> Pgrep-f sleep-d, | Xargs PS-FP
UID PID PPID C stime TTY time CMD
root 2138 0 06:11 pts/5 00:00:00 sleep
root 1001 2138 0 06:11 pts/5 00:00:00 sleep
7. Fuser:
Fuser-m/Dev # lists all the process PID that are involved with the/dev device.
Fuser testfile # Lists and testfile the process of an affair PID
Fuser-u testfile # Lists and testfile the process of an affair PID and UserID
Fuser-k testfile # Killing and testfile the process of an affair PID
8. Mount:
How to mount a shared directory under Windows under UNIX
Mount-t Smbfs-o Username=username,password=password//windowsip/pub_directory/mountpoint
/> Mkdir-p/mnt/win32
/> Mount-o username=administrator,password=1234//10.1.4.103/mine/mnt/win32
/> Umount/mnt/win32 # unload the mount.
9. Netstat:
-A indicates that all states are displayed
-L only displays the listen state, and the default is only to display connected
-P Displays the name of the application
-n displays information such as IP, port, and user
-T shows only TCP connections
/> Netstat-apnt
/> Netstat-lpnt #如果只是显示监听端口的状态, you can use this command
TUNE2FS:
Tools to adjust Ext2/ext3 file system features
-L View File system Information
/> Tune2fs-l/dev/sda1 #将会列出所有和该磁盘分区相关的数据信息, such as the inode.
/> Tune2fs-l/dev/sda1 | Grep-i "Block Size" #查看当前文件系统的块儿尺寸
/> tune2fs-l/dev/sdb1 |grep-i "mount Count" #查看 Mount Count Mount number
11. Turn on or off the Linux (iptables) firewall
Permanent after reboot:
/> Chkconfig iptables on #开启
/> Chkconfig iptables off #关闭
Immediate effect, restore after reboot:
/> Service iptables Start #开启
/> Service iptables Stop #关闭
Tar sub-volume compression and consolidation
Take 500M per reel for example
/>tar Cvzpf-somedir | Split-d-B 500m #tar分卷压缩
/>cat x* > Mytarfile.tar.gz #tar多卷合并
13. Save the information of man or info as a text file
/> Man Tcsh | Col-b > Tcsh.txt
/> Info Tcsh-o tcsh.txt-s
14. View the number of threads executing a process
/>ps-eo "args nlwp pid pcpu"
15. Using Md5sum to calculate the MD5 of a file
/> md5sum test.c
07af691360175a6808567e2b08a11724 test.c
/> md5sum test.c > Hashfile
/> Md5sum–c Hashfile # verifies that the MD5 value contained in the Hashfile and the corresponding file are still matched when the command is executed, and if TEST.C is modified at this point, the command returns a warning that does not match.
16. Display the full command-line arguments of the process in the PS command
/>ps auwwx
Chkconfig:
1). Edit the shell file header of the chkconfig operation.
#!/bin/bash
#
# chkconfig:2345 20 80
# Description:starts and stops the Redis Server
This annotation header is very important, otherwise the chkconfig command is not recognized. Where 2345 represents the level at which Init starts, that is, the service is started in the 5 levels of 2, 3, 4, four. 20 indicates the priority that the script starts, and 80 indicates the priority of the stop. These can be found in the manpage of chkconfig for more detailed instructions.
2). Compile the contents of the shell file:
Case "$" in
Start
#TODO: Executes the startup logic of the service program.
;;
Stop
#TODO: Executes the stop logic of the service program.
;;
Restart
;;
Reload
;;
Condrestart)
;;
Status
;;
The case conditions listed above are necessary, if not really, as placeholders, as in the example above.
3). Add and remove service programs:
The #--add option indicates the addition of a new service program.
/> Chkconfig--add redis_6379
#查看是否删除或添加成功
/> Chkconfig | grep redis_6379
redis_6379 0:off 1:off 2:on 3:on 4:on 5:on 6:off
The #--del option means that the existing service program is deleted.
/> Chkconfig--del redis_6379