已经找到“” 的记录352条
Linux crontab 命令

Linux crontab 命令

Linux 命令大全 Linux 命令大全

Linux crontab 是用来定期执行程序的命令。

当安装完成操作系统之后,默认便会启动此任务调度命令。

crond 命令每分钟会定期检查是否有要执行的工作,如果有要执行的工作便会自动执行该工作。

注意:新创建的 cron 任务,不会马上执行,至少要过 2 分钟后才可以,当然你可以重启 cron 来马上执行。

而 linux 任务调度的工作主要分为以下两类:

  • 1、系统执行的工作:系统周期性所要执行的工作,如备份系统数据、清理缓存
  • 2、个人执行的工作:某个用户定期要做的工作,例如每隔 10 分钟检查邮件服务器是否有新信,这些工作可由每个用户自行设置

语法

crontab [ -u user ] file

crontab [ -u user ] { -l | -r | -e }

说明:

crontab 是用来让使用者在固定时间或固定间隔执行程序之用,换句话说,也就是类似使用者的时程表。

-u user 是指设定指定 user 的时程表,这个前提是你必须要有其权限(比如说是 root)才能够指定他人的时程表。如果不使用 -u user 的话,就是表示设定自己的时程表。

参数说明

  • -e : 执行文字编辑器来设定时程表,内定的文字编辑器是 VI,如果你想用别的文字编辑器,则请先设定 VISUAL 环境变数来指定使用那个文字编辑器(比如说 setenv VISUAL joe)
  • -r : 删除目前的时程表
  • -l : 列出目前的时程表

时间格式如下:

f1 f2 f3 f4 f5 program
  • 其中 f1 是表示分钟,f2 表示小时,f3 表示一个月份中的第几日,f4 表示月份,f5 表示一个星期中的第几天。program 表示要执行的程序。
  • 当 f1 为 * 时表示每分钟都要执行 program,f2 为 * 时表示每小时都要执行程序,其馀类推
  • 当 f1 为 a-b 时表示从第 a 分钟到第 b 分钟这段时间内要执行,f2 为 a-b 时表示从第 a 到第 b 小时都要执行,其馀类推
  • 当 f1 为 */n 时表示每 n 分钟个时间间隔执行一次,f2 为 */n 表示每 n 小时个时间间隔执行一次,其馀类推
  • 当 f1 为 a, b, c,... 时表示第 a, b, c,... 分钟要执行,f2 为 a, b, c,... 时表示第 a, b, c...个小时要执行,其馀类推
*    *    *    *    *
-    -    -    -    -
|    |    |    |    |
|    |    |    |    +----- 星期中星期几 (0 - 6) (星期天 为0)
|    |    |    +---------- 月份 (1 - 12) 
|    |    +--------------- 一个月中的第几天 (1 - 31)
|    +-------------------- 小时 (0 - 23)
+------------------------- 分钟 (0 - 59)

使用者也可以将所有的设定先存放在文件中,用 crontab file 的方式来设定执行时间。

实例

每一分钟执行一次 /bin/ls:

* * * * * /bin/ls

在 12 月内, 每天的早上 6 点到 12 点,每隔 3 个小时 0 分钟执行一次 /usr/bin/backup:

0 6-12/3 * 12 * /usr/bin/backup

周一到周五每天下午 5:00 寄一封信给 alex@domain.name:

0 17 * * 1-5 mail -s "hi" alex@domain.name < /tmp/maildata

每月每天的午夜 0 点 20 分, 2 点 20 分, 4 点 20 分....执行 echo "haha":

20 0-23/2 * * * echo "haha"

下面再看看几个具体的例子:

0 */2 * * * /sbin/service httpd restart  意思是每两个小时重启一次apache 

50 7 * * * /sbin/service sshd start  意思是每天7:50开启ssh服务 

50 22 * * * /sbin/service sshd stop  意思是每天22:50关闭ssh服务 

0 0 1,15 * * fsck /home  每月1号和15号检查/home 磁盘 

1 * * * * /home/bruce/backup  每小时的第一分执行 /home/bruce/backup这个文件 

00 03 * * 1-5 find /home "*.xxx" -mtime +4 -exec rm {} \;  每周一至周五3点钟,在目录/home中,查找文件名为*.xxx的文件,并删除4天前的文件。

30 6 */10 * * ls  意思是每月的1、11、21、31日是的6:30执行一次ls命令

注意:当程序在你所指定的时间执行后,系统会发一封邮件给当前的用户,显示该程序执行的内容,若是你不希望收到这样的邮件,请在每一行空一格之后加上 > /dev/null 2>&1 即可,如:

