Ubuntu 12.04服务器版使用 cp -r -f 强制覆盖拷贝时仍需确认的问题

问题现象:


使用cp -r -f 强制覆盖拷贝命令时,每一个文件都需要认为的键入“Y”进行确认,甚是烦扰,难道要我点击一万下不成?

问题原因:


cp命令被设置了别名
alias cp='cp -i'
所以在每次执行cp命令是都会按照这个设置进行人为的确认(-i参数的含义)。

解决方法:


一.使用unalias cp命令 解除对cp的别名(仅本次终端连接会话临时取消),我们先输入alias命令,查看系统内部已经设置的别名:

[root@localhost ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'

输入unalias cp命令,取消cp命令的别名.

[root@localhost ~]# unalias cp

二.直接输入\cp命令,作用也是取消cp的别名

[root@localhost ~]# \cp filename new/filename
[root@localhost ~]#

三.使用管道的方式,自动输入yes

[root@localhost ~]# yes | cp filename new/filename

解决Ubuntu和Windows双系统时间差异8小时的方法

Windows/Ubuntu双系统用户会发现在Ubuntu里面的时间正常的情况下Windows的系统时间被改到8小时前。

原来Linux操作系统是以CMOS时间做为格林威治标准时间,再根据系统设置的时区来确定目前系统时间。但是Windows会直接修改CMOS时间。而中国的时区是+8区,所以才会造成时间被调整了-8个小时。

所以您可以让Windows去使用时区或者让Ubuntu使用本地时间。

修改Windows使用时区的方法是在注册表:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation\

下面增加一个名为RealTimeIsUniversalREG_DWORD键,并赋值为1

对于Ubuntu 16.04以下版本, 使用本地时间的方法是:

$ sudo gedit /etc/default/rcS

把里面的 UTC=yes 改为 UTC=no

对于`Ubuntu 16.04`以及之后的版本(如:`Ubuntu 18.04`),使用如下命令:

$ sudo timedatectl set-local-rtc 1

参考链接


解决ubuntu和windows双系统时间差异8小时的方法

Ubuntu 12.04 + Apache2.2.22搭建SPDY服务器

SPDY是Google开发的基于传输控制协议(TCP)的应用层协议,该协议规定在一个SPDY连接内可以有无限个并行请求,服务器可以主动向客户端发起通信向客户端推送数据,通过请求优化、预加载、压缩HTTP 来达到加速的目的。

对用记而言,SPDY是基于SSL加密,它可以让网络访问更安全,用户隐私更加得到保护。对站长而言,SPDY在降低连接数目的同时,还使服务器上每个客户端占用的资源减少,从释放出更多内存和CPU ,让网站的浏览速度提升不少。

SPDY协议已经被Chrome、Firefox、Opera、IE 11以上支持,用户在访问使用SPDY协议加载的网站几乎感觉不到与普通的Https页面访问有何不同,而SPDY带来的页面加载速度提升和服务器性能优化确是有十分重要意义的。

具体的操作步骤如下:

  • 启用Apache2的HTTPS支持

参考 UBUNTU 12.04 下 APACHE 2.2.22 开启 HTTPS

  • 下载Apache2的mod_spdy模块

官网:https://developers.google.com/speed/spdy/mod_spdy/
由于众所周知的原因,本站提供下载(2015-11-6版本)
mod_spdy 64-bit .deb (Debian/Ubuntu)
mod_spdy 32-bit .deb (Debian/Ubuntu)

  • 安装mod_spdy模块(本站是64位系统)
$sudo dpkg -i mod-spdy-*.deb
$sudo apt-get -f install
  • 重启Apache2
$sudo service apache2 restart
  • 验证

目前验证貌似没有起作用啊!目前最新的chrome已经没办法进行验证了,主要是由于HTTP/2已经发布,Google放弃了spdy,转而支持HTTP/2,还是静待新版本的HTTP/2吧。

  • 卸载
$sudo dpkg -r mod-spdy-beta
$sudo dpkg -P mod-spdy-beta
  • 参考链接

Linux Mint + Apache2.2搭建SSL/HTTPS/SPDY服务器
https://developers.google.com/speed/spdy/mod_spdy/

Ubuntu 15.04 Btrfs分区拷贝文件提示 “拼接文件出错:设备上没有空间” (No space left on device)

在安装Ubuntu 15.04的时候,由于机器使用的是SSD硬盘,因此在建立HOME分区的时候选择了使用Btrfs格式作为分区格式。一直都是使用正常,直到今天,在向HOME分区拷贝一个16GB的文件的时候提示 “拼接文件出错:设备上没有空间” (英文系统可能会提示 “No space left on device”)。

  • 磁盘空间真的不足了?

使用"df"命令查询分区,发现所有分区都是足够的。如下图所示,空间足够使用,尤其是HOME分区,足足有40GB的空间。df_command_when_btrfs_no_space_error

  • 单个文件的大小太大了? 超过分区限制了?

维基百科搜索“btrfs”,简介中标明,最大文件尺寸 16 EiB,显然,16GB的文件,是不会超过这个限制的。

  • 分区中的文件数目太多?超过文件数量限制?

同样是维基百科,btrfs条目,标明 最大文件数量 2^64,显然,120GB的一个硬盘,即使是全部是一个字节的小文件,也达不到这个数字的。

  • Inode耗尽?

使用"df -i"命令查询Inode信息,发现好奇怪的现象,home所在的分区信息中Inode信息,不管是已经你使用的,还是可以使用的,还是总数,都是 0. 为什么呢?
df_i_command_when_btrfs_no_space 后来才知道,btrfs格式是不能使用df命令的,btrfs有自己的单独的命令查询.

$btrfs fi df /home

btrfs_fi_df_i_command_when_btrfs_no_space

仔细观察一下输出结果,好奇怪,使用df 命令,我们查询到分区的大小在90GB左右,但是这里显示的文件的大小仅仅是43GB,而且已经使用了42.50GB,按照这个显示,自然是空间不足了,那么,我们的空间去了哪里?

  • 产生这个问题的根本原因

这个问题的产生,本质上是btrfs设计导致的,原因归咎于btrfs所采用的COW技术,这项技术需要一个比较大的保留存储空间,但是当空间不足的时候,本应减少保留空间,而显然,默认情况下,没有正确处理这种情况。这个问题在3.18版本之后得到比较好的解决。

  • 解决方法

对于 btrfs 3.18之前的版本来说,执行如下命令即可.

$btrfs balance start -v -dusage=0 /home

从3.18版本开始,这个命令是当空间不足出现的时候,默认执行的,很遗憾,15.04的btrfs版本号是3.17.

  • Btrfs的常用命令

显示btfs文件系统信息

$sudo btrfs fi show
Label: none uuid: 6fb44e01-f148-41c7-8448-17b58089f908
Total devices 1 FS bytes used 43.42GiB
devid 1 size 88.00GiB used 46.06GiB path /dev/sdb7

Btrfs v3.17

btrfs磁盘文件检查(需要重启进入修复模式中执行)

sudo btrfs check --repair /dev/sda7
  • 参考链接

Btrfs Problem_FAQ
Ubuntu thinks btrfs disk is full but its not

Ubuntu thinks btrfs disk is full but its not

由于国外网站经常打不开,因此内容直接复制到这里 原文链接

Btrfs is different from traditional filesystems. It is not just a layer that translates filenames into offsets on a block device, it is more of a layer that combines a traditional filesystem with LVM and RAID. And like LVM, it has the concept of allocating space on the underlying device, but not actually using it for files.

A traditional filesystem is divided into files and free space. It is easy to calculate how much space is used or free:

|--------files--------|                                                |
|------------------------drive partition-------------------------------|

Btrfs combines LVM, RAID and a filesystem. The drive is divided into subvolumes, each dynamically sized and replicated:

|--files--|    |--files--|         |files|         |                   |
|----@raid1----|------@raid1-------|-----@home-----|metadata|          |
|------------------------drive partition-------------------------------|

The diagram shows the partition being divided into two subvolumes and metadata. One of the subvolumes is duplicated (RAID1), so there are two copies of every file on the device. Now we not only have the concept of how much space is free at the filesystem layer, but also how much space is free at the block layer (drive partition) below it. Space is also taken up by metadata.

When considering free space in Btrfs, we have to clarify which free space we are talking about - the block layer, or the file layer? At the block layer, data is allocated in 1GB chunks, so the values are quite coarse, and might not bear any relation to the amount of space that the user can actually use. At the file layer, it is impossible to report the amount of free space because the amount of space depends on how it is used. In the above example, a file stored on the replicated subvolume @raid1 will take up twice as much space as the same file stored on the @homesubvolume. Snapshots only store copies of files that have been subsequently modified. There is no longer a 1-1 mapping between a file as the user sees it, and a file as stored on the drive.

You can check the free space at the block layer with btrfs filesystem show / and the free space at the subvolume layer with btrfs filesystem df /


# df -h
Filesystem              Size  Used Avail Use% Mounted on
/dev/mapper/sda4_crypt   38G   12G   13M 100% /

For this mounted subvolume, df reports a drive of total size 38G, with 12G used, and 13M free. 100% of the available space has been used. Remember that the total size 38G is divided between different subvolumes and metadata - it is not exclusive to this subvolume.

# btrfs filesystem df /
Data, single: total=9.47GiB, used=9.46GiB
System, DUP: total=8.00MiB, used=16.00KiB
System, single: total=4.00MiB, used=0.00
Metadata, DUP: total=13.88GiB, used=1.13GiB
Metadata, single: total=8.00MiB, used=0.00

Each line shows the total space and the used space for a different data type and replication type. The values shown are data stored rather than raw bytes on the drive, so if you're using RAID-1 or RAID-10 subvolumes, the amount of raw storage used is double the values you can see here.

The first column shows the type of item being stored (Data, System, Metadata). The second column shows whether a single copy of each item is stored (single), or whether two copies of each item are stored (DUP). Two copies are used for sensitive data, so there is a backup if one copy is corrupted. For DUP lines, the used value has to be doubled to get the amount of space used on the actual drive (because btrfs fs df reports data stored, not drive space used). The third and fourth columns show the total and used space. There is no free column, since the amount of "free space" is dependent on how it is used.

The thing that stands out about this drive is that you have 9.47GiB of space allocated for ordinary files of which you have used 9.46GiB - this is why you are getting No space left on device errors. You have 13.88GiB of space allocated for duplicated metadata, of which you have used 1.13GiB. Since this metadata is DUP duplicated, it means that 27.76GiB of space has been allocated on the actual drive, of which you have used 2.26GiB. Hence 25.5GiB of the drive is not being used, but at the same time is not available for files to be stored in. This is the "Btrfs huge metadata allocated"problem. To try and correct this, run btrfs balance start -m /. The -m parameter tells btrfs to only re-balance metadata.

A similar problem is running out of metadata space. If the output had shown that the metadata were actually full (used value close to total), then the solution would be to try and free up almost empty (<5% used) data blocks using the command btrfs balance start -dusage=5 /. These free blocks could then be reused to store metadata.

For more details see the Btrfs FAQs:

Ubuntu下的截图编辑软件Shutter

使用习惯了Windows下的QQ截图MAC下面的Skitch,能够非常方便的进行窗口的截图,并且使用箭头,矩形等编辑工具,对图片进行编辑,注释。Ubuntu下的搜索了好长时间才找到功能差不多的图片备注软件Shutter

安装命令

#安装依赖库
$ sudo apt install  libgoo-canvas-perl

$ sudo apt-get install shutter

也可以在Ubuntu软件中心中搜索 Shutter 来安装。

简单的使用参考下面的图片:
Shutter_Main
Shutter_Edit

Linux计算MD5和Sha1的命令

MD5

MD5即Message-Digest Algorithm 5(信息-摘要算法 5),用于确保信息传输完整一致。是计算机广泛使用的杂凑算法之一(又译摘要算法、哈希算法),主流编程语言普遍已有MD5实现。

Sha1

安全散列算法(英语:Secure Hash Algorithm)是一种能计算出一个数位讯息所对应到的,长度固定的字串(又称讯息摘要)的算法。且若输入的讯息不同,它们对应到不同字串的机率很高;而SHA是FIPS所认证的五种安全散列算法。这些算法之所以称作“安全”是基于以下两点(根据官方标准的描述):“1)由讯息摘要反推原输入讯息,从计算理论上来说是很困难的。2)想要找到两组不同的讯息对应到相同的讯息摘要,从计算理论上来说也是很困难的。任何对输入讯息的变动,都有很高的机率导致其产生的讯息摘要迥异。

