mac 运行 linux 命令大全,开发必会的 Linux & Mac 命令

Linux 和 Mac 也是就OS X 的命令非常相似,在开发过程中会经常用到,命令忘记用法就使用

# 命令[command]的帮助信息,显示在当前命令行内

[command] --help

# 显示命令[command]完整帮助文档

man [command]

使用超级管理员身份

# 使用超级管理员身份执行命令 [command]

sudo [command]

文件类

查找文件

快速查找

# 根据名称查找/目录下的[file full name]文件

find / -name [file full name]

# 递归查找 [.] 也就是所有 后缀为 [suffix] 的文件

find . -name "*.[suffix]"

# 查找当前目录中的所有 [jar]文件

ls -l | grep '[jar]'

递归查找

# 递归查找所有文件内容中,前提这是一个可以被读取并识别的,包含[search key]的 xml 文件

find . -name "*.xml" |xargs grep "[search key]"

内容查找

# 查找所有的包含 [context] 后缀为 [suffix] 的文件

grep -H '[context]' *.[suffix]

# 显示所有以 [head] 开头的文件中包含 [test]的行

grep '[test]' [head]*

# 显示在aa,bb,cc文件中匹配[context]的行

grep '[context]' aa bb cc

# 显示aa中所有包含每个字符串至少有[number]个连续小写字符的字符串的行

grep '[a-z]\{[number]\}' aa

查看文件头[number]行

# [filename] 文件名

head -n [number] [filename]

查看文件尾[number]行

# [filename] 文件名

tail -n [number] [filename]

查看日志类型文件

# 日志文件 [logfile.log]

tail -f [logfile.log]

# 这个命令会自动显示新增内容,屏幕只显示10行内容的(可设置)[linenumber]

tail -f -n [linenumber] [logfile.log]

文件操作

显示当前目录

pwd

以树状图列出目录的内容

# 以树状图显示目录 [folder] 内容,如果没有请安装 tree 工具

tree [folder]

# OS X 请安装 tree或者使用下面的命令

find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'

# 递归变量文件夹内的结构,忽略 [build] 的子文件夹,并输出到文件 FileTree.md

tree -d -I [build] > FileTree.md

文件权限

# [file]的权限进行 options 操作

chmod [options] [file]

# 第一位指定属主的权限,第二位指定组权限,第三位指定其他用户的权限

# 4,执行时设置用户ID

# 2,执行时设置用户组ID

# 1,设置粘着位

# 如6(4+2)代表有读写权,7(4+2+1)有读、写和执行的权限

# -rwxrwxrwx,r表示读、w表示写、x表示可执行 options 为777

Option

option

Full option

Desc

-c

--changes

只输出被改变文件的信息

-f

--silent --quiet

当chmod不能改变文件模式时,不通知文件的用户

-R

--recursive

可递归遍历子目录,把修改应到目录下所有文件和子目录

-v

--verbose

无论修改是否成功,输出每个文件的信息

--reference=filename

参照filename的权限来设置权限

Option Code

code

Desc

+

增加权限

-

删除权限

=

重新分配权限

Who

who

Desc

u

用户

g

o

其它

a

所有用户(默认)

permission

Permison

Desc

r

w

x

执行

s

设置用户(或组)的ID号

t

设置粘着位(sticky bit),防止文件或目录被非属主删除

u

用户的当前权限

g

组的当前权限

o

其他用户的当前权限

实例

Dome

Desc

chmod 751 file

给file的属主分配读、写、执行(7)的权限,给file的所在组分配读、执行(5)的权限,给其他用户分配执行(1)的权限

chmod u=rwx,g=rx,o=x file

上例的另一种形式

chmod u+x file

给file的属主增加执行权限

chmod 4755

设置用ID,给属主分配读、写和执行权限,给组和其他用户分配读、执行的权限

chmod =r file

为所有用户分配读权限

chmod 444 file

同上

chmod a-wx,a+r file

同上

chmod -R u+r directory

递归地给directory目录下所有文件和子目录的属主分配读的权限

显示当前文件夹详情

ls -al

复制文件

# 复制文件 [source] 到 [dest]

cp [source] [dest]

# 递归复制整个文件夹 [sourceFolder] 到 [targetFolder]

cp -r [sourceFolder] [targetFolder]

# 远程拷贝 [sourecFile] 到 [romoteUserName@remoteIp:remoteAddr]

scp [sourecFile] [romoteUserName@remoteIp:remoteAddr] 远程拷贝

移动文件

# 移动文件 [movefile] 到 [targetFolder]

mv [movefile] [targetFolder]

重命名

# 将 [oldNameFile] 重命名为 [newNameFile]

mv [oldNameFile] [newNameFile]

压缩文件

# 保存为 [tarFileName.tar.gz] , 从[fromFolder]压缩到[targetFolder]

tar -czf [tarFileName.tar.gz] [fromFolder] [targetFolder]