20 03 * * * . /etc/profile;/bin/sh /var/www/runoob/test.sh > /dev/null 2>&1 

脚本无法执行问题

如果我们使用 crontab 来定时执行脚本,无法执行,但是如果直接通过命令(如:./test.sh)又可以正常执行,这主要是因为无法读取环境变量的原因。

解决方法:

  • 1、所有命令需要写成绝对路径形式,如: /usr/local/bin/docker

  • 2、在 shell 脚本开头使用以下代码:

    #!/bin/sh
    
    . /etc/profile
    . ~/.bash_profile

    3、在 /etc/crontab 中添加环境变量,在可执行命令之前添加命令 . /etc/profile;/bin/sh,使得环境变量生效,例如:

    20 03 * * * . /etc/profile;/bin/sh /var/www/runoob/test.sh

    Linux 命令大全 Linux 命令大全

Linux clock命令

Linux clock命令

Linux 命令大全 Linux 命令大全

Linux clock命令用于调整 RTC 时间。

RTC 是电脑内建的硬件时间,执行这项指令可以显示现在时刻,调整硬件时钟的时间,将系统时间设成与硬件时钟之时间一致,或是把系统时间回存到硬件时钟。

语法

clock [--adjust][--debug][--directisa][--getepoch][--hctosys][--set --date="<日期时间>"][--setepoch --epoch=< >][--show][--systohc][--test][--utc][--version]

参数说明

  • --adjust  第一次使用"--set"或"--systohc"参数设置硬件时钟,会在/etc目录下产生一个名称为adjtime的文件。当再次使用这两个参数调整硬件时钟,此文件便会记录两次调整间之差异,日后执行clock指令加上"--adjust"参数时,程序会自动根 据记录文件的数值差异,计算出平均值,自动调整硬件时钟的时间。
  • --debug  详细显示指令执行过程,便于排错或了解程序执行的情形。
  • --directisa  告诉clock指令不要通过/dev/rtc设备文件,直接对硬件时钟进行存取。这个参数适用于仅有ISA总线结构的老式电脑。
  • --getepoch  把系统核心内的硬件时钟新时代数值,呈现到标准输出设备。
  • --hctosys  Hardware Clock to System Time,把系统时间设成和硬件时钟一致。由于这个动作将会造成系统全面更新文件的存取时间,所以最好在系统启动时就执行它。
  • --set--date  设置硬件时钟的日期和时间。
  • --setepoch--epoch=<年份>  设置系统核心之硬件时钟的新时代数值,年份以四位树字表示。
  • --show  读取硬件时钟的时间,并将其呈现至标准输出设备。
  • --systohc  System Time to Hardware Clock,将系统时间存回硬件时钟内。
  • --test  仅作测试,并不真的将时间写入硬件时钟或系统时间。
  • --utc  把硬件时钟上的时间时为CUT,有时也称为UTC或UCT。
  • --version  显示版本信息。

实例

获取当前的时间

# clock //获取当前的时间

显示UTC时间

# clock -utc //显示UTC时间

Linux 命令大全 Linux 命令大全

Linux chroot 命令

Linux chroot 命令

Linux 命令大全 Linux 命令大全

Linux chroot (英文全称:change root) 命令用于改变根目录。

chroot 命令把根目录换成指定的目的目录。

语法

chroot [--help][--version][目的目录][执行指令...]

参数说明

  • --help  在线帮助。
  • --version  显示版本信息。

实例

改变根目录

# chroot /mnt/ls //改变根目录

Linux 命令大全 Linux 命令大全

Linux bind命令

Linux bind命令

Linux 命令大全 Linux 命令大全

Linux bind命令用于显示或设置键盘按键与其相关的功能。

您可以利用bind命令了解有哪些按键组合与其功能,也可以自行指定要用哪些按键组合。

语法

bind [-dlv][-f <按键配置文件>][-m <按键配置>][-q <功能>]

参数说明

  • -d  显示按键配置的内容。
  • -f<按键配置文件>  载入指定的按键配置文件。
  • -l  列出所有的功能。
  • -m<按键配置>  指定按键配置。
  • -q<功能>  显示指定功能的按键。
  • -v  列出目前的按键配置与其功能。

实例

显示按键组合的所有功能

