Linux操作笔记

1.关闭死程序

[root@node3 ~]# ps -aux | grep fire
root 2105 0.0 0.0 112660 964 pts/0 S+ 15:10 0:00 grep –color=auto fire
root 10620 0.0 0.1 1215096 239328 ? Sl 1月11 19:02 /usr/lib64/firefox/firefox
[root@node3 ~]# kill -9 10620

2.动态显示

动态跟踪文件file的增长情况(output appended data as the file grows),tail会每隔一秒去检查一下文件是否增加新的内容,如果增加就追加在原来的输出后面显示。但这种情况,必须保证在执行tail命令时,文件已经存在
[root@webServer logs]# tail -f catalina.out

3.Ubuntu卸载软件

删除软件及其配置文件
apt-get –purge remove
删除没用的依赖包
apt-get autoremove

kylin@Ubuntu:~$ sudo apt-get remove --purge ant
kylin@Ubuntu:~$ sudo apt-get autoremove --purge ant

4.tar解压与压缩

解压到当前目录:
[root@webServer ~]# tar -zxvf xxx.tar.gz
解压到指定目录:
[root@hadron ~]# tar -zxvf xxx.tar.gz -C /opt
打包压缩命令:
[root@hadron ~]# tar -zcvf xxx.tar.gz xxx/

参数的意义

  • c Create a new archive.
  • t List the contents of an archive.
  • x Extract the contents of an archive.
  • f The archive file name is given on the command line (required whenever the tar output is going to a file)
  • M The archive can span multiple floppies.
  • v Print verbose output (list file names as they are processed).
  • u Add files to the archive if they are newer than the copy in the tar file.
  • z Compress or decompress files automatically.

5.zip加密与解密

加密,输入两次密码

[root@hadron ~]# zip -re data.zip data
Enter password: 
Verify password: 
  adding: data/ (stored 0%)
  adding: data/house.zip (stored 0%)
  adding: data/test_doc.zip (stored 0%)
  adding: data/whitewines.zip (stored 0%)
  adding: data/20news-small.zip (stored 0%)

解压,输入密码

[root@hadron ~]# unzip data.zip 
Archive:  data.zip
   creating: data/
[data.zip] data/house.zip password: 
 extracting: data/house.zip          
 extracting: data/test_doc.zip       
 extracting: data/whitewines.zip     
 extracting: data/20news-small.zip 

6.CentOS7 设置截图的快捷键

1) 截图工具所在位置:应用(Applications)-工具(Utilities)-截图(Screenshot)
2) 快捷键设置的位置:应用程序(Applications)-系统工具(System Tools)-设置(Settings)-键盘(Keyboard)
3) 切换到快捷键选项卡:快捷键(Shortcuts),找到截图(Screenshots),单击右侧想要设置的项,按下要设置的快捷键即可(不用输入)。比如:我常用的是选定区域的截图(Save a screenshot of an area to Pictures),并且我使用的比较多的快捷键是QQ的截图快捷键(Ctrl+Alt+A)
这里写图片描述

7.hosts

Hosts文件是一个用于储存计算机网络中各节点信息的计算机文件。这个文件负责将主机名映射到相应的IP地址。hosts文件通常用于补充或取代网络中DNS的功能。和DNS不同的是,计算机的用户可以直接对hosts文件进行控制。
hosts文件在不同操作系统(甚至不同Windows版本)的位置都有所区别:

  • Windows系统
    一般在C:\WINDOWS\system32\drivers\etc目录下
  • Linux系统
    在/etc目录下

8.SSH

8.1 无选项参数运行 SSH

默认的,ssh 会尝试用当前用户作为用户名来连接。

