linux常用命令行在mac本上做基础练习与记录

作者: admin 分类: 命令行 发布时间: 2019-03-23 17:04  阅读: 136 views

linux命令做一些系统上的常用操作,那是不用不知道,用了老忘掉,不记全忘掉。做一些整理方便查找

看官方原版解释最清楚

 

1.linux查看命令行的使用帮助  info ?

File: *manpages*,  Node: ln,  Up: (dir)

LN(1)                     BSD General Commands Manual                    LN(1)

NAME
     link, ln -- make links

SYNOPSIS
     ln [-Ffhinsv] source_file [target_file]
     ln [-Ffhinsv] source_file ... target_dir
     link source_file target_file

DESCRIPTION
     The ln utility creates a new directory entry (linked file) which has the
     same modes as the original file.  It is useful for maintaining multiple
     copies of a file in many places at once without using up storage for the
     ``copies''; instead, a link ``points'' to the original copy.  There are
     two types of links; hard links and symbolic links.  How a link ``points''
     to a file is one of the differences between a hard and symbolic link.

     The options are as follows:

     -F    If the target file already exists and is a directory, then remove
           it so that the link may occur.  The -F option should be used with
           either -f or -i options.  If none is specified, -f is implied.  The
           -F option is a no-op unless -s option is specified.

     -h    If the target_file or target_dir is a symbolic link, do not follow
           it.  This is most useful with the -f option, to replace a symlink
           which may point to a directory.

     -f    If the target file already exists, then unlink it so that the link
           may occur.  (The -f option overrides any previous -i options.)

     -i    Cause ln to write a prompt to standard error if the target file
           exists.  If the response from the standard input begins with the
           character `y' or `Y', then unlink the target file so that the link
           may occur.  Otherwise, do not attempt the link.  (The -i option
           overrides any previous -f options.)

     -n    Same as -h, for compatibility with other ln implementations.

     -s    Create a symbolic link.

     -v    Cause ln to be verbose, showing files as they are processed.

2.linux查看磁盘空间 df -lh

deathearth:~ chenhailong$ df -lh
Filesystem   Size   Used  Avail Capacity  iused    ifree %iused  Mounted on
/dev/disk1  112Gi   53Gi   58Gi    48% 14076083 15254365   48%   /

3.linux查看当前目录下的文件及文件夹大小 du  -sh *

deathearth:~ chenhailong$ du -sh *
980K	1.log
4.0K	2.log
980K	3.log
8.0K	Applications
 53M	Desktop
 17M	Documents
7.2G	Downloads
103M	Eclipse.app
 14M	IdeaProjects

4.linux查看内存使用情况 free -m  | mac查看内存使用情况top -l 1 | head -n 10 | grep PhysMem

--linux查看内存使用情况
root@deathearth:~# free -m
             total       used       free     shared    buffers     cached
Mem:           993        921         72          0        118        292
-/+ buffers/cache:        509        484
Swap:            0          0          0

--Mac查看内存使用情况
deathearth:~ chenhailong$ top -l 1 | head -n 10 | grep PhysMem
PhysMem: 7125M used (1086M wired), 1065M unused.

5. linux创建目录mkdir test/删除目录 rm -rf test

mkdir test

rm -rf test  #-rf 指删除当前目录及子目录所有文件、无提示

6. linux显示当前所在的目录 pwd

deathearth:~ chenhailong$ pwd
/Users/chenhailong

7. linux创建快捷方式/连接  ln -s 源文件 目标名称

deathearth:some_tools chenhailong$ ln -s zookeeper-3.4.11 zookeeper

8. linux解压文件夹(有多种方式,根据情况使用)  tar -zxvf xxx.

