Linux基础命令和原理总结

作为一个程序员或者测试开发人员,我们在进行项目部署和运维时,经常会用到一些linux命令,可是这些命令老是忘记,每次用到的时候都要去谷歌百度,很是麻烦!这不,为了自己使用方便,对常见的linux命令, SHELL, VIM, Linux性能调优和linux kernel的总结,以便在用到时能够快速地找到相关命令,同时有需要的朋友也可以参考搜藏该篇文章!文章对讲到的每个命令都有详细的参数解释,并且给出一些常用例子,因此也非常适合用来学习!


image.png
image.png
image.png
  1. 工作中常用的命令总结;

shell(命令解释器)自带的命令称为内部命令,其它的是外部命令
内部命令使用help帮助:help cd
外部命令使用help帮助:ls --help
type命令:用于区分是内部命令还是外部命令:

type ls

ls is aliased to `ls --color=auto' #外部命令

type cd

cd is a shell builtin #内部命令
pwd命令:显示当前目录
ls命令:查看目录和文件名称
ls -l 查看目录各个字段含义

第一字段:首字母代表的是文件类型 ,其中"-"为普通文件、"d"为目录文件、"c"为字符设备文件、"b"为块设备文件、"p"为管道文件、"l"为链接文件、"s"为socket文件。“rwx”分别代表拥有读、写和执行权限,"-代表无对应权限。三个"rwx"依次代表文件所有者、文件所有者所在用户组、其它用户对文件拥有的权限。
第二字段:文件硬连接数量
第三字段:文件拥有者
第四字段:文件拥有者所在组
第五字段:文件大小(以字节为单位)
第六字段:文件最后更改时间
第七字段:文件名(若为链接文件则追加显示其链接的原文件的路径)

ls命令其它参数含义:
-a显示隐藏文件(.开头的文件)
-r逆序排序
-t按照时间顺序显示
-R递归显示
ls -lartR : 按照时间顺序倒序显示所有文件及其文件夹的文件

cd命令:更改当前的工作目录
cd /path/... 绝对路径
cd ./path/... 相对路径(./可以省略)
cd ../path/... 相对路径

mkdir -p 递归目录:递归创建目录

rmdir命令:删除目录
rmdir a/b/c/d/e/ #删除空目录
rm -r a/b/c/d/ #递归删除目录,但是系统会做多次询问
rm -rf a/b/c/d/ #删除目录,不做任何询问

cp命令:复制文件和目录
-r 复制目录
-p 保留用户、权限、时间等文件属性

mv命令:移动文件和重命名
mv *.log 目标目录

通配符:
*匹配任何字符串
?匹配一个字符串
[xyz]任何一个字符串
[a-z]匹配一个范围

cat命令:文本内容显示到终端

head命令:查看文件开头
head -3 文件名称 #显示文件开头3行

tail命令:查看文件末尾
tail -3 文件名称 #显示文件末尾3行
tail常用参数-f,文件内容更新后,同步显示更新的文件信息
tail -f 文件名称

wc命令:统计文件内容信息
wc 文件名称

useradd命令:新建用户
useradd 用户名

userdel命令:删除用户
userdel 用户名 用户所在的家目录不会被删除
userdel -r 用户名 用户相关的所有配置都会被删除

passwd命令:修改用户密码
passwd 用户名

usermod命令:修改用户属性

/etc/passwd文件:查看用户文件
tail /etc/passwd

/etc/shadow文件:查看用户密码
tail /etc/shadow

groupadd命令:添加用户组
groupadd 用户组

groupdel命令:删除用户组
groupdel 用户组

用户切换
su 用户名 切换用户,但是用户所在环境不变,即pwd路径不会变化
su - 用户名 切换用户,同时会切换到用户家目录,即/home/用户名

sudo命令:普通用户需要执行root用户权限的解决方案。

  1. linux基础的原理和一些常用的命令;


    image.png
image.png

以下是一些常用命令汇总;The following table provides a reminder of most of the commands that we have covered so far. If you include the three, as-yet-unmentioned, commands in the last column, then you will probably be able to achieve >95% of everything that you will ever want to do in Unix (remember, you can use the man command to find out more about top, ps, and kill). The power comes from how you can use combinations of these commands.

image.png
  1. 日常linux 命令的cheat sheet总结;


    image.png
image.png
image.png
image.png
image.png

Linux常用命令作为it人员的必备技能,我们需要掌握常用的基础命令,本文总结了工作中常用的命令列出来,希望可以帮助大家经常查阅,解决工作中的问题. 有需要补充可以联系我,完善文章.

Basic Linux commands

Command Description
ls Lists all files and directories in the present working directory
ls -R Lists files in sub-directories as well
ls -a Lists hidden files as well
ls -al Lists files and directories with detailed information like permissions,size, owner, etc.
cd or cd ~ Navigate to HOME directory
cd .. Move one level up
cd To change to a particular directory
cd / Move to the root directory
cat > filename Creates a new file
cat filename Displays the file content
cat file1 file2 > file3 Joins two files (file1, file2) and stores the output in a new file (file3)
mv file "new file path" Moves the files to the new location
mv filename new_file_name Renames the file to a new filename
sudo Allows regular users to run programs with the security privileges of the superuser or root
rm filename Deletes a file
man Gives help information on a command
history Gives a list of all past commands typed in the current terminal session
clear Clears the terminal
mkdir directoryname Creates a new directory in the present working directory or a at the specified path
rmdir Deletes a directory
mv Renames a directory
pr -x Divides the file into x columns
pr -h Assigns a header to the file
pr -n Denotes the file with Line Numbers
lp -nc , lpr c Prints “c” copies of the File
lp-d lp-P Specifies name of the printer
apt-get Command used to install and update packages
`mail -s 'subject'

