• Linux is strictly case sensitive
  • All content in Linux is saved as files, including hardware, users, and files
  • Linux does not rely on extensions to distinguish file types, but on permissions, but there are some convention extensions for administrators to see
    • Package.gz. bz2.tar.bz2.tgz
    • Binary file.rpm
    • The web page file.html.php
    • Script file.sh
    • Configuration file.conf
  • Windows programs cannot be installed and run directly on Linux
  • Linux makes more use of character interfaces
    • It consumes less system resources

    • Reducing the possibility of errors and attacks will make the system more stable

Connecting to the server

  • The simplest is to use the Web shell directly
  • SSH connection
SSH [email protected]Copy the code

Press Enter -> Yes -> Enter your password

Common Linux Commands

Common directory

directory use
/ The root directory
/boot Start the directory and start the related files
/dev Device file
/etc The configuration file
/home Ordinary user home directory, can operate
/lib System library save directory
/mnt Mobile device mount directory
/media The cd-rom mounting directory
/misc Mount directory of the tape drive
/root Super user's home directory, can be operated
/tmp Temporary directory, operable
/proc Running kernel information mapping, mainly output process information, memory resource information, disk partition information and so on
/sys Hardware device driver information
/var variable
/bin Common basic commands, such as ls and chmod, can be used by common users
/sbin Basic system commands, such as shutdown and reboot, are used to start and repair the system. Only administrators can run these commands
/usr/bin It’s a run script for some software you installed later
/usr/sbin Place some user-installed system administration essentials

Basic Command format

Command prompt

[root@xxxx tmp]#
Copy the code
  • Root Current login user
  • Host name localhost.
  • ~ Current working directory, default is the current user’s home directory
  • Prompt, super user is #, normal user is $

The command format

  • Command [options] [Parameters]
  • You can write them together when multiple options are available
  • -a is equivalent to –all

ll = ls -l

  • Ls: list lists all files in the current folder
  • -l: lists detailed file information
  • -a Displays all files, including hidden files
  • -d Displays the properties of the directory itself, not the subfiles
  • -h Displays the file size in a user-friendly manner

mkdir

  • Create a directory
  • Mkdir -p [directory] // Recursive creation
mkdir aa
mkdir -p bb/cc
Copy the code

cd

  • Change directory
  • CD catalogue
    • To the home directory
    • .Current directory
    • . The higher the directory
  • The relative path refers to the current directory
  • The absolute path starts at the root
  • You can press TAB to complete commands and directories
cd hello
Copy the code

pwd

  • PWD = print working Directory

rmdir

  • Remove empty directory
  • Rmdir [directory]
rmdir hello
Copy the code

rm

  • Delete a file or directory remove
  • Rm [file or directory]
    • -r Deletes a directory
    • -f Forcible deletion
  • Rm -rf [file or directory] Deletes all directories recursively
rm -rf hello
Copy the code

cp

copy

  • -r Replication directory. The default directory is files
  • -i will prompt you when copying files

mv

Move or rename

ln

  • Link command to generate a link file link
  • Ln [source file] [target file]
    • Creating hard links
  • Ln -s [source file] [target file]
    • -s Creates a soft link
  • Similar to Windows shortcuts
  • If you change one file, the other one will change
  • If the source file is deleted, the soft link cannot be used
  • The soft link source file must be written in an absolute path
ln -s /root/folder/1.txt 11.txt
Copy the code

File search command

locate

  • It is faster to search by file name in the background database
  • Data stored in the/var/lib/mlocate/mlocate db background database, updated once a day
  • You can update the database immediately with the updatedb command
  • You can only search for file names
Yum install mlocate -y // Mlocate needs to be installedCopy the code

which

  • You can see the alias which ls
  • All you can see are externally installed commands
  • You cannot view the built-in commands of the shell, such as which CD

The environment variable

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

  • Defines the path of the system search command
  • echo $PATH
  • The operating system is multi-user, system variables take effect for all users, and user variables take effect for the current user

find

  • File search command
  • Find [search criteria]
