编程知识 cdmana.com

Summary of common commands in Linux operating system

file & Catalog related

Memory & other

see & create a file & Turntable sign

ls -a Show hidden files
ls -l Show file details
touch ~/aa Create a file in the home directory ( If the file exists, update the creation time )
touch ~/.aa Create hidden files in the home directory
. Represents the current directory
. . On behalf of the previous Directory
cd ~ Back to the user directory
cd / Return to root
cd . . Return to the previous directory
cd - Jump to the last open directory
cat /etc/shells Check what's under the current system shell
echo $SHELL View the currently in use shell

Create and delete directories

mkdir a establish a Catalog
mkdir a b c establish a,b,c Catalog
mkdir -p a/b/c Create a directory that contains relationships
tree View the current directory structure
rmdir a Delete empty directory a(rmdir Only empty directories can be deleted )
rm -r a Recursive deletion a Catalog
rm -rf a Mandatory deletion a Catalog

File moving and renaming

mv file1 file2 The file 1 Rename to file 2
mv a.c . ./ Move up one level
mv a.c . ./aaaa.c Move up and rename
mv . ./a.c ./ A higher level a.c Move to current directory
mv file1 -/ Moving files

Copy files and directories

cp file1 file2 Will file 1 Copy to file 2
cp file1 dir/ Copy the file to dir Under the table of contents
cp file1 . ./ Copy the file to the next directory
cp dir1 dir2 -r Put the table of contents 1 Copy to directory 2
cp dir1 ~/ -r Put the table of contents 1 Copy to user directory

View the details and output to the terminal

cat file1 see file 1 Details of
cat Waiting for user input , And output it to the terminal ,ctrl+d End input
more file1 Show only one screen of content , Press enter to display line by line , Press the space to display all of them
head -num file1 Before displaying the file num That's ok
tail -num file1 Show the end of the file num That's ok

Soft link hard link

ln -s file1 file2 establish file1 And file2 The soft links ( A symbolic link )
ln file1 file2 establish file1 And file2 A hard link

 Insert picture description here
Be careful : The existing file is file1, The established document is file2,
Soft link : Small display space , Depends on the file to which it is linked , Once the original file disappears , The file generated by soft link will be invalid
Hard links : The display is the same size as the linked file , The original file disappeared , Files generated by hard links will not be affected , Upper figure a.c , b.c , c.c Point to the same storage space , A hard link is equivalent to a pointer to a memory space , Deleting one pointer does not affect other pointer access to the same memory space

Calculation file Byte Count , Number of words , Number of columns

wc file1 Display the file in sequence , Number of words , Number of characters
wc -l file1 Show only rows
wc -w file1 Display only words Count
wc -c file1 Display only Bytes Count

Specify file view format

od -tc file1 With ASSCL Code form shows
od -tcx file1 With ASSCL Code and 16 Base display

Check the size of a directory

du -dm With M Displays the size of all current directories
du -dk dir1 With M Show directory dir Size
du -dk With K Displays the size of all current directories
du -hb dir With K Show directory dir Size
du -db With B Displays the size of all current directories
du -hb dir With B Show directory dir Size

Find files