# bind -l //显示按键组合的内容
abort
accept-line
alias-expand-line
arrow-key-prefix
backward-byte
backward-char
backward-delete-char
backward-kill-line
backward-kill-word
backward-word
beginning-of-history
beginning-of-line
……省略部分内容
vi-goto-mark
vi-insert-beg
vi-insertion-mode
vi-match
vi-movement-mode
vi-next-word
vi-overstrike
vi-overstrike-delete
vi-prev-word
vi-put
vi-redo
vi-replace
vi-rubout
vi-search
vi-search-again
vi-set-mark
vi-subst
vi-tilde-expand
vi-yank-arg
vi-yank-to
yank
yank-last-arg
yank-nth-arg
yank-pop

显示当前按键组合的设置

# bind -l
abort
accept-line
alias-expand-line
arrow-key-prefix
backward-byte
backward-char
backward-delete-char
backward-kill-line
backward-kill-word
backward-word
beginning-of-history
beginning-of-line
call-last-kbd-macro
capitalize-word
character-search
character-search-backward
clear-screen
complete
complete-command
complete-filename
complete-hostname
complete-into-braces
complete-username
complete-variable
copy-backward-word
copy-forward-word
copy-region-as-kill
dabbrev-expand
delete-char
delete-char-or-list
delete-horizontal-space
digit-argument
display-shell-version
do-lowercase-version
downcase-word
dump-functions
dump-macros
dump-variables
dynamic-complete-history
edit-and-execute-command
emacs-editing-mode
end-kbd-macro
end-of-history
end-of-line
exchange-point-and-mark
forward-backward-delete-char
forward-byte
forward-char
forward-search-history
forward-word
glob-complete-word
glob-expand-word
glob-list-expansions
history-and-alias-expand-line
history-expand-line
history-search-backward
history-search-forward
insert-comment
insert-completions
insert-last-argument
kill-line
kill-region
kill-whole-line
kill-word
magic-space
menu-complete
menu-complete-backward
next-history
non-incremental-forward-search-history
non-incremental-forward-search-history-again
non-incremental-reverse-search-history
non-incremental-reverse-search-history-again
old-menu-complete
operate-and-get-next
overwrite-mode
possible-command-completions
possible-completions
possible-filename-completions
possible-hostname-completions
possible-username-completions
possible-variable-completions
previous-history
quoted-insert
redraw-current-line
re-read-init-file
reverse-search-history
revert-line
self-insert
set-mark
shell-backward-kill-word
shell-backward-word
shell-expand-line
shell-forward-word
shell-kill-word
skip-csi-sequence
start-kbd-macro
tab-insert
tilde-expand
transpose-chars
transpose-words
tty-status
undo
universal-argument
unix-filename-rubout
unix-line-discard
unix-word-rubout
upcase-word
vi-append-eol
vi-append-mode
vi-arg-digit
vi-back-to-indent
vi-bword
vi-bWord
vi-change-case
vi-change-char
vi-change-to
vi-char-search
vi-column
vi-complete
vi-delete
vi-delete-to
vi-editing-mode
vi-end-word
vi-eof-maybe
vi-eword
vi-eWord
vi-fetch-history
vi-first-print
vi-fword
vi-fWord
vi-goto-mark
vi-insert-beg
vi-insertion-mode
vi-match
vi-movement-mode
vi-next-word
vi-overstrike
vi-overstrike-delete
vi-prev-word
vi-put
vi-redo
vi-replace
vi-rubout
vi-search
vi-search-again
vi-set-mark
vi-subst
vi-tilde-expand
vi-yank-arg
vi-yank-to
yank
yank-last-arg
yank-nth-arg
yank-pop
root@snail-hnlinux:~# 
root@snail-hnlinux:~# 
root@snail-hnlinux:~# 
root@snail-hnlinux:~# 
root@snail-hnlinux:~# bind -v
set bind-tty-special-chars on
set blink-matching-paren on
set byte-oriented off
set completion-ignore-case off
set convert-meta off
set disable-completion off
set echo-control-characters on
set enable-keypad off
set enable-meta-key on
set expand-tilde off
set history-preserve-point off
set horizontal-scroll-mode off
set input-meta on
set mark-directories on
set mark-modified-lines off
set mark-symlinked-directories off
set match-hidden-files on
set meta-flag on
set output-meta on
set page-completions on
set prefer-visible-bell on
set print-completions-horizontally off
set revert-all-at-newline off
set show-all-if-ambiguous off
set show-all-if-unmodified off
set skip-completed-text off
set visible-stats off
set bell-style audible
set comment-begin #
set completion-prefix-display-length 0
set completion-query-items 100
set editing-mode emacs
set history-size 1000
set keymap emacs

列出指定功能的按键和按键组合

