-- 各种查找文件 --
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
↑
统计的结果
Linux学习笔记_常用操作_2
最新推荐文章于 2023-12-23 14:55:33 发布