[root@hadron ~]# ssh 192.168.1.160
The authenticity of host '192.168.1.160 (192.168.1.160)' can't be established.
ECDSA key fingerprint is ac:f1:e0:63:72:f7:1c:70:a5:4f:65:2b:ab:0d:9f:12.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.160' (ECDSA) to the list of known hosts.
root@192.168.1.160's password: 
Last login: Wed Mar 15 00:39:04 2017 from 192.168.1.81
[root@cnode0 ~]# exit
登出
Connection to 192.168.1.160 closed.

本示例命令中,ssh 会尝试用root的用户身份来登入192.168.1.160服务器

8.2 指定登录用户

因为192.168.1.156是Ubuntu服务器,不能使用root用户登录,这时可以指定用户登录。

[root@hadron ~]# ssh kylin@192.168.1.156
The authenticity of host '192.168.1.156 (192.168.1.156)' can't be established.
ECDSA key fingerprint is b2:34:8c:09:32:d2:1a:cb:cf:c2:60:ed:ad:d9:d7:46.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.156' (ECDSA) to the list of known hosts.
kylin@192.168.1.156's password: 
Welcome to YHKylin 4.0-1D (GNU/Linux 3.14.57-20160128.kylin.4.server.generic+ aarch64)
Last login: Tue Mar 15 09:00:09 2016 from 192.168.1.81
kylin@tdh02:~$ 

9 scp

9.1 复制文件

命令格式1:
scp local_file remote_username@remote_ip:remote_folder
或者
scp local_file remote_username@remote_ip:remote_file

命令格式2:
scp local_file remote_ip:remote_folder
或者
scp local_file remote_ip:remote_file

命令格式1指定了用户名,命令执行后需要输入用户密码,第1个命令仅指定了远程的目录,文件名字不变,第2个指定了文件名(可以自定义文件名)
比如:

[root@anode1 ~]# scp ReadFile.jar root@192.168.1.81:/root/ReadFile2.jar
root@192.168.1.81's password: 
ReadFile.jar                             100% 1248     1.2KB/s   00:00

到81机器上查询

[root@hadron ~]# ls |grep ReadFile2.jar
ReadFile2.jar

命令格式2没有指定用户名,默认是当前用户”root”访问

[root@anode1 ~]# scp ReadFile.jar 192.168.1.81:/root/
root@192.168.1.81's password: 
ReadFile.jar                             100% 1248     1.2KB/s   00:00    

到81机器上查询

[root@hadron ~]# ls |grep ReadFile.jar
ReadFile.jar

9.2 复制目录

命令格式:
scp -r local_folder remote_username@remote_ip:remote_folder

或者
scp -r local_folder remote_ip:remote_folder

10 清空历史命令记录

可以通过history命令查看之前执行的命令

[root@hadron ~]# history
   18  sh ./a.out 
   19  ./a.out &
   20  ls
   21  ./a.out &
   22  ls
   23  cd source/
   24  ls
   25  cd 
   26  ls
   27  cd python/
.....

使用history -c命令清空历史命令记录

[root@hadron ~]# history -c
[root@hadron ~]# history
   25  history

11 开机默认进入命令界面(文本界面)

针对于CentOS7,使用systemctl set-default multi-user.target命令

[root@hadron ~]# systemctl set-default multi-user.target

然后重启系统即可

12 解压rar

wget http://www.rarlab.com/rar/rarlinux-3.8.0.tar.gz
tar zxvf rarlinux-3.8.0.tar.gz
cd rar
make
make install

[root@hadron opt]# wget http://www.rarlab.com/rar/rarlinux-3.8.0.tar.gz
--2017-06-23 14:45:45--  http://www.rarlab.com/rar/rarlinux-3.8.0.tar.gz
正在解析主机 www.rarlab.com (www.rarlab.com)... 5.135.104.98
正在连接 www.rarlab.com (www.rarlab.com)|5.135.104.98|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:791915 (773K) [application/x-gzip]
正在保存至: “rarlinux-3.8.0.tar.gz100%[==============================================================================================================>] 791,915      645KB/s 用时 1.2s   

