Linux learning (2) common command learning

Summary of common Linux commands (1):

 

View command help:

1, man command

2. Command --help

 

Directory switching : cd

cd directory switch directory hierarchy change directory

cd directory/directory

cd .. : the upper level directory

cd / : root directory

cd ~ : go home

 

Create and delete directories

mkdir create

mkdir directory name

mkdir -pa/b/c, short for mkdir to create directories make directories

mkdir a/b/c.txt iteratively created

rmdir delete

rmdir directory name: only one empty directory can be deleted

 

Display the list of files in the directory (use ll later)

ls -l(long) -d(directory) displays the abbreviation of directory or file list

ls: Names of visible files (and directories) displayed

ls -a: show the names of all files

A "." in front of a file means a hidden file

ls -l: show file details

Shorthand : ll(★)

ll -h: friendly display

Browse documents

cat: show all the contents of the file

cat filename

more: paging display

Space : next page

carriage return : next line

less: paging display

It can be viewed through the PgUp PgDn page

tail(★★)

View the content of the back of a file

tail - displays the last few lines of filenames

tail -f filename

dynamic viewing

For example :

tail -f catalina.xxx.log

End scrolling with ctrl+c

file manipulation

create a file

touch filename creates a blank file

copy file

cp file directory/filename

For example :

cp 1.txt 2.txt Copy 1.txt and name it 2.txt

cp 1.txt 1/1.txt Copy 1.txt to 1.txt in 1 directory

Move files (rename)

mv file directory/filename

mv filename new filename

-i: ask whether to overwrite if the destination file already exists

-f: enforce, don't ask

-u: If the destination file exists, it will only be moved if it is newer than the source file.

 

delete file rm

rm filename: delete with query

rm -f filename: delete without asking

rm -r directory: recursive delete with query

rm -rf directory: recursive delete without asking (use with caution)

-r/R --recursive delete all directory layers under this directory at the same time

-f force delete file

To delete a file, generally use rm oldboy.txt. This method will prompt you to confirm, which is recommended for beginners.

The rm -f oldboy.txt method does not prompt for confirmation, but deletes it directly, which is dangerous and is not recommended for beginners.

It is recommended not to use "rm -fr file name" for file deletion . This method of killing chickens with a knife is unnecessary. "rm -f file". rm -fr is generally used to forcefully delete a directory without prompting. very dangerous

 

tar: package or decompress a file or directory (★★)

Commonly used combinations

-cvf : pack a file or directory

-zcvf: Pack and compress a file or directory Compression format: gzip

-xvf: extract or open a tar file

Format :

tar parameter file name to be packaged | decompressed file directory

For example :

Package all files in the current directory into test1.tar

tar -cvf test1.tar ./*

Package and compress all files in the current directory into test2.tar.gz

tar -zcvf test2.tar.gz ./*

Extract test1.tar to the current directory

tar -xvf test1.tar

Unzip test1.tar to the b directory

tar -xvf test1.tar -C b

Other common commands

grep: find matching strings (★)

grep string

pwd: show the current working directory

wget: download data

wget resource path

vi and vim editor

Edit normal files

Three modes: command line, insert, bottom line mode.

Switch to command line mode: press the Esc key;

Switch to insert mode: press i, o, a keys;

i is inserted before the current position

I insert at the beginning of the current line

a is inserted after the current position

A is inserted at the end of the current line

o Insert a line after the current line

O inserts a row before the current row

Switch to bottom line mode: press : (colon);

vi/vim notepad editor

Execute vi oldboy.txt to enter the vi editor, click a or i (insert abbreviation) to enter the editing mode to start editing the content, after editing, press the esc key to exit the editing mode, and finally press :wq to save and exit the file wq is the abbreviation of Write quit, In the command mode, you can type a colon ":" after the command parameters can be connected. q only save without exit, :wq! force save and exit

 

> redirection (data flow in the direction of the arrow) overwrites the original file

>> append redirection (data flow in the direction of the arrow) appends content to the end of the original file

cat to view file contents

cat >>oldboy.txt<<EOF XXXXXXX EOF Among them, XXX in the middle of AAA is the content that needs to be written into oldboy.txt, and EOF is the logo and can be replaced by other characters, as long as it is a pair. The EOF at the end needs to be written in freeze frame.

 

The head header displays the file header -n (number of lines), the default header is 10 lines

The tail of the tail shows the end of the file -n (the number of lines), the default is 10 lines at the end

grep filter function command

What needs to be found (what you want) + filtered files

-v + content to be filtered out (excluded content) + filtered files

 

sed fetches various content

-n suppress default output

p print

d delete

sed -n /xxx/p file xxx is the content to be queried

sed /^xxx/d file excludes the output of content starting with xxx

 

 

Pipe | ★

An important concept whose role is to use the output of one command as the input of another command

For example :

Find the 192.168 string in the results of ifconfig

ifconfig | grep 192.168

Find processes commonly used

Find processes related to java

ps -ef | grep java

Find information about 3306

ps -ef | grep 3306

system management commands

date Display or set the system time

date displays the current system time

date -s "2014-01-01 10:10:10" set the system time

clear clear screen

ctrl+l

ps Status of a running process

ps -ef to view all processes

★ps –ef | grep ssh Find a process

kill kill a process

kill 2868 kills the process numbered 2868

★kill -9 2868 Force kill process

network management

ifconfig: view all network settings

ifconfig NIC name down : disable NIC

ifconfig NIC name up : enable NIC

ping: same as in window

Cancel via ctrl+c

netstat View network ports.

netstat -an | grep 3306 Query the occupancy of port 3306

 

yum install tree -y install command from internet to server

tree to view the directory structure

LANG=en Temporarily adjust character set

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325985260&siteId=291194637