Linux(三)——Unix&Linux 的基础命令
Linux(三)——Unix&Linux 的基础命令快捷键Ctl-A 光标移动到行首 Ctl-C 终止命令 Ctl-D 注销登录 Ctl-E 光标移动到行尾 Ctl-U 删除光标到行首的所有字符,在某些设置下,删除全行 Ctl-W 删除当前光标到前边的最近一个空格之间的字符 Ctl-H 删除光标前边的字符 Ctl-R 匹配最相近的一个文件,然后输出 Ctl-Z 将目前任务转为后台运行 Path 相关(cd、ls)pwd #print working dir // 目录查看 ls == ls -h #list files under current directory ls -l #list with block and property ls -A #list including hidden files ls -Alh #list in a friendly view ls /home #list a upper dir ls *.json #list by wildcards ls -lrt #按时间排序,以列表的方式显示目录项 // 目录跳转 cd - #switch to last path cd .. #switch to upper path cd / #switch to root path cd ~/hexo #switch by absolute path cd ./user/xx #switch by relative path 帮助命令(help、man、info、type)help #仅适用于内置命令,效果不佳 man ls #查看命令手册 info ls #GNU的更详细的命令手册 type xxx $ xxx is a shell builtin #说明是内建命令,这些命令都是在 bash 源码中的 builtins 的 .def 中 $ xxx is /usr/bin/xxx #说明是外部命令 $ xxx is an alias for xx #说明该指令为命令别名所设定的名称 文件相关文件查看(cat、nl、head、tail、more、less、file)//文件内容 cat file #preview file cat -n fileA #preview file with linenum nl fileA #preview trim file with linenum more/less fileA #分页查看,more会直接结束,less 需要q退出 tail file #只看后几行 tail -n 2 file #只看2行 cut -c -5 file #每行前五个字节(包含第五个) cut -c 5- file #每行前五个之后的字节(包含第五个) cut -c 5 file #每行第五个字节 cut -c 2-5 file #每行第2到5之间的字节(包含第五个) //文件类型 file file #查看文件类型 文件创建、复制、删除、重命名(touch、mkdir、rm、cp、mv)// 创建 touch filename #create empty file mkdir xxx/xx -p #create path(-p: create xxx) //复制 cp -r A B #duplicate A's files to B(B unexist & only one floor) cp -r A B #copy A to B(if B exist) //删除 rm filename #delete filename rm -r dir #delete dir //重命名 mv xxx/oldfile xxx/newfile #rename a file mv oldfile xxx/newfile #rename & move a file mv dir xxx/dir #move dir to xxx/dir which is created 文件压缩和解压// 压缩 zip zip -rqo file.zip ./filename #普通压缩 zip -{1…9} -rqo zip.zip ./filename #不同级别压缩、加密压缩 zip -dv cp.zip file #从cp.zip中删除文件 # -d 从压缩文件内删除指定的文件 # -o 将压缩文件的更改时间设成和文件的最新更改时间一致 # -q 不显示指令执行过程 # -r 递归处理,将指定目录下的所有文件和子目录一并处理 # -v 显示指令执行过程或显示版本信息 //查看 unzip -l file.zip #显示压缩文件内所包含的文件 //解压 unzip unzip file.zip #直接解压 unzip -q file.zip -d ./dir #解压到 dir 中 # -d <目录> 指定文件解压缩后所要存储的目录 # -q 执行时不显示任何信息 # -v 执行时显示详细的信息 //tar //压缩 tar -cf file.tar xxx.xx #把xxx.xx 压缩为 file.tar tar -czvf file.tar.gz xxx.xx #把xxx.xx 打包为 tar.gz 文件 # -c 建立新的备份文件 # -f 指定备份文件 # -v(--verbose) 显示指令执行过程 # -z(--gzip) 通过gzip指令处理备份文件 tar -cphf etc.tar /dir #一般用于系统备份 # -p 保留文件属性和跟随链接(符号链接或软链接) # -h(--dereference) 不建立符号连接,直接复制该连接所指向的原始文件 # 使用 tar 备份文件当你在其他主机还原时希望保留文件的属性和备份链接指向的源文件而不是链接本身 //查看压缩内容 tar -tf file.tar #查看 file.tar tar -tzvf test.tar.gz #查看压缩文件内容 # -C<目录>(--directory) 指定文件解压缩后所要存储的目录 # -f 指定备份文件 //解压 tar -xf file.tar -C ./dir #解压 file.tar tar -xzf file.tar.gz #解压 tar.gz 打包文件 # -x (--extract) 从备份文件中还原文件 # -z(--gzip) 通过gzip指令处理备份文件 文件软链接(ln)软链接:
ln -s log.log link #为log.log 建立名为 link 的软链接 # -s 软链接(符号链接) 文件查找(whereis、which、find)locate *.jpg #locate 会维护一个数据库,查找时不会真的去找 which who #查找安装的命令、程序可以用 //find 命令 find [path] [option] [action] find . -name *.jpg #查找 jpg 文件 find . -type f #查找一般文件 #d: 目录 #c: 字型装置文件 #b: 区块装置文件 #p: 具名贮列 #f: 一般文件 #l: 符号连结 #s: socket find . -ctime n #在过去n天内被变更过的文件 find . -atime n #在过去n天内被访问过的文件 find . -mtime n #在过去n天内容最后被修改的时间的文件 # -mtime n:n 为数字,表示为在 n 天之前的一天之内修改过的文件 # -mtime +n:列出在 n 天之前(不包含 n 天本身)被修改过的文件 # -mtime -n:列出在 n 天之内(包含 n 天本身)被修改过的文件 find . -newer /home/shiyanlou/Code # -newer file:file为一个已存在的文件,列出比file还要新的文件 find . -type f -perm 644 -exec ls -l {} ; #查找前目录中文件属主具有读、写权限,并且文件所属组的用户和其他用户具有读权限的文件 File Permission(chown、chmod)
chmod 600 file #为 file 设置600权限 //g、o 还有 u 分别表示 group、others和user //+ 和 - 分别表示增加和去掉相应的权限 chmod go-rw iphone6 #表示去掉group、others 的读写权限 chown username file #grant file ownership to user chown :group file #grant file ownership to group chown xx:xx file #grant file ownership to xx & xx chown -R user:group dir #grant dir(-r) ownership to xx & xx 文件合并(join、paste)join file1 file2 #逐行合并,相同的部分仅保留一份 #「1 hello」和「1 world」合并为「1 hello world」 paste f1 f2 [文件...] #逐行合并 # -d 自定义合并后的分割符( 'n' 以回车为每行的分割符) paste -s file #将一个文件中的多行数据合并为一行显示,但不修改原文件 软件安装dpkg 和 apt-get主要应用于类 Debian 系统 apt 是Advance Packaging Tool(高级包装工具)的缩写,APT最早被设计成dpkg的前端,用来处理deb格式的软件包,现在已经成为 Debian 及其派生发行版的软件包管理器。 apt 主要解决了软件的安装源、依赖关系处理、软件更新和发行版升级的问题。 apt-get 的使用一般情况下,使用 apt 命令即可完成一般的安装操作。
// apt-get apt-get update #更新软件源,软件源记录了软件和软件依赖,通过一并安装依赖保证软件能够正常运行 apt-get install name #安装软件 apt-get remove name #移除<package>以及任何依此存包的其它包 apt-get purge name #与remove相同,同时移除配置等文件 apt-get autoremove name #移除不再被依赖的软件包 apt-get autoclean #移除已安装的软件包 # -y 自动同意安装软件包的选项 # -q 静默安装方式 # -f 修复损坏的依赖关系 # -d 只下载不安装 // apt-cache apt-cache search softname #搜索是否安装了该软件 // apt-file dpkg 的使用dpkg -l #列出系统中安装的所有程序 sudo dpkg -i name.deb #安装指定deb包 sudo dpkg -r name #移除指定的软件包 dpkg -s name #查看已安装软件的详细信息 RPM 和 yum具体使用方法还请自行搜索。 RPM包管理器(简称RPM,全称为The RPM Package Manager),是由Red Hat推出的软件包管理系统,现在在各种发行版中普遍使用,被用于安装、卸载和供给和
rpm软件包形式管理软件虽然方便,但是rpm只是追踪软件包之间的依赖关系并没有进行解决。 yum(yellowdog Updater,Modified)是一个rpm的前端程序,主要目的是用来解决rpm的依赖关系问题,其特点如下:
HomebrewmacOS 上使用的包管理器,功能强大,使用方便。 主要是凑一下 Unix 系统包管理的数。 详细介绍参看少数派文章 像 Mac 高手一样管理应用,从 Homebrew 开始。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |