linux common commands shorthand

First, the command prompt explanation

1. [root@localhost ~]#
  • root: The current logged-on user
  • localhost: CPU name
  • ~: Current directory
  • #: Superuser ($: ordinary users)
2. -rwxr--r-- 1 root root 1904 May 28 16:00 a.txt
  • -: File type -: file d: directory l: Soft link file
  • rwx: File access permissions r: read w: write, x: execution
  • rw-r--r--: A group of three characters, respectively, 所有者 所属组 其他角色access to the file
  • 1: This file is the number of calls
  • First root: the owner shows u
  • Second root: belonging group g
  • 1904: File size, unit: byte byte
  • May 28 16:00: The file was last modified time
  • a.txt: file name

Second, the basic command

Reference article: https://www.cnblogs.com/yjd_hycf_space/p/7730690.html

command effect Explanation
cd /usr/local Change directory cd: change directory, Enter the /usr/localdirectory
cd .. Go back one level
./ Current directory
pwd Displays the current directory
ls View files in the directory ls: list
ll View detailed information in the catalog file
mkdir test new folder mkdir: make directory, New testFolder
rm -rf a.txt Delete Files To delete a.txta file, rm: remove, -r(recursive): delete recursively -f(force): Force Delete
mv ./test / Moving Files (folder) or rename mv: moveMove the current folder testto the root directory/
cp a.txt b.txt Copy files cp: copyCopy a.txtfilesb.txt
touch a.txt Create a file Create a a.txtfile
cat -n a.txt View the contents of small files -n: Display the line number
less -N a.txt View large file content -N: Display the line number, must be capitalized, 键盘上下键moving up and down a line, qexit Review, /hellocommand to find hellothe string
tail -f admin.log Dynamic View Log -fRead cycle
grep -n "hello" ./a.txt Location where to find the file in a string hello: The string you want to find, ./a.txt: specific file path
sed -n '10,15p' nohup.out Queries 10-15line log
find ./ -name "*.txt" Find Files ./: Look, -name: Find the file name, *.txt: all at .txtthe end of the file
df -h Display of the total capacity of the file system, the amount of the remaining amount df: disk free, -h: To KB, MB, GBdisplay user-friendly format
du -sh a.txt Display file or directory sizes du: disk usage, -s: Summary
top Performance Analysis command, the process of CPU, memory usage ratio
vim a.txt Edit the file Esc-> :-> wq-> Save and exit q!-> exit without saving
sudo Execute command as system administrator switch user do
./configure -> make -> make install Installation trilogy ./configure: The automatic system is required when generating a compiled Makefilefile make: compile make install: mounting
ifconfig View and configure network devices ifconfig: interfaces config
netstat Display network status
netstat -nltp | grep 8080 View the process port is located -n: numericDirectly using an IP address l: listeningdisplay Socket monitoring of servers t: tcpto display the connection status of TCP transport protocol p: programsdisplay the program identification number and name of the program you are using the Socket
ps -ef | grep tomcat View the process ps: 将某个进程显示出来, |: 管道命令, 指ps命令与grep同时执行, -e: 显示所有程序, -f: 显示UID,PPIP,C与STIME栏位
kill -9 [pid] 结束进程 -9: 强制结束
lsof 列出当前系统打开的文件 lsof: list open files
lsof -i:8080 列出使用8080端口的进程ID
echo "" > nohup.out 清空文件 echo: 字符串输出
sh 执行脚本文件
bash 执行脚本文件
shutdown -h now 立即关机
reboot 重启
groupadd group_name 创建用户组
groupdel group_name 删除用户组
groupmod -n new_group_name old_group_name 重命名一个用户组 -n: 新组名
useradd user1 创建一个新用户
userdel -r user1 删除一个用户 -r: 排除主目录
passwd 修改口令

三、chmod命令

参考文章: http://c.biancheng.net/view/755.html

1. 作用:

修改文件访问权限

2. 使用数字修改文件权限
  • 字符对应数字
r --> 4
w --> 2
x --> 1
  • 所有者u 所属组g 其他o

  • 使用方式
    chmod [-R] 权限值 文件名, -R(注意是大写)选项表示连同子目录中的所有文件,也都修改设定的权限。

  • 示例:
    chmod 777 a.txt

  • 再举个例子,通常我们以 Vim 编辑 Shell 文件批处理文件后,文件权限通常是 rw-rw-r--(644),那么,如果要将该文件变成可执行文件,并且不让其他人修改此文件,则只需将此文件的权限该为 rwxr-xr-x(755)即可。

3. 使用字母修改文件权限
  • chmod u=rwx,go=rx a.txt

  • + - =

