shell(10) 常用命令.doc

ls

-l, show the hard link count;

-i, show i-node

-h, human readable

-t, sort by modify time

-S, sort by size

-r, --reverse

-R, show content of sub-dir

-v, sort by version

 

cp

-p, 保留源文件属性,如修改时间

-l, create hard link

-s, create soft link

-R, copy dir

-r, 递归复制文件

 

stat

show more info of a file

 

mount

null parameter, show all mounted file systems

mount -t type device directory

-a, mount add file systems according to /etc/fstab

 

"mount -t iso9660 -o loop abc.iso mnt", mount iso file

 

简单用法 :

fat32 的分区

mount -o codepage=936,iocharset=cp936 /dev/hda7 /mnt/cdrom (mount -t vfat -o iocharset=cp936 /dev/hda7 /mnt/cdrom)

ntfs 的分区

mount -o iocharset=cp936 /dev/hda7 /mnt/cdrom

iso 文件

mount -o loop /abc.iso /mnt/cdrom

软盘

mount /dev/fd0 /mnt/floppy

USB 闪存

mount /dev/sda1 /mnt/cdrom      说明 : /mnt/cdrom 目录必须存在

所有 /etc/fstab 内容 mount -a

 

可以指定文件格式 "-t 格式 ", 格式可以为 vfat, ext2, ext3 .

 

开机就 mount windows 下的分区

自动将 windows d 盘挂到 /mnt/d 上,用 vi 打开 /etc/fstab ,加入以下一行

/dev/hda5 /mnt/d vfat defaults,codepage=936,iocharset=cp936 0 0

注意,先得手工建立一个 /mnt/d 目录

mount 局域网上其他 windows 机器共享出的目录 (bjchenxu)

mount -t smbfs -o username=guest,password=guest //machine/path /mnt/cdrom

 

du/df

-h, human readable

-c, show count info of all file listed

-s, show statistic info only

du -sh

 

sort

默认按字符排序

-n ,将数字识别成数字排序

-M, sort by month

-r, --reverse

-b, --ignore-leading-blanks

还可以指定用于排序的字段、合并排序结果等;

 

grep

-v, 不包括 xxx

-n, show line number

-c, get count of marched lines

-e, 指定多个模式 , eg: grep -e ER] -e WA] abc.log 约等于 grep [EW][RA] abc.log

 

gzip

gzip

gzcat ,显示压缩后文本文件的内容

gunzip

 

tar

tar function [options] object1 object2 ...

tar -xzvf abc.tgz

function:

-c, create a new tar file

-r, append to the tar file end

-t, list files in tarball

-u, update files in tarball

-x, unzip tar file

options

-p, 保留文件权限

-v, list files when proceeding

-z, redirect output to gzip

-f, set the dest file

 

tee

将来自 STDIN 的数据同时发往 STDOUT 与文件

eg:

date | tee a.txt

 

eval

执行所有的 shell 替换后执行命令

eg:

#set a b c d

#eval echo The last argument is /$$#    # 直接使用 echo 则输出为 $4 echo 只执行了一次替换

 

eg2: 命令行很复杂时使用 eval

#a="id | cut -f1 -d' '"

#$a                # 错误, | cut -f 等都被作为了 id 的参数,

#eval $a         # 成功, bash 会先解释 $a ,此时会被解释成上面的字串, eval 会使得该字串再次被处理,即作为命令执行

 

sort file(s)

排序

 

wc file(s)

统计行数、单词、字符数

 

uniq file

删除重复行

 

grep

grep [options] pattern [file]

-i    case insensitive

-v    搜索不匹配行

-n   print line number

-r    

-c   输出匹配行数目

-h  

-l    只输出匹配的文件名

 

使用正则表达式,如 :

grep a$ a.txt

find

find [path] [expression]

expression:

-name pattern

-iname , case-insensitive

-print

alias

alias li='ls -il'  # create an alias, avialable in the local shell

set aliases in ~/.bashrc

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值