Search by name
  • Avoid extensive searches, which consume system resources
  • -name
  • -I is case insensitive
TXT // Find the file whose name is 1. TXT in the root directoryCopy the code
The wildcard
  • The find function searches the system for the name of a file that meets the conditions. If a match is required, the wildcard is used to match the name. The wildcard is a full match
  • The wildcard
      • Match anything
    • ? Matches any character
    • [] Matches any character in brackets
-iname ab[cdef]. TXT // Abc.txt file can be foundCopy the code

Search by time
find -mtime +5
Copy the code
parameter meaning
atime File access time
ctime The time to change file attributes
mtime Time to modify file contents
parameter meaning
– 5 Files modified within 5 days
5 Files modified 5 days ago
+ 5 The file was modified 5 days ago

Search by size
  • K lowercase, M capital
find . -size +0k
Copy the code
parameter meaning
-8k Less than 8 k
8k Equal to 8 k
+8k More than 8 k
Integrated application of
find /tmp -size +10k -a -size -20k
Copy the code
  • > 10KB and < 20KB
  • A and logical and both conditions are satisfied
  • -o or Logical or, one of the two conditions can be met
  • -exec operates on the result of the previous command
find /tmp -size +10k -a -size -20k -exec ls -lh {} \;
Copy the code

grep

  • Matches a qualified string in the file
    • -i ignores case
    • -v Excludes the specified string
  • Run the find command to search the system for the name of a file that meets the requirements. If a match is required, use a wildcard
  • The grep command is used to search for matching strings in the file. If matching is required, use the regular expression to match
Vi a.txt cat a.txt // cat concatenate is used to connect files and print them to the standard output device. Grep b a.thist grep -v b a.thist // a.thist F is not displayed in the grep -i f a.thist // a.thist command, which is case insensitiveCopy the code

Decompression command

zip
  • A compressed file or directory is a compressed format
function The command
The compressed file Zip Zip file name. Zip source file
Compressed directory Zip -r Indicates the name of the compressed directory. Zip indicates the source directory
Unpack the Unzip The name of the pressurized directory. Zip
yum install unzip zip -y

mkdir book
touch book/1.txt
touch book/2.txt
zip -r book.zip book
rm -rf book
unzip book.zip
Copy the code

gzip
  • Gzip is high voltage and can compress files even smaller
  • The gzip command does not support directories
The command The sample
Gzip source file Gzip a.txt does not save source files, only compressed files after compression
Gzip -c Source files > Compressed files Gzip -c a.txt > a.txt.gz saves the source file
Gzip a.txt > a.txt.gz // will save the source file. Gzip -r book // Will compress the files in the book directory. Gzip -d a.txt.gz // decompress gunzip a.txt.gz // decompressCopy the code

Useradd Zhangsan // Create user ZhangsanCopy the code
tar
  • Pack command, pack only, not compress
  • Tar -cvf Package file name source file
    • – c packaging
    • -v Displays the process
    • -f Specifies the file name after packaging
    tar -cvf book.tar book
    Copy the code
    • – x packages
    tar -xvf book.tar
    Copy the code
tar.gz
  • Gzip is high compression, but does not compress folders.
  • Tar packs a folder into a file without compression
  • You can tar and then gzip folders when you compress them
Gz book // -z stands for gzip. Tar -zxvf book.tar.gz // Decompress the fileCopy the code

Close and restart commands

Shutdown shutdown command

  • -c Cancels the previous shutdown command
  • -h shutdown
  • – r to restart
  shutdown -r 06:00
  shutdown -c

Copy the code

init

  • Shutdown the init 0
  • Restart the init 6

logout

  • Exit logout

who

  • W or who
  • Last in reverse order, most recently logged in

Viewing file Contents

cat 1.txt

more

  • See more, page by page, can turn the page (space is next page, b is previous page)

head

  • // Check the first two lines

tail

  • Tail-2 1. TXT // Check the last two lines
  • Tail -f 1. TXT // View file changes in real time
Head - June 1. TXT | tail - 3 / / check before six after 3 / / 123456789 - > 123456 - > 456Copy the code