MD5 与 SHA1 是当前最常用的两种哈希算法。那在Linux下如何计算这两种哈希值呢,基本上所有的 Linux 发行版都内置了这两个命令,比如要校检的文件命为OurUnix.tar:

计算文件的 MD5 – md5sum

$ md5sum OurUnix.tar
b9555cc1915652237948e37ccc9c484e OurUnix.tar

计算文件的 SHA1 – sha1sum

$sha1sum OurUnix.tar
bb7d67fb5776c2854edf35ec4a585ff8adc3dbda OurUnix.tar

引用 Linux计算MD5和Sha1的命令

Linux下新的网络管理工具ip替代ifconfig零压力

wKiom1XVQvajRv9nAAGSTCXZEBI308

如果你使用 Linux 足够久,那么你自然知道一些工具的来与去。2009年 Debian 开发者邮件列表宣布放弃使用缺乏维护的 net-tools 工具包正是如此。到今天 net-tools 仍然被部分人们所使用。事实上,在 Ubuntu 14.10 中你依旧可以使用 ifconfig 命令来管理你的网络配置。

然而在某些情况下(例如, Ubuntu Docker 容器), net-tools 工具包将不会被默认安装,这就意味着不能使用 ifconfig 。尽管如此,还是可以用软件仓库来安装 net-tools 。