-c 'cc-address'-b 'bcc-address'
'to-address'| Command to send email | |mail -s "Subject"
to-address < Filename` | Command to send email with attachment |

File Permission commands

Command Description
ls -l to show file type and access permission
r read permission
w write permission
x execute permission
-= no permission
Chown user For changing the ownership of a file/directory
Chown user:group filename change the user as well as group for a file or directory

Environment Variables command

Command Description
echo $VARIABLE To display value of a variable
env Displays all environment variables
VARIABLE_NAME= variable_value Create a new variable
Unset Remove a variable
export Variable=value To set value of an environment variable

User management commands of linux

Command Description
sudo adduser username To add a new user
sudo passwd -l 'username' To change the password of a user
sudo userdel -r 'username' To remove a newly created user
sudo usermod -a -G GROUPNAME USERNAME To add a user to a group
sudo deluser USER GROUPNAME To remove a user from a group
finger Shows information of all the users logged in
finger username Gives information of a particular userNetworking command
Command Description
SSH username@ip-address or hostname login into a remote Linux machine using SSH
Ping hostname="" or ="" To ping and Analyzing network and host connections
dir Display files in the current directory of a remote computer
cd "dirname" change directory to “dirname” on a remote computer
put file upload ‘file’ from local to remote computer
get file Download ‘file’ from remote to local computer
quit Logout

Process command

Command Description
bg To send a process to the background
fg To run a stopped process in the foreground
top Details on all Active Processes
ps Give the status of processes running for a user
ps PID Gives the status of a particular process
pidof Gives the Process ID (PID) of a process
kill PID Kills a process
nice Starts a process with a given priority
renice Changes priority of an already running process
df Gives free hard disk space on your system
free Gives free RAM on your systemVI Editing Commands
VIM Command Description
i Insert at cursor (goes into insert mode)
a Write after cursor (goes into insert mode)
A Write at the end of line (goes into insert mode)
ESC Terminate insert mode
u Undo last change
U Undo all changes to the entire line
o Open a new line (goes into insert mode)
dd Delete line
3dd Delete 3 lines
D Delete contents of line after the cursor
C Delete contents of a line after the cursor and insert new text. Press ESC key to end insertion.
dw Delete word
4dw Delete 4 words
cw Change word
x Delete character at the cursor
r Replace character
R Overwrite characters from cursor onward
s Substitute one character under cursor continue to insert
S Substitute entire line and begin to insert at the beginning of the line
~ Change case of individual character

Hope this Linux reference guide helps you!

希望这些常用的命令和系统原理,以及linux操作可以帮助大家提升linux命令和操作!!!

你可能感兴趣的:(Linux基础命令和原理总结)