2017-06-23 14:45:46 (645 KB/s) - 已保存 “rarlinux-3.8.0.tar.gz” [791915/791915])

[root@hadron opt]# tar -zxvf rarlinux-3.8.0.tar.gz
rar/
rar/readme.txt
rar/rarfiles.lst
rar/unrar
rar/rar
rar/license.txt
rar/file_id.diz
rar/order.htm
rar/whatsnew.txt
rar/Makefile
rar/rar.txt
rar/technote.txt
rar/default.sfx
rar/rar_static
[root@hadron opt]# cd rar
[root@hadron rar]# make
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
cp rar unrar /usr/local/bin
cp rarfiles.lst /etc
cp default.sfx /usr/local/lib
[root@hadron rar]# make install 
mkdir -p /usr/local/bin
mkdir -p /usr/local/lib
cp rar unrar /usr/local/bin
cp rarfiles.lst /etc
cp default.sfx /usr/local/lib

遇到问题

[root@hadron rar]# rar
bash: /usr/local/bin/rar: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录

因为64位系统中安装了32位程序,两种解决办法
方法1

[root@hadron rar]# yum install glibc.i686
[root@hadron rar]# yum install libstdc++

方法2

[root@hadron rar]# cp rar_static /usr/local/bin/rar
cp:是否覆盖"/usr/local/bin/rar"? y

这样rar命令可以使用了

[root@hadron rar]# rar

RAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008
Shareware version         Type RAR -? for help

Usage:     rar <command> -<switch 1> -<switch N> <archive> <files...>
               <@listfiles...> <path_to_extract\>

<Commands>
  a             Add files to archive
  c             Add archive comment
  cf            Add files comment
  ch            Change archive parameters
  cw            Write archive comment to file
  d             Delete files from archive
  e             Extract files to current directory
  f             Freshen files in archive
  i[par]=<str>  Find string in archives
  k             Lock archive
  l[t,b]        List archive [technical, bare]
  m[f]          Move to archive [files only]
  p             Print file to stdout
  r             Repair archive
  rc            Reconstruct missing volumes
  rn            Rename archived files
  rr[N]         Add data recovery record
  rv[N]         Create recovery volumes
  s[name|-]     Convert archive to or from SFX
  t             Test archive files
  u             Update files in archive
  v[t,b]        Verbosely list archive [technical,bare]
  x             Extract files with full path

13 文件比较diff

diff输出格式(默认):
n1 a n3,n4 表示在文件1的n1行后面添加n3到n4行
n1,n2 d n3 表示在n1到n2行之间删除n3行
n1,n2 c n3,n4 表示把n1,n2行用n3,n4行替换掉
字母a:表示附加(add)
字符c:表示修改(change)
字符d:表示删除(delete)
字母前的是源文件,字母后是目标文件。Nx表示行号。
以”<”打头的行属于第一个文件,以”>”打头的行属于第二个文件。

a.txt

aa
bbb
ccccc
1
2
3
4

b.txt

aa
bbb
cccc
1
2
3

4

diff命令

[root@hadron diff]# diff a.txt b.txt
3c3
< ccccc
---
> cccc
6a7
> 

上面的“3c3”表示a.txt的第3行和b.txt的第3行内容有所不同,以”<”打头的行属于第一个文件(a.txt),以”>”打头的行属于第二个文件(b.txt)。

14 md5

md5sum校验的是文件内容,与文件名无关

root@kylin2:/opt# md5sum Manager-Kylin-20170814.tar.gz 
ebcf5491a121dc80bee069fa872ab71c Manager-Kylin-20170814.tar.gz
[root@hadron Kylin]# md5sum Manager-Kylin-20170814.tar.gz
ebcf5491a121dc80bee069fa872ab71c  Manager-Kylin-20170814.tar.gz
[root@hadron Kylin]# 

可以确定两个Manager-Kylin-20170814.tar.gz文件是相同的。