# 列出压缩文件 [tarFileName] 的内容文件列表

tar -tzf [tarFileName.tar.gz]

解压文件

# 解压 [tarFileName.tar.gz] 的文件

tar -xvzf [tarFileName.tar.gz]

删除文件大小为零的文件

find ./ -size 0 | xargs rm -f &

目录操作

创建目录

# 创建 [newfolder] 目录

mkdir [newfolder]

删除目录

# 删除空目录 [emptyFolder]

rmdir [emptyFolder]

# 安全删除目录 [folder] 中所有内容

\rm -r [folder]

# 递归删除目录 [folder] 中所有内容 这样容易误删除

rm -rf [folder]

网络类

查看端口占用情况

# 查看端口号 [port] 的使用情况

netstat -tln | grep [port]

查看端口属于哪个程序

# 查看端口号 [port] 属于哪个程序

lsof -i :[port]

网络检测

# 检查网卡

ping 127.0.0.1

# 检查网络 [host or ip address]

ping [host or ip address]

# 路由跟踪 到 [host] 的路由

traceroute [host]

进程类

查看进程

# 查看所有有关[progress name]的进程

ps –ef | grep [progress name]

# 查看所有进程

ps aux

# 查看 [progress] 进程

ps aux |grep [progress]

查看Java运行进程

# 查看java进程

jps

# 查看java进程号

jps -q

# java 应用程序main class的完整package名或者应用程序的jar文件完整路径名

jps -l

# 查看java进程号 输出传递给main 方法的参数

jps -m

# 查看java进程传递给JVM的参数

jps -v

终止进程

# 终止线程号为[pid]的线程

kill -9 [pid]

用户类

显示用户

# 显示当前用户名

whoami

切换用户

# 切换到 username

su -username

配置 信息类

打印信息

# 打印java home环境变量的值

echo $JAVA_HOME

# 读取环境变量更你使用的bash有关,如果是 bash 是读取 ~/.bash_profile 中

远程管理

远程登录

# 使用ssh登录 [userName] [ip]

