Ubuntu配置技巧(三)

 

Partitions

# sudo -s    ;login as root, and keep old enviroment variables.
# free -m |grep "Mem" | awk '{print $2}'    ; you need to study awk
# fdisk -l
# df -th    ;-t display fs type,
        -h human-readable
# du -sh    ;-s summary

分区挂载


# sudo mount -t 文件系统类型 设备路经 访问路经
    常用文件类型:
        iso9660 光驱文件系统,
        vfat fat/fat32分区,
        ntfs ntfs分区,
        smbfs windows网络共享目录,
        reiserfs、ext3、xfs Linux分区
如果中文名无法显示尝试在最後增加 -o nls=utf8 或 -o iocharset=utf8
如果需要挂载後,普通用户也可以使用,在 -o 的参数後面增加 ,umask=022 如:-o nls=utf8,umask=022

1. 只读挂载ntfs分区

# mount -t ntfs -o nls=utf8,umask=0 /dev/sdb1 /mnt/c

2. 可写挂载ntfs分区

# mount -t ntfs-3g -o locale=zh_CN.utf8,umask=0 /dev/sdb1 /mnt/c

3. 挂载fat32分区

# mount -t vfat -o iocharset=utf8,umask=0 /dev/sda1 /mnt/c

4. 挂载共享文件

# mount -t smbfs -o  username=xxx,password=xxx,iocharset=utf8 //192.168.1.1/share /mnt/share

5. 挂载ISO文件

# mount -t iso9660 -o loop,utf8 xxx.iso /mnt/iso


6. 制作ISO文件
# mkisofs -o test.iso -Jrv -V test_disk /home/carla/

7. 转换目录到iso文件

mkisofs -o isofile.iso  dirname

8. 转换CD到iso文件

dd if=/dev/cdrom of=isofile.iso

Processes

# watch        ;execute command periodly
        ;-n or --interval: to specify a different interval. default = 2s

        ;-d or --differences:
        ;    highlight the differences between successive updates.
        ;--cumulative option:
               ;    makes highlighting "sticky", presenting a running display of all             ;    positions that have ever changed. 
        ;-t or --no-title option :
        ;    turns off the header showing the interval, command, and current time at             the top of the display, as well as the following blank line.

# ps -?

ERROR: Garbage option.
********* simple selection *********  ********* selection by list *********
-A all processes                      -C by command name
-N negate selection                   -G by real group ID (supports names)
-a all w/ tty except session leaders  -U by real user ID (supports names)
-d all except session leaders         -g by session OR by effective group name
-e all processes                      -p by process ID
T  all processes on this terminal     -s processes in the sessions given
a  all w/ tty, including other users  -t by tty
g  OBSOLETE -- DO NOT USE             -u by effective user ID (supports names)
r  only running processes             U  processes for specified users
x  processes w/o controlling ttys     t  by tty

*********** output format **********  *********** long options ***********
-o,o user-defined  -f full            --Group --User --pid --cols --ppid
-j,j job control   s  signal          --group --user --sid --rows --info
-O,O preloaded -o  v  virtual memory  --cumulative --format --deselect
-l,l long          u  user-oriented   --sort --tty --forest --version
-F   extra full    X  registers       --heading --no-heading --context
                    ********* misc options *********
-V,V  show version      L  list format codes  f  ASCII art forest
-m,m,-L,-T,H  threads   S  children in sum    -y change -l format
-M,Z  security data     c  true command name  -c scheduling class
-w,w  wide output       n  numeric WCHAN,UID  -H process hierarchy

# pstree

查看进程打开的文件
# lsof -p 进程的pid

显示开启文件abc.txt的进程
# lsof abc.txt

显示21端口现在运行什么程序
# lsof -i :21

显示nsd进程现在打开的文件
# lsof -c nsd

在后台运行程序,退出登录后,并不结束程序
# nohup 程序 &
# tail nohup    ;查看中间运行情况 


# top        ;subcommand h or ?

Networking

根据IP查网卡地址
# arping IP地址    ;send ARP REQUEST to a neighbour host

根据IP查电脑名
# nmblookup -A IP地址

查看当前IP地址
# ifconfig eth0 |awk '/inet/ {split($2,x,":");print x[2]}'

# lsof -i :21    ;check the pid who are listening on port 21

同一个网卡增加第二个IP地址,
    在网卡eth0上增加一个1.2.3.4的IP:
    # ifconfig eth0:0 1.2.3.4 netmask 255.255.255.0
    删除增加的IP:
    # ifconfig eth0:0 down

立即让网络支持nat
# echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
# sudo iptables -t nat -I POSTROUTING -j MASQUERADE

 查看路由信息
# netstat -rn
# sudo route -n

手工增加一条路由
# route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1

手工删除一条路由
# route del -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1

修改网卡MAC地址的方法
# ifconfig eth0 down #关闭网卡
# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE #然后改地址
# ifconfig eth0 up #然后启动网卡

对7.10的永久改地址方法
# gedit /etc/network/interfaces