$ sudo apt-get install net-tools

由于 net-tools 不再维护,我们强烈建议以 ip 命令代替 ifconfig。更重要的是 ip 在代替 ifconfig 的基础上表现得更好。

有趣的是 ip 不只是 ifconfig 的一个替代品,这两个命令在结构上有很多不同。即便如此,它们却都用于同一个目的。实际上 ip 命令可以完成下面所有事务。

  • 列出系统上配置了哪些网络接口
  • 查看网络接口的状态
  • 配置网络接口(包括本地环路和以太网)
  • 启用或禁用网络接口
  • 管理默认静态路由
  • IP 隧道配置
  • 配置 ARP 或 NDISC 缓存条目

接下来就让我们按上面说的试着用 ip 代替 ifconfig 。 我将例举一些简单的例子说明怎么使用 ip 命令。要正确使用并理解这些命令需要 root 权限,你可以用 su 切换到 root 用户或着使用 sudo 。因为这些命令将会改变你机器的网络信息。小心谨慎使用

注意:演示中用的地址仅作演示,具体到你的计算机时,会由你的网络以及硬件而不一样。

接下来,开始吧!

收集信息

多数人学习使用 ifconfig 做的第一件事就是查看网络接口上分配的 IP 地址。直接终端输入 ifconfig 不带任何参数回车即可看到。那么使用 ip 来做到这点我们只需要这样。

