The Shell Common Command summary under the Linux server

Source: Internet
Author: User
Tags md5 win32 iptables

1.   Find
       find Pathname-options [-print-exec-ok]
 & nbsp;     Let's take a look at the parameters of the command: The directory path that the
       pathname Find command is looking for. For example, to represent the current directory, with/to represent the system root directory. The
      -print find command outputs matching files to standard output. The
      -exec Find command executes the shell command given by the parameter to the matching file. The corresponding command is in the form of ' command ' {};, note the space between {} and; there are no spaces between two {},
       Note there must be a semicolon ending.
       0)-ok and-exec have the same effect, but in a more secure mode to execute the shell command given by the parameter, the prompts are given before each command is executed, Let the user determine if the
       find.-name "datafile"-ctime-1-exec ls-l {} is executed, and the file name datafile* is found. Create files that are actually within 1 days, and then display their details.
       find.-name "datafile"-ctime-1-exec rm-f {}; Locate file name datafile*, and create an actual 1-day Files, and then delete them.

Find. -name "DataFile"-ctime-1-ok ls-l {}; The only difference between these two examples and above is that-OK will be more secure when each file is prompted to execute the command.
Find. -name "DataFile"-ctime-1-ok rm-f {};

1) Find. -name is based on the file name lookup, but the file name is case-sensitive.
Find. -name "datafile*"

2) Find. -iname is based on the 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 find searches for a directory depth of 2 (from the current directory), where the current directory is considered the first level.

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./RW and their subdirectories under file name datafile*.
Find. -path "./dir*" lists all files that match dir* directories and their directories.
Find. (-path "./d1"-o-path "./d2")-prune-o-name "datafile*" lists all files that are not in the./d1 and D2 and their subdirectories with file name datafile*.

6) Find. -user Ydev Find all files that are owned by the main user Ydev.
Find. ! -user Ydev Find all files that are not Ydev by the main user, notice the spaces between the-user.

7) Find. -nouser find all files that are not owned by the main user, in other words, the main user may have been deleted.

8) Find. -group Ydev Find all files that are Ydev for the primary user group.

9) Find. -nogroup find all files that are not part of the primary user group, in other words, the primary user group may have been deleted.

Find. -MTIME-3[+3] Find a file that modifies the time within 3rd [beyond].
Find. -MMIN-3[+3] Find files that modify the data time within 3 minutes [outside].
Find. -ATIME-3[+3] Find the documents that visit the time within 3rd [outside].
Find. -AMIN-3[+3] Find a file that has access time within 3 minutes [outside].
Find. -CTIME-3[+3] Find files that modify the state time within 3rd [outside].
Find. -CMIN-3[+3] Find files that modify the state time within 3 minutes [outside].

One) find. -newer Eldest_file! -newer Newest_file to find out when the file was 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 to find all files older than file's change time

Find. -type D finds files of the file type as a directory.
Find. ! -type D finds files of a file type that are not directory.
B-block device files.
D-Directory.
C-Character device files.
P-pipe file.
L-Symbolic link file.
F-Normal files.

Find. -size [+/-]100[c/k/m/g] represents a file with a length equal to [greater than/less than] 100 [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 initiate a new process to perform-exec operations for each file that is searched, while 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 minutes 1~59
2nd hour 1~23 (0 means midnight)
3rd Liege 1~31
4th Month 1~12
5th week 0~6 (0 for Sunday)
6th column the command to run

Time-Sharing Week the command to run

21* * */apps/bin/cleanup.sh
The above example shows the cleanup.sh of the 21:30 running/apps/bin directory per night.
4 1,10,22 * */apps/bin/backup.sh
The above example shows the backup.sh in the 1, 10, and 22nd of the 4:45 running/apps/bin directory each month.
1 * * 6,0/bin/find-name "core"-exec rm {};
The above example shows that every Saturday, Sunday 1:10 runs a find command.
0,30 18-23 * * * */apps/bin/dbcheck.sh
The example above shows running the dbcheck.sh in the/apps/bin directory every 30 minutes between 18:00 and 23:00 every day.
0 * * 6/apps/bin/qtrend.sh
The above example shows the qtrend.sh of the 11:00pm running/apps/bin directory every Saturday.

-u user name.
-E To edit the crontab file.
-l lists the contents of the crontab file.
-R Deletes the crontab file.
The system will automatically save the cron execution script named <username> in the/var/spool/cron/directory.
Cron is a timed task, and when the task is started, it is generally a new shell to restart, so it is cumbersome to use the information of the login profile, especially the environment variables.
Generally, the 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 plan to execute more than one statement, you should use semicolons to split them. Note: The above statement must be executed under the account root.

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 process after you exit the account.
Nohup means not to hang (no hang up).

4. Cut:
1 Cut general format is: Cut [options] file1 file2
-C list Specifies the number of cut characters.
The-f field specifies the number of clipping fields.
-d Specifies a field separator 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-cut 2nd to last character
-c-5 cut the start to the 5th character
-C1-50 cut the first 50 characters.
The-f format is the same as-C.
-f1,5 Cut the 1th field, the 5th field.
-f1,10-12 Cut the 1th field, the 10th field to the 12th field.
2) The way to use:
cut-d:-f3 Cut_test.txt (based on ":" As the delimiter, returning the data in field 3) *field calculated from 0.
cut-d:-f1,3 Cut_test.txt (based on ":" As a separator, returning data in field 1 and 3 at the same time)
cut-d:-c1,5-10 cut_test.txt (return 1th and 第5-10个 characters)