[root@hadron Kylin]# md5sum web*
bc92d8103cbfb473c9854717f3e1677b  store.tar.gz
9067a8b723f5229b49eeef0ff46bc66d  store.bak
[root@hadron Kylin]# 

可知道store.tar.gz和 store.bak内容不同!

16 查看磁盘空间

df命令用于显示目前在Linux系统上的文件系统的磁盘使用情况统计
-h, –human-readable 使用人类可读的格式

[root@node3 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       147G  130G   18G  89% /
devtmpfs         63G     0   63G   0% /dev
tmpfs            63G  172K   63G   1% /dev/shm
tmpfs            63G  418M   63G   1% /run
tmpfs            63G     0   63G   0% /sys/fs/cgroup
/dev/sda3       271G   13G  258G   5% /data
tmpfs            13G   52K   13G   1% /run/user/0
/dev/loop2      7.8G  7.8G     0 100% /var/ftp/iso-home
[root@node3 ~]# df -h /tmp
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       147G  130G   18G  89% /
[root@node3 ~]#

du命令用于显示指定的目录或文件所占用的磁盘空间,
-h或–human-readable 以K,M,G为单位,提高信息的可读性。

[root@node3 ~]# du -h /tmp
0   /tmp/.ICE-unix
0   /tmp/.font-unix
0   /tmp/.X11-unix
0   /tmp/.Test-unix
0   /tmp/.XIM-unix
0   /tmp/.esd-0
0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-httpd.service-6X6p8Z/tmp
0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-httpd.service-6X6p8Z
0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-rtkit-daemon.service-SPYDCq/tmp
0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-rtkit-daemon.service-SPYDCq
0   /tmp/ssh-5ip8dhXgZeo5
0   /tmp/ssh-zhmfU1HmgApU
14M /tmp
[root@node3 ~]#

17 sed命令

sed -i通过选项i可以直接修改文件内容,语法如下。

sed -i 's/要被取代的串/新串/g' filePath

其中s是替换命令,s后包含在斜杠中的文本是正则表达式,后面跟着的是需要替换的文本。可以通过 g 标志对行进行全局替换。

[root@master ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

如果被替换的字符串或新字符串中包含了/,则可以用#替换命令中的/。示例如下

[root@master hadoop]# sed -i 's#export JAVA_HOME=${JAVA_HOME}#export JAVA_HOME=/usr/java/jdk1.8.0_144#' hadoop-env.sh 

18 &与nohup

普通进程用&符号放到后台运行,如果启动该程序的控制台(Shell)退出后,则该进程随即终止。

nohup <程序名> &
该方式运行程序,则控制台logout后,进程仍然继续运行,起到守护进程的作用
使用nohup命令后,原程序的的标准输出被自动改向到当前目录下的nohup.out文件,起到了log的作用,实现了完整的守护进程功能。

19 统计目录下的文件或目录数

[root@node1 ~]# ls -l |grep "^-"|wc -l
17
[root@node1 ~]# ls -l |grep "^d"|wc -l
10
[root@ndoe1 ~]# 

说明:
(1)ls -l :
列出当前文件夹下文件信息
(2)grep “^-” :
“^-“是正则表达式,以“-”开头的表示文件,也就是查找一般文件;如果查找目录就是 ^d,
(3) wc -l :
统计输出信息的行数

20 查找当前目录下(包含子目录)某类文件个数

[root@node1 ~]# find . -type f -name "*.rar" | wc -l
81
[root@node1 ~]#

终端显示样式

\33[0m 关闭所有属性
\33[1m 设置高亮度
\33[7m 反显

\33[30m – \33[37m 设置前景色
\33[40m – \33[47m 设置背景色

[root@hadron ~]# echo -e “\033[1m something here \033[0m”
something here
[root@hadron ~]# echo -e “\033[7m something here \033[0m”
something here
[root@hadron ~]# echo -e “\033[41;36m something here \033[0m”
something here
[root@hadron ~]#
这里写图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值