This is a script for clearing system logs:
Vim logmess_clean.sh
# Bin/bash // shell interpreter used by the script
Cd/var/log // switch to the log storage directory
Echo> messages // clear logs
Echo "logmessages is clean" // output "log clearing" after script execution is complete"
[Root @ localhost shellscripts] # ll view the script permission
Total 4-rw-r --. 1 root 67 May 26 logmess_clean.sh // The script written by default is not executable.
Chmod + x logmess_clean.sh
[Root @ localhost shellscripts] #./logmess_clean.sh logmessages is clean run this script:
# Cat/var/log/messages check that the script is successfully executed:
If you do not want to input./or sh to execute the script, you want to execute scriprt anywhere in the system. Move the script to the PATH environment variable:
[Root @ localhost shellscripts] # echo $ PATH // view the PATH of the current system shell environment variable/usr/lib/qt-3.3/bin:/usr/local/sbin: /usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[Root @ localhost shellscripts] # mv logmess_clean.sh/bin // move the script to the variable path
[Root @ localhost ~] # Logmess_clean.sh // execute the script
Logmessages is clean
You can also configure the environment variable path:
[Root @ localhost ~] # Vim/root/. bash_profile // edit the current environment variable after the system
PATH = $ PATH: $ HOME/bin:/shellscripts/
[Root @ localhost ~] # Logmess_clean.sh
Logmessages is clean
Root/. bash_profile is one of the three environment variable setting files in linux, and the scope of this environment variable is only for the current user.
After the modification is complete, the system has recorded the/bin path, and we need to disconnect the connection. to take effect immediately, run the following statement: # source. bash_profile
You can also edit the. bashrc environment variable file.
Modify the. bash File
[Root @ localhost/] # vi/root/. bashrc
#. Bashrc
# User specific aliases and functions
Alias rm = rm-I
Alias cp = cp-I
Alias mv = mv-I
# Source global definitions if [-f/etc/bashrc]; then./etc/bashrc fi
Export PATH = "$ PATH:/shellscripts/" // Add this row