deathearth:Desktop chenhailong$ tar -zxvf zookeeper-3.4.11.tar 
x zookeeper-3.4.11/
x zookeeper-3.4.11/bin/
x zookeeper-3.4.11/bin/README.txt
x zookeeper-3.4.11/bin/zkCleanup.sh
x zookeeper-3.4.11/bin/zkCli.cmd
x zookeeper-3.4.11/bin/zkCli.sh
x zookeeper-3.4.11/bin/zkEnv.cmd
x zookeeper-3.4.11/bin/zkEnv.sh
x zookeeper-3.4.11/bin/zkServer.cmd
x zookeeper-3.4.11/bin/zkServer.sh
x zookeeper-3.4.11/build.xml
x zookeeper-3.4.11/conf/
x zookeeper-3.4.11/conf/configuration.xsl
x zookeeper-3.4.11/conf/log4j.properties
x zookeeper-3.4.11/conf/zoo_sample.cfg
解压gz文件
gzip -d xx.gz

9. linux压缩文件  tar -zcvf 文件名 目录

deathearth:Desktop chenhailong$ tar -zcvf a.zip image4.png 
a image4.png

10.linux复制/迁移文件  cp  源文件 目标目录(源文件存在)   mv 源文件 目标目录(源文件消失)

11. linux根据名称查找文件信息  find ./ -name xxx

deathearth:some_tools chenhailong$ ls
%DAj%AA}%95jk%A8%F68%D5%DCT? 					FileZilla_3.37.1_macosx-x86_setup_bundled.dmg			bootstrap-3.3.7.zip
BaiduYun_2.4.4.dmg						NavicatPremium1118.dmg						googlechrome_mac_63.0.3239.84.dmg
DingTalk_v4.2.39.dmg						NeteaseMusic_mac_1.5.9.622.dmg					ideaIU-2017.3.4.dmg
EasyConnectPlugin.dmg						SafeControls.dmg						jdk-8u181-macosx-x64.dmg
FileZilla.app							SogouInput_mac_4.6.0.5592.dmg					xmind-8-update6-macosx.dmg
FileZilla_3.17.0.1_macosx-x86.zip				USB_Install OS X Yosemite.dmg					youkumac_7-28_2.dmg
FileZilla_3.33.0_macosx-x86_setup_bundled.dmg			axure 8.0 mac 中文破解版 v8.0.0.3312@901_115284.exe		zookeeper-3.4.11
deathearth:some_tools chenhailong$ find ./ -name FileZilla.app
.//FileZilla.app
deathearth:some_tools chenhailong$ 
(1)find / -amin -10   # 查找在系统中最后10分钟访问的文件(access time)
(2)find / -atime -2   # 查找在系统中最后48小时访问的文件
(3)find / -empty   # 查找在系统中为空的文件或者文件夹
(4)find / -group cat   # 查找在系统中属于 group为cat的文件
(5)find / -mmin -5   # 查找在系统中最后5分钟里修改过的文件(modify time)
(6)find / -mtime -1   #查找在系统中最后24小时里修改过的文件
(7)find / -user fred   #查找在系统中属于fred这个用户的文件
(8)find / -size +10000c  #查找出大于10000000字节的文件(c:字节,w:双字,k:KB,M:MB,G:GB)
(9)find / -size -1000k   #查找出小于1000KB的文件

12. linux查找系统变量中的关键字相关路径 which xxx

deathearth:some_tools chenhailong$ which python
/usr/bin/python
deathearth:some_tools chenhailong$ which java
/usr/bin/java

13.linux连接登录其他机器ssh方式   ssh root@ip

deathearth:some_tools chenhailong$ ssh root@127.0.0.1
The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established.
RSA key fingerprint is b4:66:fc:aa:1d:4e:48:c5:a3:ec:17:d7:ce:bd:3f:2a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '127.0.0.1' (RSA) to the list of known hosts.
Password:

14.linux查看端口占用 netstat -tunlp|grep 5601     |  mac查看端口占用  lsof -i tcp:port

root@deathearth:~# netstat -tunlp|grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1357/nginx.conf 
deathearth:doc chenhailong$ lsof -i tcp:2181
COMMAND  PID        USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    2339 chenhailong   38u  IPv6 0xc3d91fc17b67d011      0t0  TCP *:eforward (LISTEN)

