记录常忘记的Linux命令


7.快速清空文件内容

使用>filename
>将输出重定向到文件,如果文件不存在就创建文件;如果文件存在就覆盖文件。
此处>前面不带输出,即用“空”去覆盖文件,也就清空了文件内容。


6.解压缩GBK/GB2312编码ZIP文件

由于zip格式没有指定编码格式,Windows下的编码格式为GBK/GB2312等,Linux下默认编码格式为UTF8,故有些zip文件在Linux下解压时会出现乱码问题。
使用unzip -O cp936 xxx.zip指定字符编码则能正常解压缩。
-O CHARSET为DOS、Windows和OS/2 生成的压缩文件指定字符编码。
cp936即GBK,IBM在发明Code Page的时候将GBK放在第936页。

[260174@w26-260174 Senesors]$ unzip
UnZip 6.00 of 20 April 2009, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment only
  -v  list verbosely/show version info       -T  timestamp archive to latest
  -x  exclude files that follow (in xlist)   -d  extract files into exdir
modifiers:
  -n  never overwrite existing files         -q  quiet mode (-qq => quieter)
  -o  overwrite files WITHOUT prompting      -a  auto-convert any text files
  -j  junk paths (do not make directories)   -aa treat ALL files as text
  -U  use escapes for all non-ASCII Unicode  -UU ignore any Unicode fields
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
  -K  keep setuid/setgid/tacky permissions   -M  pipe through "more" pager
  -O CHARSET  specify a character encoding for DOS, Windows and OS/2 archives
  -I CHARSET  specify a character encoding for UNIX and other archives

See "unzip -hh" or unzip.txt for more help.  Examples:
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer

5.关闭SSH连接

先使用wwho查看当前所有连接,再使用who am i查看自己的连接,最后使用pkill -kill -t pts/x关闭不需要的ssh连接。

[lch@test ~]$ who
lch      pts/0        2017-11-01 10:17 (x.x.x.x)
lhq      pts/1        2017-10-31 17:01 (172.27.15.17)
yzx      pts/2        2017-11-01 07:34 (172.27.15.21)
lhq      pts/3        2017-11-01 10:20 (172.27.15.17)
lch      pts/4        2017-11-01 10:22 (x.x.x.x)
[lch@test ~]$ who am i 
lch      pts/0        2017-11-01 10:17 (x.x.x.x)
[lch@test ~]$ pkill -kill -t pts/4
[lch@test ~]$ who
lch      pts/0        2017-11-01 10:17 (x.x.x.x)
lhq      pts/1        2017-10-31 17:01 (172.27.15.17)
yzx      pts/2        2017-11-01 07:34 (172.27.15.21)
lhq      pts/3        2017-11-01 10:20 (172.27.15.17)

4. 重启网络

修改配置文件后重启网络用service network restart
使用ifconfig查看仍未获取ip地址,查看/etc/sysconfig/network-scripts/ifcfg-ethxxx文件中ONBOOTBOOTPROTO属性值,ONBOOT=yes表示在系统启动时激活网卡,BOOTPROTO=dhcp表示使用dhcp服务自动获取ip地址,BOOTPROTO=static表示使用静态ip地址,BOOTPROTO=none表示未指定协议。


3. CentOS 7 启动界面选择

不再修改/etc/inittab文件里的runlevel
默认图形界面:systemctl set-default graphical.target
字符(命令行)界面:systemctl set-default multi-user.target
/etc/inittab文件内容如下:

# inittab is no longer used when using systemd. 
# 
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM. 
# 
# Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target 
# 
# systemd uses 'targets' instead of runlevels. By default, there are two main targets: 
# 
# multi-user.target: analogous to runlevel 3 
# graphical.target: analogous to runlevel 5 
# 
# To view current default target, run: 
# systemctl get-default 
# 
# To set a default target, run: 
# systemctl set-default TARGET.target 

2. 建立文件/目录链接

-s为软链接。
链接到目录的话,目录最后需要有/

root@ubuntu:/# ls -l | grep relearn
root@ubuntu:/# ln -s /mnt/hgfs/linuxc_relearn/ relearn
root@ubuntu:/# ls -l | grep relearn
lrwxrwxrwx   1 root root    25 Jan  4 06:48 relearn -> /mnt/hgfs/linuxc_relearn/
root@ubuntu:/# cd relearn
root@ubuntu:/relearn# ls
1.txt
root@ubuntu:/relearn# 

1. 重启ssh服务

有时ping得通但ssh不上Fedora。

[root@localhost uart_test]# service sshd restart
Redirecting to /bin/systemctl restart  sshd.service
[root@localhost uart_test]# 

猜你喜欢

转载自blog.csdn.net/hxiaohai/article/details/53695592
今日推荐