$ ip a

这条命令将会列出所有网络接口的相关信息。

你说你只想看 IPv4 相关信息,那么可以这样。

$ ip -4 a

你又说你想看特定的网络接口的相关信息,那么用如下命令查看无线网卡连接信息。

$ ip a show wlan0

你甚至可以定位更具体的信息,欲查看 wlan0 上的 IPv4 信息,那么可以这样。

$ ip -4 a show wlan0

还可以这样列出正在运行的网络接口。

$ ip link ls up

修改配置网络接口

接下来让我们来学习 ip 命令的核心功能——修改配置网络接口。假如你想为第一个以太网的网卡( eth0 )安排一个特定的地址。用 ifconfig 的话,看起来是这样的。

$ ifconfig eth0 192.168.1.101

那么用 ip 命令却是这样的。

$ ip a add 192.168.1.101/255.255.255.0 dev eth0

简短一点可以这样。

$ ip a add 192.168.1.101/24 dev eth0

显然这样的话,你需要知道你要安排的地址的子网掩码。

同样的方式,你可以这样删除一个网卡的地址。

$ ip a del 192.168.1.101/24 dev eth0

如果你想简单的清除所有接口上的所有地址,只需要这样即可。

$ ip -s -s a f to 192.168.1.0/24

ip 命令另一方面还能激活/禁用网络接口。

禁用 eth0 

$ ip link set dev eth0 down

激活 eth0

$ ip link set dev eth0 up

使用 ip 命令,我们还可以添加/删除默认的网关,就像这样。

$ ip route add default via 192.168.1.254

如果你想获得网络接口的更多细节,你可以编辑传输队列,给速度慢的接口设置一个低值,给速度快的设置一个较高值。那么你需要像这样做。

$ ip link set txqueuelen 10000 dev eth0

该命令设置了一个很长的传输队列。你应该设置一个最适合你硬件的值。

还可以用 ip 命令为网络接口设置最大传输单元。

$ ip link set mtu 9000 dev eth0

一旦你做了改变,便可以使用 ip a list eth0 来检验是否生效。

管理路由表

其实还可以使用 ip 命令来管理系统路由表。这是 ip 命令非常有用的一个功能。并且你应该小心使用

查看所有路由表。

$ ip r

输出结果将像下图所示。

wKiom1XVQySyp5CgAACNl1KcyA0951

现在你想要路由的所有流量从 eth0 网卡的192.168.1.254网关通过,那么请这样做。

$ ip route add 192.168.1.0/24 dev eth0

删除这个路由。

$ ip route del 192.168.1.0/24 dev eth0

这篇文章仅仅对 ip 命令进行了一些介绍。不是要求你马上使用 ip 命令。你可以继续使用 ifconfig 。因为 ifconfig 的弃 用相当的慢,很多发行版里依旧默认安装了该命令。但是相信最终会逐步被 ip 命令完全取代。看过这篇介绍,到时候你便能很快的转换过去。如果你还想了解 更多 ip 命令的用法,请看 ip 命令的 man 手册。

参考链接


Linux下新的网络管理工具ip替代ifconfig零压力