在 iface eth0 inet static 后面添加一行:
    pre-up ifconfig eth0 hw ether 01:01:01:01:01:01
配置文件应该像如下
    face eth0 inet static
    pre-up ifconfig eth0 hw ether 01:01:01:01:01:01
    address 192.168.1.10
    netmask 255.255.255.0
    gateway 192.168.1.1
最后是 logout 或者reboot

统计当前IP连接的个数
# netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r -n
# netstat -na|grep SYN|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r -n

统计当前20000个IP包中大于100个IP包的IP地址
# tcpdump -tnn -c 20000 -i eth0 | awk -F "." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr | awk ' $1 > 100 '

屏蔽IPV6
# echo "blacklist ipv6" | sudo tee /etc/modprobe.d/blacklist-ipv6

察看当前网络连接状况以及程序
# netstat -atnp

查看网络连接状态
# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

查看当前系统所有的监听端口
# nc -zv localhost 1-65535    ;netcat

查看网络的当前流量
    安装 ethstatus 软件
    # apt-get install ethstatus
    查看 ADSL 的速度
    # ethstatus -i ppp0
    查看 网卡 的速度
    # sudo ethstatus -i eth0

查看域名的注册备案情况
# whois baidu.cn

查看到某一个域名的路由情况
# tracepath baidu.cn

重新从服务器获得IP地址
# dhclient

从当前页面开始镜像整个网站到本地

# wget -r -p -np -k http://www.21cn.com
· -r:在本机建立服务器端目录结构;
· -p: 下载显示HTML文件的所有图片;
· -np:只下载目标站点指定目录及其子目录的内容;
· -k: 转换非相对链接为相对链接。

如何多线程下载
# apt-get install axel
# axel -n 5 http://xxx.xxx.xxx.xxx/xxx.zip
或者
# lftp -c "pget -n 5 http://xxx.xxx.xxx.xxx/xxx.zip“

如何查看HTTP头
# w3m -dump_head http://www.xxx.com

Services

添加一个服务
# update-rc.d 服务名 defaults 99

删除一个服务
# update-rc.d 服务名 remove

临时重启一个服务
# /etc/init.d/服务名 restart

临时关闭一个服务
# /etc/init.d/服务名 stop

临时启动一个服务
# /etc/init.d/服务名 start

文件和文件夹

# locate filename    ;same as find command
# touch    filename    ;create empty file
# cd            ;same as cd ~

将当前目录下最近30天访问过的文件移动到上级back目录
# find . -type f -atime -30 -exec mv {} ../back \;

将当前目录下最近2小时到8小时之内的文件显示出来
# find . -mmin +120 -mmin -480 -exec more {} \;

删除当前目录里面所有的 .svn 目录
# find . -name .svn -type d -exec rm -fr {} \;

删除当前目录所有以“~”结尾的临时文件
# find . -name "*~" -exec rm {} \;

备份当前系统到另外一个硬盘 
# rsync -Pa / /media/disk1 --exclude=/media/* --exclude=/home/* --exclude=/sys/*
                           --exclude=/tmp/* --exclude=/proc/* --exclude=/mnt/*

去掉文件中的^M, 注意不要使用同样的文件名,会清空掉原文件
# cat filename | tr -d "^M" > newfile;
或者
# sed -e "s/^M//g" filename > newfile;

Nautilus

显示隐藏文件    Ctrl+h
显示地址栏    Ctrl+l

特殊 URI 地址
* computer:/// - 全部挂载的设备和网络
* network:/// - 浏览可用的网络
* burn:/// - 一个刻录 CDs/DVDs 的数据虚拟目录
* smb:/// - 可用的 windows/samba 网络资源
* x-nautilus-desktop:/// - 桌面项目和图标
* file:/// - 本地文件
* trash:/// - 本地回收站目录
* ftp:// - FTP 文件夹
* ssh:// - SSH 文件夹
* fonts:/// - 字体文件夹,可将字体文件拖到此处以完成安装
* themes:/// - 系统主题文件夹

查看已安装字体
# fc-list
在nautilus的地址栏里输入”fonts:///“,就可以查看本机所有的fonts  (这个似乎不行)

时钟


读取CMOS时间
# hwclock --hctosys

从服务器上同步时间
# ntpdate ntp.ubuntu.com
# ntpdate time.nist.gov

设置电脑的时区为上海
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

XP 和 Ubuntu 相差了 8 小时的时差
关闭UTC,将当前时间写入CMOS。
# sed -ie 's/UTC=yes/UTC=no/g' /etc/default/rcS
# hwclock --systohc

Others

延迟抓图
# gnome-screenshot -d 10 #延迟10秒抓图
# gnome-screenshot -w -d 5 #延迟5秒抓当前激活窗口

回收站在哪里
$HOME/.local/share/Trash/

默认打开方式的配置文件在哪里
全局    /etc/gnome/defaults.list
个人    ~/.local/share/applications/mimeapps.list

Firefox 的缓存目录在哪里
ls ~/.mozilla/firefox/*.default/Cache/

Pidgin 的聊天记录在哪里
~/.purple/logs/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值