15. linux查看日志文件信息 tail -30 xx.log

deathearth:Desktop chenhailong$ tail -5 wordpress.log 
112.10.16.139 - - [20/Mar/2019:22:03:04 +0800] "GET /wp-includes/js/comment-reply.min.js?ver=4.9.1 HTTP/1.1" 304 0 "https://www.deathearth.com/462.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
112.10.16.139 - - [20/Mar/2019:22:03:05 +0800] "GET /wp-content/plugins/akismet/_inc/form.js?ver=4.0.1 HTTP/1.1" 304 0 "https://www.deathearth.com/462.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
47.92.121.206 - - [20/Mar/2019:22:05:35 +0800] "GET / HTTP/1.1" 200 38283 "-" "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03D))"
112.10.16.139 - - [20/Mar/2019:22:11:01 +0800] "GET /462.html HTTP/1.1" 200 17937 "https://blog.csdn.net/chenhailonghp/article/details/88701643" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
66.249.64.14 - - [20/Mar/2019:22:13:13 +0800] "GET /419.html HTTP/1.1" 200 9156 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
tail -f      等同于--follow=descriptor,根据文件描述符进行追踪,当文件改名或被删除,追踪停止
tail -F     等同于--follow=name  --retry,根据文件名进行追踪,并保持重试,即该文件被删除或改名后,如果再次创建相同的文件名,会继续追踪
tailf        等同于tail -f -n 10(貌似tail -f或-F默认也是打印最后10行,然后追踪文件),与tail -f不同的是,如果文件不增长,它不会去访问磁盘文件,所以tailf特别适合那些便携机上跟踪日志文件,因为它减少了磁盘访问,可以省电

16. linux查看文件信息 并进行翻页查看   less xx.log      | more xx.log

deathearth:Desktop chenhailong$ more wordpress.log 
97.74.228.115 - - [14/Mar/2019:15:46:07 +0800] "POST /xmlrpc.php HTTP/1.1" 200 414 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; fr; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"
97.74.228.115 - - [14/Mar/2019:15:46:07 +0800] "" 400 0 "-" "-"
185.211.245.169 - - [14/Mar/2019:15:46:30 +0800] "POST /xmlrpc.php HTTP/1.1" 200 414 "http://deathearth.com/xmlrpc.php" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/535.24.77 (KHTML, like Gecko) Chrome/54.8.3571.8843 Safari/531.94"
103.130.201.5 - - [14/Mar/2019:15:47:39 +0800] "GET /wp-login.php HTTP/1.1" 200 1212 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"
103.130.201.5 - - [14/Mar/2019:15:47:41 +0800] "POST /wp-login.php HTTP/1.1" 200 1622 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"
103.130.201.5 - - [14/Mar/2019:15:47:42 +0800] "GET /wp-login.php HTTP/1.1" 200 1212 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"
103.130.201.5 - - [14/Mar/2019:15:47:43 +0800] "POST /wp-login.php HTTP/1.1" 200 1601 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"
103.130.201.5 - - [14/Mar/2019:15:47:47 +0800] "GET /wp-login.php HTTP/1.1" 200 1212 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"
103.130.201.5 - - [14/Mar/2019:15:47:49 +0800] "POST /wp-login.php HTTP/1.1" 200 1636 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"
103.130.201.5 - - [14/Mar/2019:15:47:51 +0800] "POST /wp-login.php HTTP/1.1" 200 1600 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"
103.130.201.5 - - [14/Mar/2019:15:47:52 +0800] "GET /wp-login.php HTTP/1.1" 200 1212 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0"

less功能更强大些,mac查询日志并进行翻页查找

b 下一页
d 下半页
y 前一行
u 前半页
_blank 下一行

 

其他的后续待处理

 


   原创文章,转载请标明本文链接: linux常用命令行在mac本上做基础练习与记录

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

更多阅读