标签 linux 下的文章

Ubuntu:

sudo update-alternatives --config editor

There are 4 choices for the alternative editor (providing /usr/bin/editor).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /bin/nano            40        auto mode
  1            /bin/ed             -100       manual mode
  2            /bin/nano            40        manual mode
  3            /usr/bin/vim.basic   30        manual mode
  4            /usr/bin/vim.tiny    10        manual mode

Press <enter> to keep the current choice[*], or type selection number:

Non-interactive solution for setting vim as default editor:

sudo update-alternatives --set editor /usr/bin/vim.basic

CentOS:

On CentOS, you can change this value by adding the following line to your ~/.bashrc:

$ export EDITOR=`which name_of_editor`

Source the file to implement the changes:

$ source ~/.bashrc

sudo update-alternatives --set editor /usr/bin/vim.basic

The aim: to make checking system resource usage a little more accessible, ideally with historical data thrown into the mix for some added context.

Two years on and the fruits of that redesigned effort are finally available to sample, albeit through a new app called (aptly enough) GNOME Usage.

gnome-usage.jpg

A new version of Usage is set to be released alongside GNOME 3.28 in March, and, accordingly, will be available to install in Ubuntu 18.04 LTS.

But how’s the app looking?

Well, don’t get too excited. Despite being in development for a while the app doesn’t quite deliver on the lure of the early mock-ups. For instance, it doesn’t provide historical data (yet) or offer any stats on power usage.

Effectively Usage 3.28 only tells you what your computer is doing right now — a job the regular System Monitor app and CLI apps like top can do too.

That said, it’s nice enough. Even at this early stage it’s clear to see that Usage is well placed as user friendly alternative to GNOME System Monitor. Through the use of colorful graphs you can quickly see how system resources like RAM, CPU and network are being used.

GNOME Usage wants to relay all of the information the GNOME System Monitor tool does, but in a more modern and easier to parse manner, with less emphasis on interfering with processes, and more on inferring what they’re up to.

This first version is able to relay the following information:

  • Processor Usage
  • Memory usage
  • Network usage
  • Storage usage

It also lets you:

  • Filter processes by name
  • Browse & visualise storage

GNOME developers will hate me for saying it but Usage sort of reminds me of a mobile system resource app in that it’s designed to relay system information in a manner that’s instantly digestible. CLI tools like top and other process monitoring tools aren’t indecipherable, but understanding what they show requires a couple of minutes of orientation.

Usage is promising and I look forward to seeing it mature.

(Of course, nothing competes with the sheer system monitor bling of Deepin System Monitor!)
Reiteratium Disclamerium

Now, lest anyone misunderstand: Usage is not replacing System Monitor. Development on System Monitor is continuing (indeed, there are nice improvements coming in GNOME 3.28). They are two apps that do similar things, but in different ways, aimed at different users.

Got it? Get it? Good.
Install GNOME Usage on Ubuntu

If you’re running the Ubuntu 18.04 daily builds then you can try Usage out for yourself by installing it from Ubuntu Software.

https://www.omgubuntu.co.uk/2018/02/gnome-usage-in-ubuntu-18-04

修改阿里云CentOS Linux服务器的主机名(实例名)

阿里云主机的默认主机名是为AY开头的随机名称,如何修改为易于区分的友好名称呢?请看下面的操作步骤:

vi /etc/hosts

i键,修改主机名,esc键,:x键保存退出

vi /etc/sysconfig/network

i键,修改主机名(HOSTNAME=),esc键,:x键保存退出

输入以下命令:

hostname 新主机名

然后用ssh重新登录,就会显示新的主机名。

起因
最近使用nohup创建了一个后台进程,默认日志输出到了nohup.out文件中,程序跑起来也就没再管,过了大约一周,发现硬盘空间不够了,于是查找原因,发现这个nohup.out文件已经到了70G了,导致硬盘空间不足了。

解决方案

只输出错误信息到日志文件

nohup ./program >/dev/null 2>log &

什么信息也不要

nohup ./program >/dev/null 2>&1 &

知识补充,关于Linux的重定向

Linux的3中重定向

0:表示标准输入

1:标准输出,在一般使用时,默认的是标准输出

2:标准错误信息输出

可以用来指定需要重定向的标准输入或输出。例如,将某个程序的错误信息输出到log文件中:./program 2>log这样标准输出还是在屏幕上,但是错误信息会输出到log文件中。另外,也可以实现0,1,2之间的重定向。2>&1:将错误信息重定向到标准输出。

关于/dev/null文件

Linux下还有一个特殊的文件/dev/null,它就像一个无底洞,所有重定向到它的信息都会消失得无影无踪。这一点非常有用,当我们不需要回显程序的所有信息时,就可以将输出重定向到/dev/null

在CentOS 6更新后,不可避免的会在启动选项中产生多个内核选项,一个内核文件大概占100兆左右(一般100M以下),可以使用以下命令进行删除多余的内核.

1.首先列出系统中正在使用的内核:

# uname -a

2.查询系统中全部的内核:

# rpm -qa | grep kernel

3.将你想删除的内核删除掉:(例如,在我的系统中,我要删掉2.6.32-71.el6.i686的内核,需要把所有含有2.6.32-71.el6.i686字样的全部删掉)

#yum remove kernel-2.6.32-71.el6.i686
#yum remove kernel-devel-2.6.32-71.el6.i686

4.重启后就可以看到,内核被删掉了,同时多余的启动项也自动被删掉了,不需要自己手动修改/boot/grub/menu.lst

在默认情况下,linux终端输出的文字并不是彩色的。那么,如果想让linux输出彩色文本,那么应该怎么做呢? `echo -e
"e[1;颜色代码m显示的文字e[0m"`

  • 红色:31
  • 绿色:32
  • 黄色:33
  • 蓝色:34
  • 洋红:35
  • 青色:36
  • 白色:37
  • 黑色:38