4. 常见数字权限
  • -rw------- (600) 只有所有者才有读和写的权限。
  • -rw-r--r-- (644) 只有所有者才有读和写的权限,群组和其他人只有读的权限。
  • -rw-rw-rw- (666)每个人都有读写的权限
  • -rwx------ (700) 只有所有者才有读,写和执行的权限。
  • -rwx--x--x (711) 只有所有者才有读,写和执行的权限,群组和其他人只有执行的权限。
  • -rwxr-xr-x (755) 只有所有者才有读,写,执行的权限,群组和其他人只有读和执行的权限。
  • -rwxrwxrwx (777) 每个人都有读,写和执行的权限

四、chown命令

1. 作用:

改变文件所有者和所属组

2. 示例:
  • 将文件a.txt的所有者设为wangzai, 所属组设为wangzaigroup:
    chown wangzai:wangzaigroup a.txt

  • 将目前目录下的所有文件与子目录的拥有者都设为wangzai, 所属组设为wangzaigroup: chown -R wangzai:wangzaigroup *

五、解压缩命令

1. 选项
  • -c 压缩
  • -x 解压缩
  • -z:有gzip属性的
  • -v:显示所有过程
  • -f: 使用档案名字,切记,这个参数是最后一个参数,后面只能接档案名。
2. 解压
  • 解压.tar文件: tar xvf a.tar
  • 解压.gz文件: gunzip
  • 解压.tar.gz文件: tar zxvf a.tar.gz
  • 解压.rar文件: unrar
  • 解压.zip文件: unzip
3. 压缩
  • 压缩成.zip文件: zip a.zip a.txt
  • 压缩成.tar文件: tar cvf a.tar a.txt
  • 压缩成.tar.gz文件: tar zcvf a.tar.gz a.txt

六、sudo命令

1. 作用:

通过sudo,我们能把某些超级权限有针对性的下放,并且不需要普通用户知道root密码(sudo用的不是root密码,而是当前用户密码),所以sudo相对于权限无限制性的su来说,还是比较安全的,所以sudo也能被称为受限制的su,另外sudo是需要授权许可的,所以也被称为授权许可的su。

2. 执行流程:

sudo执行命令的流程是当前用户切换到root(或其他指定切换到的用户),然后以root(或其他指定的切换到的用户)身份执行命令,执行完成后,直接退回到当前用户,而这些的前提是要通过sudo的配置文件/etc/sudoers来进行授权。

3. 配置文件:

sudo的配置文件是/etc/sudoers,我们可以用他的专用编辑工具visodu来进行配置,配置好后,可以切换到您授权的用户下,通过sudo -l来查看哪些命令是可以执行或禁止的。

七、wget rpm yum命令

1. wget:

类似于迅雷,是一种下载工具,World Wide Web”与“get”的结合。

2. yum:

Yellow dog Updater, Modified,软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包。

3. rpm:

软件管理;r=redhat p=package m=management;用于安装 卸载 .rpm软件

4. 串联下:

使用wget下载一个 rpm包, 然后用 rpm -ivh xxx.rpm 安装这个软件,嫌麻烦的话,就可以直接用 yum install sqoop 来自动下载和安装依赖的rpm软件。

5. 常用命令:
  • 安装:rpm -ivh *.rpm
  • 卸载:rpm -e packgename
  • 查看是否已经安装:rpm -q nginx

  • 安装:yum install xxx
  • 移除:yum remove xxx
  • yum –y install xxx

八、dump命令

1. 安装dump:

yum -y install dump

2. 作用:

备份文件系统

3. 格式:

dump [选项] 备份之后的文件名 原文件或目录

4. 选项:
  • -level0~9: 共10个备份级别, 0: 完全备份, 1~9: 增量备份
  • -f: 备份之后的文件名
  • -u: 备份成功之后, 把备份时间记录在/etc/dumpdates文件中
  • -v: 显示备份过程中更多的输出信息
  • -j: 调用bzlib库压缩备份文件, 其实就是把备份文件压缩为.bz2格式, 默认压缩等级是2
  • -W: 显示允许被dump的分区的备份等级及备份时间
5. 示例

dump -0 -f /usr/local/test/test1.bak /usr/local/test/test1

九、linux服务器之间传输文件

1. 说明:

scp: secure copy

2. 用法:
  • 本地文件 -> 远程服务器: scp a.txt [email protected]:/home/
    然后直接输入远程服务器密码

  • 远程服务器文件 -> 本地: scp [email protected]:/home/a.txt /home
    即调换顺序即可

十、linux windows之间传输文件

1. linux安装lrzsz命令:

yum -y install lrzsz

2. 用法:
  • rz回车: receive, 接收文件, 然后从windows选择一个文件上传到linux, 即: windows -> linux

  • sz a.txt回车: send, 发送a.txt文件到windows, 即: linux -> windows

3. 说明:

当使用Git Bash Here的shell终端时, rz命令会出现waiting to receive.**B0100000023be50错误, 因为Git shell不支持rzsz, 解决办法: 换用xshell或其他终端即可

Guess you like

Origin www.cnblogs.com/wangzaiplus/p/10945462.html