首页 > 运维 > linux运维 > 正文

Linux操作笔记

星夢妙者
发布: 2025-07-10 13:30:13
原创
855人浏览过

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

代码语言:javascript代码运行次数:0运行复制
kylin@Ubuntu:~$ sudo apt-get remove --purge antkylin@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加密与解密

加密,输入两次密码

代码语言:javascript代码运行次数:0运行复制
[root@hadron ~]# zip -re data.zip dataEnter 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%)
登录后复制

解压,输入密码

代码语言:javascript代码运行次数: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)

Linux操作笔记
7.hosts

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

Windows系统 一般在C:\WINDOWS\system32\drivers\etc目录下Linux系统 在/etc目录下 8.SSH8.1 无选项参数运行 SSH

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

代码语言:javascript代码运行次数:0运行复制
[root@hadron ~]# ssh 192.168.1.160The 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)? yesWarning: 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用户登录,这时可以指定用户登录。

代码语言:javascript代码运行次数:0运行复制
[root@hadron ~]# ssh kylin@192.168.1.156The 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)? yesWarning: 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.81kylin@tdh02:~$ 
登录后复制
9 scp9.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个指定了文件名(可以自定义文件名) 比如:

代码语言:javascript代码运行次数:0运行复制
[root@anode1 ~]# scp ReadFile.jar root@192.168.1.81:/root/ReadFile2.jarroot@192.168.1.81's password: ReadFile.jar                             100% 1248     1.2KB/s   00:00
登录后复制

到81机器上查询

代码语言:javascript代码运行次数:0运行复制
[root@hadron ~]# ls |grep ReadFile2.jarReadFile2.jar
登录后复制

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

代码语言:javascript代码运行次数:0运行复制
[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机器上查询

代码语言:javascript代码运行次数:0运行复制
[root@hadron ~]# ls |grep ReadFile.jarReadFile.jar
登录后复制
9.2 复制目录

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

或者 scp -r local_folder remote_ip:remote_folder

10 清空历史命令记录

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

代码语言:javascript代码运行次数:0运行复制
[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命令清空历史命令记录

代码语言:javascript代码运行次数:0运行复制
[root@hadron ~]# history -c[root@hadron ~]# history   25  history
登录后复制
11 开机默认进入命令界面(文本界面)

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

代码语言:javascript代码运行次数:0运行复制
[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

代码语言:javascript代码运行次数:0运行复制
[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.gz”100%[==============================================================================================================>] 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.gzrar/rar/readme.txtrar/rarfiles.lstrar/unrarrar/rarrar/license.txtrar/file_id.dizrar/order.htmrar/whatsnew.txtrar/Makefilerar/rar.txtrar/technote.txtrar/default.sfxrar/rar_static[root@hadron opt]# cd rar[root@hadron rar]# makemkdir -p /usr/local/binmkdir -p /usr/local/libcp rar unrar /usr/local/bincp rarfiles.lst /etccp default.sfx /usr/local/lib[root@hadron rar]# make install mkdir -p /usr/local/binmkdir -p /usr/local/libcp rar unrar /usr/local/bincp rarfiles.lst /etccp default.sfx /usr/local/lib
登录后复制

遇到问题

代码语言:javascript代码运行次数:0运行复制
[root@hadron rar]# rarbash: /usr/local/bin/rar: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录
登录后复制

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

代码语言:javascript代码运行次数:0运行复制
[root@hadron rar]# yum install glibc.i686[root@hadron rar]# yum install libstdc++
登录后复制

方法2

代码语言:javascript代码运行次数:0运行复制
[root@hadron rar]# cp rar_static /usr/local/bin/rarcp:是否覆盖"/usr/local/bin/rar"? y
登录后复制

这样rar命令可以使用了

代码语言:javascript代码运行次数:0运行复制
[root@hadron rar]# rarRAR 3.80   Copyright (c) 1993-2008 Alexander Roshal   16 Sep 2008Shareware version         Type RAR -? for helpUsage:     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

代码语言:javascript代码运行次数:0运行复制
aabbbccccc1234
登录后复制

b.txt

代码语言:javascript代码运行次数:0运行复制
aabbbcccc1234
登录后复制

diff命令

代码语言:javascript代码运行次数:0运行复制
[root@hadron diff]# diff a.txt b.txt3c3< ccccc---> cccc6a7> 
登录后复制

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

14 md5

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

代码语言:javascript代码运行次数:0运行复制
root@kylin2:/opt# md5sum Manager-Kylin-20170814.tar.gz ebcf5491a121dc80bee069fa872ab71c Manager-Kylin-20170814.tar.gz
登录后复制
代码语言:javascript代码运行次数:0运行复制
[root@hadron Kylin]# md5sum Manager-Kylin-20170814.tar.gzebcf5491a121dc80bee069fa872ab71c  Manager-Kylin-20170814.tar.gz[root@hadron Kylin]# 
登录后复制

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

代码语言:javascript代码运行次数:0运行复制
[root@hadron Kylin]# md5sum web*bc92d8103cbfb473c9854717f3e1677b  store.tar.gz9067a8b723f5229b49eeef0ff46bc66d  store.bak[root@hadron Kylin]# 
登录后复制

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

16 查看磁盘空间

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

代码语言:javascript代码运行次数:0运行复制
[root@node3 ~]# df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda1       147G  130G   18G  89% /devtmpfs         63G     0   63G   0% /devtmpfs            63G  172K   63G   1% /dev/shmtmpfs            63G  418M   63G   1% /runtmpfs            63G     0   63G   0% /sys/fs/cgroup/dev/sda3       271G   13G  258G   5% /datatmpfs            13G   52K   13G   1% /run/user/0/dev/loop2      7.8G  7.8G     0 100% /var/ftp/iso-home[root@node3 ~]# df -h /tmpFilesystem      Size  Used Avail Use% Mounted on/dev/sda1       147G  130G   18G  89% /[root@node3 ~]#
登录后复制

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

代码语言:javascript代码运行次数:0运行复制
[root@node3 ~]# du -h /tmp0   /tmp/.ICE-unix0   /tmp/.font-unix0   /tmp/.X11-unix0   /tmp/.Test-unix0   /tmp/.XIM-unix0   /tmp/.esd-00   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-httpd.service-6X6p8Z/tmp0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-httpd.service-6X6p8Z0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-rtkit-daemon.service-SPYDCq/tmp0   /tmp/systemd-private-036161d78b1c4e4b9f6d079205611ea4-rtkit-daemon.service-SPYDCq0   /tmp/ssh-5ip8dhXgZeo50   /tmp/ssh-zhmfU1HmgApU14M /tmp[root@node3 ~]#
登录后复制
17 sed命令

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

代码语言:javascript代码运行次数:0运行复制
sed -i 's/要被取代的串/新串/g' filePath
登录后复制

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

代码语言:javascript代码运行次数:0运行复制
[root@master ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
登录后复制

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

代码语言:javascript代码运行次数:0运行复制
[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 统计目录下的文件或目录数代码语言:javascript代码运行次数:0运行复制
[root@node1 ~]# ls -l |grep "^-"|wc -l17[root@node1 ~]# ls -l |grep "^d"|wc -l10[root@ndoe1 ~]# 
登录后复制

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

20 查找当前目录下(包含子目录)某类文件个数代码语言:javascript代码运行次数:0运行复制
[root@node1 ~]# find . -type f -name "*.rar" | wc -l81[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 ~]#

Linux操作笔记

以上就是Linux操作笔记的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号