# bind -q abort
//请用 调用abort “C-g”, “C-xC-g”, “eC-g”.

# bind -q accept-line //列出功能“accept-line”按键以及组合按键
//请用 调用accept-line “C-j”, “C-m”.

Linux 命令大全 Linux 命令大全

Linux aumix命令

Linux aumix命令

Linux 命令大全 Linux 命令大全

Linux aumix命令用于设置音效装置。

aumix(audio mixer)命令设置各项音效装置的信号强度以及指定播放与录音的装置。

语法

aumix [-123bcilmoprstvwWx][(+/-)强度][PqR][-dfhILqS]

参数说明:[-123bcilmoprstvwWx]为频道参数,用来指定装置的频道;[PqR]可用来指定播放或录音装置;[-dfhILqS] 则为指令参数。若不加任何参数,aumix会显示简单的图形界面供调整设置频道参数。

  • -1  输入信号线1。
  • -2  输入信号线2。
  • -3  输入信号线3。
  • -b  低音。
  • -c  CD。
  • -i  输入信号强度。
  • -m  麦克风。
  • -o  输出信号强度。
  • -p  PC喇叭。
  • -r  录音。
  • -s  合成器。
  • -t  高音。
  • -v  主音量。
  • -w  PCM。
  • -W  PCM2。
  • -x  混音器。
  • (+/-)强度  出现(+/-)时,代表在原有的强度上加减指定值。若未使用(+/-),则直接将强度设为指定值。  指定音效装置
  • P  指定播放装置。
  • q  显示频道设置。
  • R  指定录音装置。

指令参数

  • -d  指定音效装置的名称。
  • -f  指定存储或载入设置的文件。
  • -h  在使用时显示信息。
  • -I  以图形界面方式来执行aumix。
  • -L  从$HOME/.aumixrc或/etc/aumixrc载入设置。
  • -q  显示所有频道的设置值。
  • -S  将设置值保存至/HOME/.aumixrc。

实例

设置音效设备

# aumix

Linux 命令大全 Linux 命令大全

Linux dircolors命令

Linux dircolors命令

Linux 命令大全 Linux 命令大全

Linux dircolors命令用于设置 ls 指令在显示目录或文件时所用的色彩。

dircolors可根据[色彩配置文件]来设置LS_COLORS环境变量或是显示设置LS_COLORS环境变量的shell指令。

语法

dircolors [色彩配置文件]

dircolors [-bcp][--help][--version]

参数说明

  • -b或--sh或--bourne-shell  显示在Boume shell中,将LS_COLORS设为目前预设置的shell指令。
  • -c或--csh或--c-shell  显示在C shell中,将LS_COLORS设为目前预设置的shell指令。
  • -p或--print-database  显示预设置
  • -help  显示帮助。
  • -version  显示版本信息。

实例

显示默认值

# dircolors -p //显示默认值
# Configuration file for dircolors, a utility to help you set the
# LS_COLORS environment variable used by GNU ls with the --color option.
# Copyright (C) 1996, 1999-2008
# Free Software Foundation, Inc.
# Copying and distribution of this file, with or without modification,
# are permitted provided the copyright notice and this notice are preserved.
# The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
# slackware version of dircolors) are recognized but ignored.
# Below, there should be one TERM entry for each termtype that is colorizable
TERM Eterm
TERM ansi
TERM color-xterm
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM xterm-debian
# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
#NORMAL 00 # no color code at all
#FILE 00 # regular file: use no color at all
RESET 0 # reset to “normal“ color
DIR 01;34 # directory
LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
# numerical value, the color is as for the file pointed to.)
HARDLINK 44;37 # regular file with more than one link
FIFO 40;33 # pipe
SOCK 01;35 # socket
DOOR 01;35 # door
BLK 40;33;01 # block device driver
CHR 40;33;01 # character device driver
ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file
SETUID 37;41 # file that is setuid (u+s)
SETGID 30;43 # file that is setgid (g+s)
CAPABILITY 30;41 # file with capability
STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
# This is for files with execute permission:
EXEC 01;32
# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')
# If you use DOS-style suffixes, you may want to uncomment the following:
#.cmd 01;32 # executables (bright green)
#.exe 01;32
#.com 01;32
#.btm 01;32
#.bat 01;32
# Or if you want to colorize scripts even if they do not have the
# executable bit actually set.
#.sh 01;32
#.csh 01;32
# archives or compressed (bright red)
.tar 01;31

