深夜提醒

现在是深夜,建议您注意休息,不要熬夜哦~

🏮 🏮 🏮

新年快乐

祝君万事如意心想事成!

2024 桐庐半程马拉松
00:00:00
时间
0.00
距离(公里)
--:--
配速
--
步频
--
心率 (bpm)
--
配速
步频
|
share-image
ESC

Linux 常用命令

Linux 常用的命令

ls命令

-l 可以查文件的属性

[root@node-lvs-master ~]# ls -l
total 20
-rw-------. 1 root root 1439 Jan  6 17:31 anaconda-ks.cfg
-rw-r--r--. 1 root root 9913 Jan  6 17:31 install.log
-rw-r--r--. 1 root root 3161 Jan  6 17:30 install.log.syslog

提示: - rw- — — 三个一组,第一组是所属组 第二组 所有者 第三组 其他人 r 可读 w可写 x 可执行 d 目录 l表示软链接

-a 可以显示所有的文件 包括隐藏的文件

[root@node-lvs-master ~]# ls -a
.  ..  anaconda-ks.cfg  .bash_history  .bash_logout  .bash_profile  .bashrc  .cshrc  install.log  install.log.syslog  .ssh  .tcshrc  .xxx.log

-u 参数 显示最后的访问时间

[root@node-lvs-master ~]# ls -lu /etc/ssh/sshd_config 
-rw-------. 1 root root 3880 Jan  6 19:34 /etc/ssh/sshd_config

-t 以最后修改时间显示

[root@node-lvs-master ~]# ls -alt
total 56
dr-xr-x---.  3 root root 4096 Jan  6 19:47 .
-rw-r--r--.  1 root root    0 Jan  6 19:47 .xxx.log
drwx------.  2 root root 4096 Jan  6 19:38 .ssh
-rw-------.  1 root root   32 Jan  6 19:36 .bash_history
dr-xr-xr-x. 22 root root 4096 Jan  6 17:31 ..
-rw-------.  1 root root 1439 Jan  6 17:31 anaconda-ks.cfg
-rw-r--r--.  1 root root 9913 Jan  6 17:31 install.log
-rw-r--r--.  1 root root 3161 Jan  6 17:30 install.log.syslog
-rw-r--r--.  1 root root   18 May 20  2009 .bash_logout
-rw-r--r--.  1 root root  176 May 20  2009 .bash_profile
-rw-r--r--.  1 root root  129 Dec  4  2004 .tcshrc
-rw-r--r--.  1 root root  176 Sep 23  2004 .bashrc
-rw-r--r--.  1 root root  100 Sep 23  2004 .cshrc	 

man

查命令的详细使用文档,如果系统没有

yum -y install man

使用

 man [command]

例如

   [root@node-lvs-master ~]# man  whereis
WHEREIS(1)                                                          WHEREIS(1)

……

whereis

查看命令的路径

[root@node-lvs-master ~]# whereis --help
whereis [ -sbmu ] [ -SBM dir ... -f ] name...

例如:

[root@node-lvs-master ~]# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz

mkdir

创建目录

[root@node-lvs-master ~]# mkdir aaq
[root@node-lvs-master ~]# ls
aaq  anaconda-ks.cfg  install.log  install.log.syslog

touch

创建一个空文件或修改文件的时间

[root@node-lvs-master aaq]# touch aaa ##创建一个空文件
[root@node-lvs-master aaq]# ll 
total 0
-rw-r--r--. 1 root root 0 Jan  6 20:04 aaa ##注意时间,大小为0的空文件
[root@node-lvs-master aaq]# touch aaa ##再次执行,文件已存在,则修改文件的时间
[root@node-lvs-master aaq]# ll
total 0
-rw-r--r--. 1 root root 0 Jan  6 20:05 aaa

cp

拷贝

cp 源文件 目标文件
cp -rf 源文件 目标文件

##rm

删除

[root@node-lvs-master aaq]# rm aaa 
rm: remove regular empty file `aaa'? y
[root@node-lvs-master aaq]# rm -rf bbb 
[root@node-lvs-master aaq]# mkdir aa
[root@node-lvs-master aaq]# cd aa/
[root@node-lvs-master aa]# touch a b c
[root@node-lvs-master aa]# ls
a  b  c
[root@node-lvs-master aa]# cd ..
[root@node-lvs-master aaq]# ls
aa  lscpu
[root@node-lvs-master aaq]# rm aa/
rm: cannot remove `aa/': Is a directory
[root@node-lvs-master aaq]# rm -rf aa/ ## 加-rf 可以强制删除目录和目录下的所有文件
[root@node-lvs-master aaq]# 