5. Sort:
1 to sort the contents of the file, the default delimiter is a space, if the customization needs to use the-t option, such as-t:
2 after using the delimiter partition, the first field is 0,awk 1
3) The specific usage is as follows:
SORT-T: Sort_test.txt (the default is sorted based on the first field, and the separator between field is ":")
SORT-T:-R sort_test.txt (the default is sorted in reverse order based on the first field, and the separator between field is ":")
SORT-T: +1 sort_test.txt (sorted based on the second field, the separator between field is ":")
Sort +3n Sort_test.txt (sorted based on the third field where the N option hint is sorted numerically)
Sort-u sort_test.txt (removes duplicate rows in a file and sorts them based on the entire row)
Sort-o output_file-t: +1.2[n] Sort_text.txt (based on the second field and starting with the second character of the field, where N is also a "numeric" sort and outputs the result to output_file)
Sort-t:-M +0 filename1 filename2 (after merging two files, sorted 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&
1000
/> Sleep 100&
1001

/> Pgrep Sleep
1000
1001
/> pgrep-d: Sleep # D defines the separator 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 multiple processes, find the oldest.
1000
/> pgrep-g root,oracle Sleep # G indicates that the process's group ID will be considered in the list of groups following the-G
1000
1001
/> pgrep-u root,oracle Sleep #-U indicates that the process's effetive user ID will be considered in the group list after-u
1000
1001
/> pgrep-u root,oracle Sleep #-U indicates that the process's real user ID will be considered in the group list after-u
1000
1001
/> Pgrep-x Sleep # x indicates that the name of the process must match exactly, and the above examples can be partially matched
1000
1001
/> Pgrep-x SLE

/> Pgrep-l Sleep #-L will not only print the PID, but also print the process name
1000 Sleep
1001 Sleep
/> PGREP-LF Sleep #-F General and-L, will print process parameters
1000 Sleep 100
1001 Sleep 100

/> Pgrep-f sleep-d, | Xargs PS-FP
UID PID PPID C stime TTY time CMD
Root 1000 2138 0 06:11 pts/5 00:00:00 Sleep 1000
Root 1001 2138 0 06:11 pts/5 00:00:00 Sleep 1000

7. Fuser:
Fuser-m/Dev # lists the process PID for all the/dev devices.
Fuser testfile # List and testfile the process of the affair PID
Fuser-u testfile # List and testfile the process of the affair PID and UserID
Fuser-k testfile # Kill and testfile the process of the 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 # Uninstall the mount.

9. Netstat:

-A indicates that all states are displayed
-L only shows the listen state, the default is to show connected
-P Displays the name of the application
-n displays information such as IP, port, and user
-T show TCP connections only
/> Netstat-apnt
/> Netstat-lpnt #如果只是显示监听端口的状态, you can use this command

TUNE2FS:

Tools for adjusting EXT2/EXT3 file system features

-L View File system Information
/> Tune2fs-l/dev/sda1 #将会列出所有和该磁盘分区相关的数据信息, such as inode and so on.
/> Tune2fs-l/dev/sda1 | Grep-i "Block Size" #查看当前文件系统的块儿尺寸
/> tune2fs-l/dev/sdb1 |grep-i "mount Count" #查看 mount Count Mount Times

11. Turn Linux on or off (iptables) firewall
Permanent entry after reboot:
/> Chkconfig iptables on #开启
/> Chkconfig iptables off #关闭

Immediate effective, reboot after restore:
/> Service iptables Start #开启
/> Service iptables Stop #关闭


Tar sub-volume compression and consolidation
Take 500M per roll as an 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
/> Mans Tcsh | Col-b > Tcsh.txt
/> Info Tcsh-o tcsh.txt-s


14. View the number of threads executing the process
/>ps-eo "args nlwp pid pcpu"

15. Use Md5sum to compute the MD5 of the file
/> md5sum test.c
07af691360175a6808567e2b08a11724 test.c

     /> md5sum test.c > Hashfile
     /> md5sum–c hashfile     # verifies that the MD5 value and corresponding file contained in Hashfile are still matched when the command is executed, and that the command returns a mismatched warning if test.c is modified at this time

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.