Linux基礎(chǔ)命令和原理總結(jié)

作為一個程序員或者測試開發(fā)人員,我們在進(jìn)行項目部署和運維時,經(jīng)常會用到一些linux命令,可是這些命令老是忘記,每次用到的時候都要去谷歌百度,很是麻煩!這不,為了自己使用方便,對常見的linux命令, SHELL, VIM, Linux性能調(diào)優(yōu)和linux kernel的總結(jié),以便在用到時能夠快速地找到相關(guān)命令,同時有需要的朋友也可以參考搜藏該篇文章!文章對講到的每個命令都有詳細(xì)的參數(shù)解釋,并且給出一些常用例子,因此也非常適合用來學(xué)習(xí)!


image.png
image.png
image.png
  1. 工作中常用的命令總結(jié);

shell(命令解釋器)自帶的命令稱為內(nèi)部命令,其它的是外部命令
內(nèi)部命令使用help幫助:help cd
外部命令使用help幫助:ls --help
type命令:用于區(qū)分是內(nèi)部命令還是外部命令:

type ls

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

type cd

cd is a shell builtin #內(nèi)部命令
pwd命令:顯示當(dāng)前目錄
ls命令:查看目錄和文件名稱
ls -l 查看目錄各個字段含義

第一字段:首字母代表的是文件類型 ,其中"-"為普通文件、"d"為目錄文件、"c"為字符設(shè)備文件、"b"為塊設(shè)備文件、"p"為管道文件、"l"為鏈接文件、"s"為socket文件?!皉wx”分別代表擁有讀、寫和執(zhí)行權(quán)限,"-代表無對應(yīng)權(quán)限。三個"rwx"依次代表文件所有者、文件所有者所在用戶組、其它用戶對文件擁有的權(quán)限。
第二字段:文件硬連接數(shù)量
第三字段:文件擁有者
第四字段:文件擁有者所在組
第五字段:文件大?。ㄒ宰止?jié)為單位)
第六字段:文件最后更改時間
第七字段:文件名(若為鏈接文件則追加顯示其鏈接的原文件的路徑)

ls命令其它參數(shù)含義:
-a顯示隱藏文件(.開頭的文件)
-r逆序排序
-t按照時間順序顯示
-R遞歸顯示
ls -lartR : 按照時間順序倒序顯示所有文件及其文件夾的文件

cd命令:更改當(dāng)前的工作目錄
cd /path/... 絕對路徑
cd ./path/... 相對路徑(./可以省略)
cd ../path/... 相對路徑

mkdir -p 遞歸目錄:遞歸創(chuàng)建目錄

rmdir命令:刪除目錄
rmdir a/b/c/d/e/ #刪除空目錄
rm -r a/b/c/d/ #遞歸刪除目錄,但是系統(tǒng)會做多次詢問
rm -rf a/b/c/d/ #刪除目錄,不做任何詢問

cp命令:復(fù)制文件和目錄
-r 復(fù)制目錄
-p 保留用戶、權(quán)限、時間等文件屬性

mv命令:移動文件和重命名
mv *.log 目標(biāo)目錄

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

cat命令:文本內(nèi)容顯示到終端

head命令:查看文件開頭
head -3 文件名稱 #顯示文件開頭3行

tail命令:查看文件末尾
tail -3 文件名稱 #顯示文件末尾3行
tail常用參數(shù)-f,文件內(nèi)容更新后,同步顯示更新的文件信息
tail -f 文件名稱

wc命令:統(tǒng)計文件內(nèi)容信息
wc 文件名稱

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

userdel命令:刪除用戶
userdel 用戶名 用戶所在的家目錄不會被刪除
userdel -r 用戶名 用戶相關(guān)的所有配置都會被刪除

passwd命令:修改用戶密碼
passwd 用戶名

usermod命令:修改用戶屬性

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

/etc/shadow文件:查看用戶密碼
tail /etc/shadow

groupadd命令:添加用戶組
groupadd 用戶組

groupdel命令:刪除用戶組
groupdel 用戶組

用戶切換
su 用戶名 切換用戶,但是用戶所在環(huán)境不變,即pwd路徑不會變化
su - 用戶名 切換用戶,同時會切換到用戶家目錄,即/home/用戶名

sudo命令:普通用戶需要執(zhí)行root用戶權(quán)限的解決方案。

  1. linux基礎(chǔ)的原理和一些常用的命令;


    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總結(jié);


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

Linux常用命令作為it人員的必備技能,我們需要掌握常用的基礎(chǔ)命令,本文總結(jié)了工作中常用的命令列出來,希望可以幫助大家經(jīng)常查閱,解決工作中的問題. 有需要補(bǔ)充可以聯(lián)系我,完善文章.

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!

希望這些常用的命令和系統(tǒng)原理,以及l(fā)inux操作可以幫助大家提升linux命令和操作?。?!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容