.pcx 01;35
.mov 01;35
.mpg 01;35
.mpeg 01;35
.m2v 01;35
.mkv 01;35
.ogm 01;35
.mp4 01;35
.m4v 01;35
.mp4v 01;35
.vob 01;35
.qt 01;35
.nuv 01;35
.wmv 01;35
.asf 01;35
.rm 01;35
.rmvb 01;35
.flc 01;35
.avi 01;35
.fli 01;35
.flv 01;35
.gl 01;35
.dl 01;35
.xcf 01;35
.xwd 01;35
.yuv 01;35
# http://wiki.xiph.org/index.php/MIME_Types_and_File_Extensions
.axv 01;35
.anx 01;35
.ogv 01;35
.ogx 01;35
# audio formats
.aac 00;36
.au 00;36
.flac 00;36
.mid 00;36
.midi 00;36
.mka 00;36
.mp3 00;36
.mpc 00;36
.ogg 00;36
.ra 00;36
.wav 00;36
# http://wiki.xiph.org/index.php/MIME_Types_and_File_Extensions
.axa 00;36
.oga 00;36
.spx 00;36
.xspf 00;36

Linux 命令大全 Linux 命令大全

Linux alias命令

Linux alias命令

Linux 命令大全 Linux 命令大全

Linux alias命令用于设置指令的别名。

用户可利用alias,自定指令的别名。若仅输入alias,则可列出目前所有的别名设置。alias的效力仅及于该次登入的操作。若要每次登入是即自动设好别名,可在.profile或.cshrc中设定指令的别名。

语法

alias[别名]=[指令名称]

参数说明:若不加任何参数,则列出目前所有的别名设置。

实例

给命令设置别名

# alias lx=ls
# lx
anaconda-ks.cfg Desktop install.log install.log.syslog qte

Linux 命令大全 Linux 命令大全

Linux clear命令

Linux clear命令

Linux 命令大全 Linux 命令大全

Linux clear命令用于清除屏幕。

语法

clear

实例

清屏

#clear

Linux 命令大全 Linux 命令大全

Linux reset命令

Linux reset命令

Linux 命令大全 Linux 命令大全

Linux reset命令其实和 tset 是一同个命令,它的用途是设定终端机的状态。一般而言,这个命令会自动的从环境变数、命令列或是其它的组态档决定目前终端机的型态。如果指定型态是 '?' 的话,这个程序会要求使用者输入终端机的型别。

由于这个程序会将终端机设回原始的状态,除了在 login 时使用外,当系统终端机因为程序不正常执行而进入一些奇怪的状态时,你也可以用它来重设终端机o 例如不小心把二进位档用 cat 指令进到终端机,常会有终端机不再回应键盘输入,或是回应一些奇怪字元的问题。此时就可以用 reset 将终端机回复至原始状态。

语法

tset [-IQqrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]

参数说明

  • -p  将终端机类别显示在屏幕上,但不做设定的动作。这个命令可以用来取得目前终端机的类别。
  • -e ch  将 erase 字元设成 ch
  • -i ch  将中断字元设成 ch
  • -k ch  将删除一行的字元设成 ch
  • -I  不要做设定的动作,如果没有使用选项 -Q 的话,erase、中断及删除字元的目前值依然会送到屏幕上。
  • -Q  不要显示 erase、中断及删除字元的值到屏幕上。
  • -r  将终端机类别印在屏幕上。
  • -s  将设定 TERM 用的命令用字串的型式送到终端机中,通常在 .login 或 .profile 中用。

实例

让使用者输入一个终端机型别并将终端机设到该型别的预设状态

# reset ?

将 erase 字元设定 control-h

# reset -e ^B

将设定用的字串显示在屏幕上

# reset -s
Erase is control-B (^B).
Kill is control-U (^U).
Interrupt is control-C (^C).
TERM=xterm;

Linux 命令大全 Linux 命令大全

Linux let 命令

Linux let 命令

Linux 命令大全 Linux 命令大全

命令:let

let 命令是 BASH 中用于计算的工具,用于执行一个或多个表达式,变量计算中不需要加上 $ 来表示变量。如果表达式中包含了空格或其他特殊字符,则必须引起来。

语法格式

let arg [arg ...]

参数说明:

arg:要执行的表达式

实例:

自加操作:let no++

自减操作:let no--

简写形式 let no+=10,let no-=20,分别等同于 let no=no+10,let no=no-20

以下实例计算 a 和 b 两个表达式,并输出结果:

#!/bin/bash

let a=5+4
let b=9-3 
echo $a $b

以上实例执行结果为:

9 6

Linux 命令大全 Linux 命令大全

客户热线: