好文档 - 专业文书写作范文服务资料分享网站

Linux命令大全分类

天下 分享 时间: 加入收藏 我要投稿 点赞

精品文档

Linux sh命令(调用sh文件程序)

如何使用Linux命令 sh

Runs or processes jobs through the Bourne shell.

linux sh 的语法

sh [-a] [-c] [-C] [-e] [-E] [-f] [-h] [-i] [-I][-k] [-m] [-n] [-p] [-r] [-s] [-t] [-T] [-u] [-v] [-x] [ argument ]

-a -c

Export all variables assigned to.

Pass the string argument to the shell to be interpreted as input. Keep in mind that this option only accepts a single string as its argument, hence

multi-word strings must be quoted.

-C -e

Don't overwrite existing files with ``>.''

If not interactive, exit immediately if any untested command fails. The exit status of a command is considered to be explic- itly tested if the command is used to control an if, elif, while, or until; or if the command is the

left hand operand of an ``&&'' or ``||'' operator.

-E -f -h -i -I -k

Enable the built-in emacs command line editor (disables -V if it has been

set).

Disable pathname expansion. Makes all commands use tracked aliases. Force the shell to behave interactively. Ignore EOF's from input when interactive.

tells the shell to use Korn-compatible behavior in any case where the POSIX.2 behavior is different from the behavior specified by Korn. In particular,

this affects the trap command.

-m -n -p

Turn on job control (set automatically when interactive).

If not interactive, read commands but do not execute them. This is useful

for checking the syntax of shell scripts.

Turn on privileged mode. This mode is enabled on startup if either the effective user or group id is not equal to the real user or group id. Turning this mode off sets the effective user and group ids to the real user and group ids. Also on interactive shells and when enabled, this mode sources

/etc/suid_profile (in- stead of ~/.profile) after /etc/profile and ignores

the contents of the ENV variable.

-r

Invokes a restricted shell. In a restricted shell, you cannot do any of the following: use the cd command; change the values of the variables env, path

1欢迎下载

精品文档

or shell; use > or >> to redirect output; specify command names containing

/. These restrictions do not apply during execution of profile files.

-s

Read commands from standard input (set automatically if no file arguments are present). This option has no effect when set after the shell has already

started running (i.e. with set).

-t -T

Exits after reading and executing one command.

When waiting for a child, execute traps immediately. If this option is not set, traps are executed after the child exits, as specified in IEEE Std1003.2 (``POSIX'') This nonstandard option is useful to put guarding shells around childs that block signals. The surrounding shell may kill the child or it

may just re- turn control to the tty and leave the child alone.

-u -v -V -x

Write a message to standard error when attempting to expand a variable that

is not set, and if the shell is not interactive, exit immediately. The shell writes its input to standard error as it is read. Useful for

debugging.

Enable the built-in vi command line editor (disables -E if it has been set). Write each command to standard error (preceded by a '+ ') before it is

executed. Useful for debugging.

linux sh 的演示示例:

sh - Executes the Bourne shell, likely taking you to a $ prompt.

字符串操作

echo File Name: DSP.sh 打印字符串

# 注释本行

Vi文件操作

Vi my.sh //打开一个文件进行编辑。如果是不存在的文件则会新建文件 Esc //进入命令模式 i //进入修改模式

:q! //强制推出不保存文件修改 :wq //推出并保存修改

。 2欢迎下载

精品文档

环境变量set

set

功能说明:设置shell。

语 法:set [+-abCdefhHklmnpPtuvx]

补充说明:set指令能设置所使用shell的执行方式,可依照不同的需求来做设置。

参 数:

-a 标示已修改的变量,以供输出至环境变量。 -b 使被中止的后台程序立刻回报执行状态。 -C 转向所产生的文件无法覆盖已存在的文件。

-d Shell预设会用杂凑表记忆使用过的指令,以加速指令的执行。使用-d参数可取消。

-e 若指令传回值不等于0,则立即退出shell。 -f 取消使用通配符。

-h 自动记录函数的所在位置。

-H Shell 可利用\加<指令编号>的方式来执行history中记录的指令。 -k 指令所给的参数都会被视为此指令的环境变量。 -l 记录for循环的变量名称。 -m 使用监视模式。

-n 只读取指令,而不实际执行。 -p 启动优先顺序模式。

-P 启动-P参数后,执行指令时,会以实际的文件或目录来取代符号连接。 -t 执行完随后的指令,即退出shell。

-u 当执行时使用到未定义过的变量,则显示错误信息。 -v 显示shell所读取的输入值。

-x 执行指令后,会先显示该指令及所下的参数。 +<参数> 取消某个set曾启动的参数。

系统信息

arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本

dmidecode -q 显示硬件系统部件 - (SMBIOS / DMI) hdparm -i /dev/hda 罗列一个磁盘的架构特性

。 3欢迎下载

精品文档

hdparm -tT /dev/sda 在磁盘上执行测试性读取操作 cat /proc/cpuinfo 显示CPU info的信息 cat /proc/interrupts 显示中断 cat /proc/meminfo 校验内存使用

cat /proc/swaps 显示哪些swap被使用 cat /proc/version 显示内核的版本

cat /proc/net/dev 显示网络适配器及统计 cat /proc/mounts 显示已加载的文件系统 lspci -tv 罗列 PCI 设备 lsusb -tv 显示 USB 设备 date 显示系统日期

cal 2007 显示2007年的日历表

date 041217002007.00 设置日期和时间 - 月日时分年.秒 clock -w 将时间修改保存到 BIOS

关机 (系统的关机、重启以及登出

shutdown -h now 关闭系统(1) init 0 关闭系统(2) telinit 0 关闭系统(3)

shutdown -h hours:minutes & 按预定时间关闭系统 shutdown -c 取消按预定时间关闭系统 shutdown -r now 重启(1) reboot 重启(2) logout 注销

文件和目录操作

cd /home 进入 '/ home' 目录' cd .. 返回上一级目录 cd ../.. 返回上两级目录 cd 进入个人的主目录

cd ~user1 进入个人的主目录 cd - 返回上次所在的目录 pwd 显示工作路径 ls 查看目录中的文件 ls -F 查看目录中的文件

ls -l 显示文件和目录的详细资料 ls -a 显示隐藏文件

4欢迎下载。

)

精品文档

ls *[0-9]* 显示包含数字的文件名和目录名

tree 显示文件和目录由根目录开始的树形结构(1) lstree 显示文件和目录由根目录开始的树形结构(2) mkdir dir1 创建一个叫做 'dir1' 的目录' mkdir dir1 dir2 同时创建两个目录

mkdir -p /tmp/dir1/dir2 创建一个目录树 rm -f file1 删除一个叫做 'file1' 的文件' rmdir dir1 删除一个叫做 'dir1' 的目录'

rm -rf dir1 删除一个叫做 'dir1' 的目录并同时删除其内容 rm -rf dir1 dir2 同时删除两个目录及它们的内容 mv dir1 new_dir 重命名/移动 一个目录 cp file1 file2 复制一个文件

cp dir/* . 复制一个目录下的所有文件到当前工作目录 cp -a /tmp/dir1 . 复制一个目录到当前工作目录 cp -a dir1 dir2 复制一个目录

ln -s file1 lnk1 创建一个指向文件或目录的软链接 ln file1 lnk1 创建一个指向文件或目录的物理链接

touch -t 0712250000 file1 修改一个文件或目录的时间戳 - (YYMMDDhhmm) file file1 outputs the mime type of the file as text iconv -l 列出已知的编码

iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.

find . -maxdepth 1 -name *.jpg -print -exec convert \\\\; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)

文件搜索

find / -name file1 从 '/' 开始进入根文件系统搜索文件和目录 find / -user user1 搜索属于用户 'user1' 的文件和目录 find /home/user1 -name \\*.bin 在目录 '/ home/user1' 中搜索带有'.bin' 结尾的文件

find /usr/bin -type f -atime +100 搜索在过去100天内未被使用过的执行文件

find /usr/bin -type f -mtime -10 搜索在10天内被创建或者修改过的文件 find / -name \\*.rpm -exec chmod 755 '{}' \\; 搜索以 '.rpm' 结尾的文件并定义其权限

find / -xdev -name \\*.rpm 搜索以 '.rpm' 结尾的文件,忽略光驱、捷盘等可移动设备

locate \\*.ps 寻找以 '.ps' 结尾的文件 - 先运行 'updatedb' 命令 whereis halt 显示一个二进制文件、源码或man的位置

。 5欢迎下载

Linux命令大全分类

精品文档Linuxsh命令(调用sh文件程序)如何使用Linux命令shRunsorprocessesjobsthroughtheBourneshell.linuxsh的语法sh[-a][-c][-C][-e][-E][-f][-h][-i][-I][-k][-m][-
推荐度:
点击下载文档文档为doc格式
3cqbk2yplb4mu7526k929d31q9p63i00eby
领取福利

微信扫码领取福利

微信扫码分享