Linux学习笔记_常用操作_2

-- 各种查找文件 --

ls -laihFnSt --color=always --time=atime --full-time
ls -l /usr/bin/[!a-x]*

which traceroute -a

locate java

find / -type f -perm -4000 -exec ls -l {} /;
find / -type f -name mysql* -exec cp {} . /;

find /opt/eclipse -[a/c/m]time 0
find /opt/eclipse -user linke -exec rm -rf {} /;

find . -type f -exec cat {} /; | grep alias

-- 查看文件 --

cat -An /etc/issue
cat -vETn

head –n 20 ~/.bashrc | tail –n 10

-- 各种修改 --

chmod 7666 test; ls -l test

-- 打包 --

tar -N '2005/06/01' -zcvpf /tmp/etc.tar.gz /etc
tar -cvf - /etc | tar -xvf -

-- mount --
mount -t vfat /dev/sdb1 /xxx/ooo
               ↑
要看支持哪些,see:/lib/modules/`uname -r`/kernel/fs,常见:
       • ext2, ext3, reiserfs, 等 Linux 惯用 filesystem
       • vfat, msdos 等 Windows 常见 filesystem
       • iso9660 为光盘片的格式
       • nfs, smbfs 等为网络相关档案系统。

-- dd --
1.swap
dd if=/dev/zero of=/tmp/swap bs=4k count=16382
mkswap /tmp/swap
swapon /tmp/swap
swapoff /tmp/swap

2.备份文件、mbr、分区等等
dd if=/etc/passwd of=/tmp/passwd.back
结果可能是这种:3+1,回忆下啥意思?

dd if=/dev/hda of=/tmp/mbr.back bs=512 count=1

dd if=/dev/hda1 of=/some/path/filenaem

-- 变量 --

declare = set
declare -x = export
declare -i

declare | wc -l;/
set | wc -l;/

//TODO 写在script里?用数组?
declare -x | wc -l;/
export | wc-l;/
env | wc -l;
*:env出来的结果比declare -x 出来的多了个 _=/bin/env

-- 服务 --
chkconfig --list
chkconfig xxx on

-- 管线 --

- cut -
cut“敌法”,sort“tinker”

echo $PATH | cut -d ':' -f 3,5
export | cut -c 12-
export | cut -c 12-24

- sort -
cat /etc/passwd | sort -t : -k3 -n
last | cut -d ' ' -f1 | sort -u
last | cut -d ' ' -f1 | sort | uniq -ic(本月每个用户的登录次数)

- grep -
last | grep [a-zA-Z] | grep -v 'wtmp' | wc -l(这个月登录的总人次)
grep -v '^$' /etc/syslog.conf | grep -v '^#'(只取有效信息)

- tee -
ls -l / | tee -a ~/homefile | more(tee:"复制"导向)

cat /etc/man.config | col -x | cat -A | more
                                  ↑
               将 tab 键转换成对等的空格键

join -t ':' /etc/passwd /etc/shadow
join -t ':' -1 4 /etc/passwd -2 3 /etc/group


paste /etc/passwd /etc/shadow
cat /etc/group | paste /etc/passwd /etc/shadow - | head -n 3
                                                                       ↑
                                          ┌──────── 这个表示stdin,
                                          │                   这里就是第一个
                                          │                   命令的结果
                                          │
cat env > /tmp/env.txt          ↓
env|sort -t '=' -k1 | join -t '=' - /tmp/env.txt

- 分割,合并 -
split -b 300k /etc/termcap termcap
cat termcap* >> termcapback

ls -al / | split -l 10 - lsroot
                           ↑
                        stdin
- 参数替换 -
cut -d : -f1 </etc/passwd | head -n 3 | xargs finger

- sed -
cat /etc/passwd | sed '2d' 或者 '2,5d' '2,$d'
cat /etc/passwd | sed '2,5c No 2-5 number'
cat /etc/passwd | sed -n '5,7p'

ifconfig eth0 | grep 'inet ' | sed 's/^.*addr://g' | /
> sed 's/Bcast.*$//g'

cat /etc/passwd | /
> sed -e '4d' -e '6c no six line' > /tmp/test/passwd

- awk -

NF 每一行 ($0) 拥有的字段总数
NR 目前 awk 所处理的是『第几行』数据
FS 目前的分隔字符,预设是空格键

cat /etc/passwd | /
> awk 'BEGIN {FS=":"} $3 < 10 {print $1 "/t " $3}'

pay.txt:
Name 1st 2nd 3th
VBird 23000 24000 25000
DMTsai 21000 20000 23000
Bird2 43000 42000 41000

cat pay.txt | /
> awk 'NR==1{printf "%10s %10s %10s %10s %10s/n",$1,$2,$3,$4,"Total" }
NR>=2{total = $2 + $3 + $4
printf "%10s %10d %10d %10d %10.2f/n", $1, $2, $3, $4, total}'

  Name   1st      2nd    3th     Total        ← NR==1
  VBird    23000 24000 25000 72000.00  ← NR>=2
  DMTsai 21000 20000 23000 64000.00  ← NR>=2
  Bird2    43000 42000 41000 126000.00 ← NR>=2
                                               ↑
                                         统计的结果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值