find ./* -name “*.mp3” Find by filename
grep “string” ./* -R** Search by file content

-c Output only the count of matching lines
-i Case insensitive ( Only for single characters )
-h Do not display file name when querying multiple files
Find by filename : ./ Represents the following of the current file Is a wildcard that means all files ,-name Specify the name of the file you want to find " " Internal write file name ,.mp3 To refer to mp3 Final document , Some files are not accessible to ordinary users , Add in front sudo Can be accessed temporarily as a superuser
Search by file content : “string”,string Represents the content of the document , ./* Represents all files in the current directory , -R Means to proceed recursively
The whole meaning is : Recursively search for content in the current directory with string The file of

Change file permissions

chmod [u/g/o/a][+/-][r/w/x] file1 // Text setting
chmod [num1][num2][num3] file1 // Number setting method (num Value 0~7)
sudo chown root:root // Change file owner / All groups

File permissions explain
-rwxrwxrwx
The meaning of the first character :

  • Ordinary documents
    d Catalog
    l A symbolic link
    b Block device file
    c Character device file
    s socket file , Network socket
    p The Conduit
    The other nine characters : r Read permission ; w Write permissions ; x Executive authority
    The first three : File owner permissions ; The middle three : File all group permissions ; Last three : Other group permissions
    Text setting : u : user Users ; g : group All groups ; o : other Other groups
    Number setting method : num1 : Users ; num2 : All groups ; num3 : Other groups , take num Convert to binary , Where the bits are 1 It means that you have the corresponding authority, otherwise, there is No for example :
    777 -> 111111111 -> -rwxrwxrwx;
    111 -> 001001001 -> —x–x--x;
    665 -> 110110101 -> -rw-rw-r-x;
    774 -> 111111100 -> -rwxrwxr–;

View the path of the specified command

which cmd : cmd It's the name of the command

Check disk usage

df --block=GB With GB Form shows
df --block=MB With MB Form shows
df --block=KB With KB Form shows

mount / uninstall U disc

sud fdisk -l View partition
sudo mount /dev/sdb1 /mnt take U The disk is attached to mnt Under the table of contents
sudo umount /mnt take U Disk from mnt Directory to uninstall

Be careful : If there are files in the directory , mount U Files in the directory after disk will be hidden , When unloading U The hidden directory will appear again .

Compressed package management

tar [ Main options + Secondary options ] File or directory
Main options :
c : Create a new archive
r : Add the file to be filed to the end of the file
t : List the contents of the file , Check which files have been backed up
u : Update file , Replace the original backup file with a new file
x : Release files from Archives ( Commonly used )
Secondary options :
f : Use files or equipment , This option is usually required ( Commonly used )
k : Save existing files
m : When restoring files , Set the modification time of all files to now
M : Create a multi volume archive , So that it can be stored on several disks
v : Detailed report tar File information processed , If there is no such option ,tar Do not report file information ( Commonly used )
w : Every step requires confirmation
z : use gzip To compress / Unzip the file , Add this option to compress the archive file ,
But you must also use this option to decompress when restoring ( Commonly used )
j : use bzip2 To compress / Unzip the file , Add this option to compress the archive file ,
But you must also use this option to decompress when restoring ( Commonly used )

tar cvf dir.tar dir Create an archive
tar xvf dir.tar Restore an archive
tar zcvf dir.tar.gz dir With gzip Compress dir
tar zxvf dir.tar.gz With gzip decompression dir.tar.gz
tar jcvf dir.tar.gz2 dir With bzip2 Compress dir
tar jxvf dir.tar.gz2 With bzip2 decompression dir.tar.gz2
tar jxvf dir.tar.gz2 -C dir2 With bzip2 decompression dir.tar.gz2 To dir2 Under the table of contents
rar a -r newdir dir With rar Compress dir
unrar x dir.rar With rar decompression dir.rar
zip -r newdir dir With zip Compress dir
unzip dir.zip With zip decompression dir.zip

Process management

** command : who **
[rt123@localhost aa]$ who
rt123 :0 2019-02-27 11:09 (:0)
rt123 pts/0 2019-02-27 11:14 (192.168.197.1)
rt123 pts/1 2019-02-27 15:55 (192.168.197.1)
user name Terminal number Opening time
command : ps
PID TTY TIME CMD
7428 pts/1 00:00:01 bash
8536 pts/1 00:00:00 ps
Process number Terminal number
command :ps aux
-w : Wide output
a : Displays all processes on the terminal , Include other users' processes
r : Show only running processes
x : Display the process without control terminal

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 2 0.0 0.0 0 0 ? S 12:16 0:00 [kthreadd]
user Process number Use proportion Use proportion The terminal used ? No terminal Process running state S: sleep ; R: function

command : jobs // Display the background job number
fg num // Wake up the num No. 1 job to the front desk
bg num // Wake up the num No. 1 job is executed in the background , After executing the document +& To run in the background

kill -l // Look at all the signals
kill -num process // Send... To the process num Sign no.
2 : SIGINT // Interrupt signal
9 : SIGKILL // Kill process signal
11 : SIGSEGV // Segment error signal
18 : SIGCONT // Continue the signal
19 : SIGSTOP // Pause signal

env // View the current process environment variables
vim ~/.bashrc // Configure the current user environment variable
vim /etc/profile // Configure system environment variables
export:PATH=$PATH: New path

source file.sh // perform file What's in the script
. file.sh // perform file What's in the script
Both of them will pass the executed data to shell The parent process , If directly executed file.sh Then the data is released after the child process is finished
Script fixed format :
{
#! /bin/sh

Content
}

User management

sudo Temporarily changed to root user
su user name Switching users
sudo su Turn into root user (exit sign out root Pattern )
sudo userdel -r user name Delete user

Network management

ifconfig View network card information
sudo ifconfig eth0 down Close network card
sudo ifconfig eth0 up Open network card
sudo ifconfig eth0 IP to eth0 Configure temporary IP
ping Host name /IP Address Check if the host on the network is working
finger user name Show user details

Shut down and restart

powerdown // power failure
shutdown -t Number of seconds [-rkhncfF] Time [ Warning message ]
-t Number of seconds : Set to switch to different runlevel Before , The delay time between warning and deleting two signals
-k : Send only warning message text , But not really shutdown
-r : shutdown After the restart
-h : shutdown Then turn it off
-n : Not pass init, from shutdown The command itself turns off
-f : When you reboot , skip fsck Instructions , Don't check the file system
-F : When you reboot , Forced to do fsck Check
-c : Will already be in shutdown The action is cancelled
reboot // restart

Other commands

shift pageup Turn the page on the terminal
shift pagedown Terminal page down
man Check out the manual
man Number of chapters name See what's in chapters ( share 9 Chapter )
clear Clear the screen (ctrl + l)
alias ls=‘ls --color=auto’ to ls The left side of the equal sign replaces the right side of the equal sign
alias rm=‘rm -i’ Ask if you want to delete before deleting ,( After modifying the configuration file, restart the terminal to take effect )
echo [-n] character string Echo a string
echo $ Variable name Echo variables
echo $? Check the exit value of the previous program
date View current time
umask nnn Set the mask when creating the file , System mode The default is 666

Calculation permission formula : mode & (~umask) , The final number is the default permission

It's not easy to tidy up , Reprint please indicate the source ~

版权声明
本文为[Ran1366]所创,转载请带上原文链接,感谢

Scroll to Top