参数

-r 删除目录以及目录下面的所有文件
-f 强制删除,没有提示
-i 会给出提示

小贴士: 慎用例如rm -rf /* 会破坏系统

##mv

mv 移动或剪切

mv 源文件  目标文件

find

查找文件

1.按文件名去查-name

[root@node-lvs-master ~]# find -name "*.xxx.log"
./.xxx.log

2.查找所有后缀*.log的文件

./.xxx.log
[root@node-lvs-master ~]# find /var/log/ "*.log"
/var/log/
/var/log/lastlog
/var/log/btmp
/var/log/wtmp
/var/log/messages
/var/log/spooler
/var/log/yum.log
/var/log/anaconda.xlog
/var/log/boot.log
/var/log/audit
/var/log/audit/audit.log

3.查空文件

[root@node-lvs-master z]# find /home/z/ -empty

4.按所属组查

[root@node-lvs-master z]# find /home/zengdan/ -group z

5.查所有3天内被修改过的文档

#find / -mtime -3

6.查3天前被修改过的文档

#find / -mtime +3

7.根据文件大小去查

#find / -size +10M //大于10M的文件

8.根据文件类型来查

#find / -type f #表示查普通文件

9.根据用户来查

	#find / -user tom

10.查完文件并列出详细信息

#find / -size +1M -exec ls -l {} \;

11.查大于1M的所有普通文件

#find / -size +1M -a -type f

du

计算文件或目录的容量

[root@node-lvs-master src]# du 
4       ./debug
4       ./kernels
12      .
[root@node-lvs-master src]# du -h #人性化显示
4.0K    ./debug
4.0K    ./kernels
12K     .
[root@node-lvs-master src]# du -sh #显示总容量
12K     .

##cat

查看文件内容,一般和管道符搭配使用

[root@node-lvs-master src]# cat /etc/ssh/sshd_config | more

1.统计文件行数

[root@node-lvs-master src]# cat -n /etc/ssh/sshd_config //显示空白行
[root@node-lvs-master src]# cat -b /etc/ssh/sshd_config //不显示空白行

##more

分页查内容

##less

分页查内容

##head
查文件前多少行或多少大小的内容

[root@node-lvs-master src]# head -n 10 /etc/ssh/sshd_config  #查头10行的内容
[root@node-lvs-master src]# head -c 10K /etc/ssh/sshd_config #查10k的内容

##tail

查文件末尾的多少行内容

tail -f /var/log/nginx #动态显示

还有-n和-c和head一样

wc

统计文件内容之类的信息

[root@node-lvs-master src]# wc /etc/ssh/sshd_config  #依次显示文件的行数 单词数和字节数
 138  467 3880 /etc/ssh/sshd_config
[root@node-lvs-master src]# wc -c /etc/ssh/sshd_config 
3880 /etc/ssh/sshd_config
[root@node-lvs-master src]# wc -l /etc/ssh/sshd_config 
138 /etc/ssh/sshd_config
[root@node-lvs-master src]# wc -w /etc/ssh/sshd_config 
467 /etc/ssh/sshd_config

grep

[root@CTN-QD-247 wwwlogs]# grep  '115.231.101.171' access.log  ##过滤115.231.101.171的所有内容
[root@CTN-QD-247 wwwlogs]# grep  -v --color  'POST' access.log //过滤不包含POST的内容,并对关键词进行颜色高亮显示

##echo

在标准输出中显示内容

#ehco "aaa"

[root@CTN-QD-247 wwwlogs]# echo -e "\" #需要加双斜杠,否则会被转义
> ^C
[root@CTN-QD-247 wwwlogs]# echo -e "\""

ln

软硬链接

[root@CTN-QD-247 wwwlogs]# ls
access.log  nginx_error.log
[root@CTN-QD-247 wwwlogs]# pwd
/home/wwwlogs
[root@CTN-QD-247 wwwlogs]# ln -s access.log /root/ #创建软链接不加-s是硬链接
[root@CTN-QD-247 wwwlogs]# cd /root/
[root@CTN-QD-247 ~]# ls
access.log  lnmp-install.log  upgrade_nginx20161230153452.log
[root@CTN-QD-247 ~]# ll
total 2700
lrwxrwxrwx 1 root root      10 Jan  6 21:39 access.log -> access.log
-rw-r--r-- 1 root root 2264387 Dec 30 15:10 lnmp-install.log
-rw-r--r-- 1 root root  494739 Dec 30 15:40 upgrade_nginx20161230153452.log
文章作者:阿文
文章链接: https://www.awen.me/post/2172419458.html
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 阿文的博客
本文于 2017-06-14 19:54 发布,已超过半年(3195天),请注意甄别内容是否已过期。

评论

0 条评论
😀😃😄 😁😅😂 🤣😊😇 🙂🙃😉 😌😍🥰 😘😗😙 😚😋😛 😝😜🤪 🤨🧐🤓 😎🥸🤩 🥳😏😒 😞😔😟 😕🙁☹️ 😣😖😫 😩🥺😢 😭😤😠 😡🤬🤯 😳🥵🥶 😱😨😰 😥😓🤗 🤔🤭🤫 🤥😶😐 😑😬🙄 😯😦😧 😮😲🥱 😴🤤😪 😵🤐🥴 🤢🤮🤧 😷🤒🤕 🤑🤠😈 👿👹👺 🤡💩👻 💀☠️👽 👾🤖🎃 😺😸😹 😻😼😽 🙀😿😾 👍👎👏 🙌👐🤲 🤝🤜🤛 ✌️🤞🤟 🤘👌🤏 👈👉👆 👇☝️ 🤚🖐️🖖 👋🤙💪 🦾🖕✍️ 🙏💅🤳 💯💢💥 💫💦💨 🕳️💣💬 👁️‍🗨️🗨️🗯️ 💭💤❤️ 🧡💛💚 💙💜🖤 🤍🤎💔 ❣️💕💞 💓💗💖 💘💝💟 ☮️✝️☪️ 🕉️☸️✡️ 🔯🕎☯️ ☦️🛐 🆔⚛️🉑 ☢️☣️📴 📳🈶🈚 🈸🈺🈷️ ✴️🆚💮 🉐㊙️㊗️ 🈴🈵🈹 🈲🅰️🅱️ 🆎🆑🅾️ 🆘 🛑📛 🚫💯💢 ♨️🚷🚯 🚳🚱🔞 📵🚭 ‼️⁉️🔅 🔆〽️⚠️ 🚸🔱⚜️ 🔰♻️ 🈯💹❇️ ✳️🌐 💠Ⓜ️🌀 💤🏧🚾 🅿️🈳 🈂🛂🛃 🛄🛅🛗 🚀🛸🚁 🚉🚆🚅 ✈️🛫🛬 🛩️💺🛰️
您的评论由 AI 智能审核,一般1分钟内会展示,若不展示请确认你的评论是否符合社区和法律规范
加载中...

选择联系方式

留言反馈

😀😃😄 😁😅😂 🤣😊😇 🙂🙃😉 😌😍🥰 😘😗😙 😚😋😛 😝😜🤪 🤨🧐🤓 😎🥸🤩 🥳😏😒 😞😔😟 😕🙁☹️ 😣😖😫 😩🥺😢 😭😤😠 😡🤬🤯 😳🥵🥶 😱😨😰 😥😓🤗 🤔🤭🤫 🤥😶😐 😑😬🙄 😯😦😧 😮😲🥱 😴🤤😪 😵🤐🥴 🤢🤮🤧 😷🤒🤕 🤑🤠😈 👿👹👺 🤡💩👻 💀☠️👽 👾🤖🎃 😺😸😹 😻😼😽 🙀😿😾 👍👎👏 🙌👐🤲 🤝🤜🤛 ✌️🤞🤟 🤘👌🤏 👈👉👆 👇☝️ 🤚🖐️🖖 👋🤙💪 🦾🖕✍️ 🙏💅🤳 💯💢💥 💫💦💨 🕳️💣💬 👁️‍🗨️🗨️🗯️ 💭💤❤️ 🧡💛💚 💙💜🖤 🤍🤎💔 ❣️💕💞 💓💗💖 💘💝💟 ☮️✝️☪️ 🕉️☸️✡️ 🔯🕎☯️ ☦️🛐 🆔⚛️🉑 ☢️☣️📴 📳🈶🈚 🈸🈺🈷️ ✴️🆚💮 🉐㊙️㊗️ 🈴🈵🈹 🈲🅰️🅱️ 🆎🆑🅾️ 🆘 🛑📛 🚫💯💢 ♨️🚷🚯 🚳🚱🔞 📵🚭 ‼️⁉️🔅 🔆〽️⚠️ 🚸🔱⚜️ 🔰♻️ 🈯💹❇️ ✳️🌐 💠Ⓜ️🌀 💤🏧🚾 🅿️🈳 🈂🛂🛃 🛄🛅🛗 🚀🛸🚁 🚉🚆🚅 ✈️🛫🛬 🛩️💺🛰️