ssh [userName]@[ip]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
unlocker208 是使用 VMware 安装 MacOS的必备补丁,亲测可用,详情参阅压缩包内有readme。 VMware 安装 MacOS的流程: =============================================== 1. 安装VMware Station Pro 12.0 2. 将Unlocker解压,右击win-install.cmd,选择“以管理员身份运行” 3. 为MacOS新建虚拟机,注意一定要下载懒人版安装包,格式为ISO或CDR 4. 新建完虚拟机之后,“开启此虚拟机”,VMWare会报错。这是因为虚拟机的隐藏参数设置错误,你要手动修改: 打开虚拟机所在文件夹,找到.vmx文件,右键使用其他程序打开,并选择记事本,在文件最后添加: smc.version = "0" 并保存。 ================================================= Mac OS X Unlocker for VMware V2.0 ================================= 1. Introduction --------------- Unlocker 2 is designed for Workstation 11, Player 7, ESXi 6 and Fusion 7. If you are using an earlier product please continue using Unlocker 1 Version 2 has been tested against: * Workstation 11/12 on Windows and Linux * Player 7 & Workstation Player 12 on Windows and Linux * Fusion 7/8 on Mavericks and Yosemite * ESXi 6.0 The patch code carries out the following modifications dependent on the product being patched: * Fix vmware-vmx and derivatives to allow Mac OS X to boot * Fix vmwarebase .dll or .so to allow Apple to be selected during VM creation * Fix libvmkctl.so on ESXi 6 to allow use with vCenter * Download a copy of the latest VMware Tools for OS X Note that not all products recognise the darwin.iso via install tools menu item. You will have to manually mount the darwin.iso for example on Workstation 11 and Player 7. The vmwarebase code does not need to be patched on OS X or ESXi so you will see a message on those systems telling you that it will not be patched. In all cases make sure VMware is not running, and any background guests have been shutdown. The code is now Python as it makes the Unlocker easier to run and maintain on ESXi. There are some challenges to write the code as ESXi has a subset of Python 2.7 which constrains some modules that can be used. 2. Prerequisites ---------------- The code requires Python 2.7 to work. Most Linux distros, ESXi and OS X ship with a compatible Python interpreter and should work without requiring any additional software. Windows has a packaged version of the Python script using PyInstaller, and so does not require Python to be installed. 3. Limitations -------------- If you are using VMware Player or Workstation on Windows you may get a core dump. Latest Linux and ESXi products are OK and do not show this problem. +-----------------------------------------------------------------------------+ | IMPORTANT: | | ========== | | | | If you create a new VM using version 11 or 12 hardware VMware may stop and | | create a core dump. There are two options to work around this issue: | | | | 1. Change the VM to be HW 10 - this does not affect performance. | | 2. Edit the VMX file and add: | | smc.version = "0" | | | +-----------------------------------------------------------------------------+ 4. Windows ---------- On Windows you will need to either run cmd.exe as Administrator or using Explorer right click on the command file and select "Run as administrator". win-install.cmd - patches VMware win-uninstall.cmd - restores VMware win-update-tools.cmd - retrieves latest OS X guest tools 5. Linux --------- On Linux you will need to be either root or use sudo to run the scripts. You may need to ensure the Linux scripts have execute permissions by running chmod +x against the 2 files. lnx-install.sh - patches VMware lnx-uninstall.sh - restores VMware lnx-update-tools.cmd - retrieves latest OS X guest tools 6. Mac OS X ----------- On Mac OS X you will need to be either root or use sudo to run the scripts. This is really only needed if you want to use client versions of Mac OS X. You may need to ensure the OS X scripts have execute permissions by running chmod +x against the 2 files. osx-install.sh - patches VMware osx-uninstall.sh - restores VMware 7. ESXi ------- You will need to transfer the zip file to the ESXi host either using vSphere client or SCP. Once uploaded you will need to either use the ESXi support console or use SSH to run the commands. Use the unzip command to extract the files. <<>> Please note that you will need to reboot the host for the patches to become active. The patcher is embbedded in a shell script local.sh which is run at boot from /etc/rc.local.d. You may need to ensure the ESXi scripts have execute permissions by running chmod +x against the 2 files. esxi-install.sh - patches VMware esxi-uninstall.sh - restores VMware Note: 1. Any changes you have made to local.sh will be lost. If you have made changes to that file, you will need to merge them into the supplied local.sh file. 2. The unlocker runs at boot time to patch the relevant files and it now survives an upgrade or patch to ESXi as local.sh is part of the persisted local state. 8. Thanks --------- Thanks to Zenith432 for originally building the C++ unlocker and Mac Son of Knife (MSoK) for all the testing and support. Thanks also to Sam B for finding the solution for ESXi 6 and helping me with debugging expertise. Sam also wrote the code for patching ESXi ELF files.
Eclipse 是目前功能比较强大的JAVA IDE(JAVA编程软件),是一个集成工具的开放平台,而这些工具主要是一些开源工具软件。在一个开源模式下运作,并遵照共同的公共条款,Eclipse 平台为工具软件开发者提供工具开发的灵活性和控制自己软件的技术。 Eclipse已经围绕着免版权费技术和通用平台,为工具集成开发形成了一个独立的开放的“生态系统”。以Eclipse为基础的工具允许开发者自由选择语言,平台和厂商环境。 Eclipse提供了一个以插件为基础的框架,让你可以轻松创建,集成和使用工具软件,节省了大量时间和金钱。通过合作和一体化开发核心技术,软件工具开发者可以利用平台的重复使用功能,专注于核心技术,创建新的开发技术。 JBuilder, Eclipse, Neebeans 是3种应用比较普遍的Java开发的平台,如果你以后想走java这条路,最好学会EcLIPSE。jcreator功能太简单,不好用,JBUILDER太庞大,不好学。查看Eclipse快捷键指南。 Eclipse的平台是基于Java语言编写,并包含大量的插件创建工具以及实例。它已经在大范围的开发工作站上应用,包括Linux,HP-UX,AIX,Solaris,QNX,Mac OS X,以及Windows平台的系统。 "分享一个在Java中反射获取私有构造函数、属性、方法" 我一直以为类的私有构造函数、属性、方法除了类自身其他类是无法访问的,前几天正好学习Spring框架,在学习Spring框架基础 Bean包时,写了一个简单的例子,类似如下:   package study.spring.bean;    public class SimpleBean   {   private String beanName;   private SimpleBean() {   System.out.println( " SimpleBean " );   }   /** */ /**   * @return Returns the beanName.   */   public String getBeanName()   {   return beanName;   }   /** */ /**   * @param beanName The beanName to set.   */   public void setBeanName(String beanName)   {   this .beanName = beanName;   }   }   发现居然也能调用成功,当时很惊讶,反射机制平时在以前的项目中也常使用,但不能构造只有私有构造函数的类。   自己做了一个简单例子:   package study.spring.bean;   import java.lang.reflect.Constructor;   import java.lang.reflect.InvocationTargetException;   public class SimpleTest   {   /** *//**   * @param args   */   public static void main(String[] args)   {   // TODO Auto-generated method stub   try   {    Constructor[] cts=Class.forName("study.spring.bean.SimpleBean").getDeclaredConstructors();   for(int i=0;i<cts.length;i++){    cts[i].newInstance(null);   }   }   catch (SecurityException e)   {   // TODO Auto-generated catch block   e.printStackTrace();   }   catch (ClassNotFoundException e)   {   // TODO Auto-generated catch block   e.printStackTrace();   }   catch (IllegalArgumentException e)   {   // TODO Auto-generated catch block   e.printStackTrace();   }   catch (InstantiationException e)   {   // TODO Auto-generated catch block   

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值