小技巧: 实用的一行 Linux 命令
下面这些 Linux 命令都只有一行,虽然简短,但却非常实用。如若善于使用它们,定会给你的 Linux 使用过程带来便利。其中包括创建存档文件、递归查找文件内的字符串、搜索并替换文件里的内容、查看磁盘及目录占用情况等。
- 创建存档文件
tar -czpf folder_name.tar.gz folder_name该命令将 folder_name 创建为 folder_name.tar.gz 存档文件。 - 递归查找文件内的字符串
find ./ -name ‘*.html’ -exec grep “breadcrumbs.inc.php” ‘{}’ \; -print这条命令将查找所有包含 breadcrumbs.inc.php 的 HTML 文件。 - 搜索并替换文件里的内容
sed -i ’s/b/strong/g’ index.html此命令搜索 index.html 文件中的 b 并将其替换为 strong。 - 查看目录的磁盘占用情况
du -h --max-depth=1 | sort -n -r
[via Micah Carrick]
Read More:
find ./ -name ‘*.html’
原來是單引號啊~ 謝謝。
查看目录的磁盘占用情况
du -h --max-depth=1 | sort -n -r
我觉得,要达到这样的目的,还不如用 du -hs
http://linux.byexamples.com/ 这个网站有更多的例子和技巧。
2楼说的在理,看到man手册里说max-depth=1时与-s相同。
强,收教了
那继续补充几个不太常用的吧…… =,= ls -ltr (ll -tr) 按时间排序 最下面是最新修改的文件 ls -Slhr (ll -Shr) 按文件大小排序 最下面是最大的
alias ls='ls --color=auto' alias ll='ls -l' alias la='ll -a' alias man="TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man" alias soft-install='sudo apt-get install' alias soft-remove='sudo apt-get autoremove' alias soft-update='sudo apt-get update;sudo apt-get upgrade;sudo apt-get dist-upgrade' alias soft-clear='sudo localepurge;sudo apt-get clean; sudo apt-get autoclean; sudo apt- get autoremove' alias soft-search='apt-cache search' alias df='df -h' alias grep='grep --color' alias psgrep='ps aux | grep' alias dirsize='SIZE=
sudo du -sm |tr \. \B | tr [:blank:] \M;echo "size of current dir:$ SIZE"' alias unzip1='tar -xzvf' alias unzip2='tar -xjvf' alias rmd='rm -rf' alias checkupdate='apt-cache policy' alias showstat='apt-cache show' alias memsize="grep 'Memory' /var/log/dmesg" alias mypstree="pstree -Ghp $USER" alias useusb="sudo mount -t vfat /dev/sda1 /media/usb/ -o iocharset=utf8,rw,uid=1000,gid= 1000;rox /media/usb" alias closeusb="sudo umount /media/usb"递归查找文件内的字符 这样更简单:
grep -ri "test string" *.html
sed -i ’s/b/strong/g’ index.html
这个我试过似乎没作用???
@小狼诺夫: 这个。。。干脆用语音识别算了
sed -e 's/b/strong/g' index.html
[...] 小技巧: 实用的一行 Linux 命令 Posted in Ubuntu by admin on 11月 17th, 2007 摘自LinuxTOY: http://linuxtoy.org/archives/useful-linux-commands-2.html [...]