Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic commands in linux

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "what are the basic commands in linux". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what are the basic commands in linux" can help you solve the problem.

one。 System switch, restart command 1.1 shutdown

Format: shutdown [options]

Common command options:

-r: restart the system

-h: shut down the system

-c: cancel running shutdown

1.2 init 0 / / shut down system 1.3 init 6 / restart system 1.4 reboot / / restart system two. View Class Command 2.1 type

Format: type [Command] / / View command type

Example:

[root@HH Desktop] # type who

Who is / usr/bin/who

[root@localhost ~] # type service

Service is hashed (/ sbin/service)

2.2 pwd

Format: pwd [option (can be null)]

Common option

-P / / output the actual physical path of the current working directory

-L / / output the link path of the current working directory

Example: [root@rhel init.d] # pwd

/ etc/init.d / / the user's current working directory path is / etc/init.d

[root@rhel init.d] # pwd-P

/ etc/rc.d/init.d

[root@rhel init.d] # pwd-L

/ etc/init.d

2.3 cd

Format cd [options]

Common options:

Cd ~ / / enter the root directory

Cd-/ / returns the directory where it was last located

Cd. . / / return to the previous directory

Cd. . /. . / / return to the upper two-level directory

2.4 ls

Format ls [options] / / View contents of the directory

Common command options

-l: displays (abbreviated as "ll") the details of the directory in a long frame

-a: show all directory and file information, including hidden files

-A: similar to "- a" but does not display "." And ".." Information about the directory

-d: displays the properties of the directory itself

-h: displays information in more readable byte units (K, M), etc.

-R: recursively display content

-color: distinguishes different files by color

Example:

[root@localhost ~] # ls-l

Total dosage 132

-rw-. 1 root root 2158 March 9 17:58 anaconda-ks.cfg

Drwxr-xr-x 14 root root 4096 March 10 14:38 cmake-2.8.6

Drwxr-xr-x 4 root root 4096 March 10 15:01 DiscuzPkg

-rw-r--r--. 1 root root 64664 March 9 17:58 install.log

2.5 which

Format: which [Command] / / View Command address

Example:

[root@localhost ~] # which service

/ sbin/service

2.6 who

Format: who / / displays the information of the user who has logged in to the current computer

Example:

[root@rhel ~] # who

Zhngsan tty2 2017-03-20 02:11

Root tty1 2017-03-11 18:00

2.7 du

Format: du [options]... [directory name] / / Statistics the space occupation of catalogs and files

Common command options:

-a: include all files in statistics, not just catalogs

-h: displays information in more readable byte units (K, M, etc.)

-s: only the total space occupied by each parameter is counted.

Example:

[root@localhost ~] # du-ah / root/cmake-2.8.6/

4.0K / root/cmake-2.8.6/Source/cmVersionMacros.h

76M / root/cmake-2.8.6/Source

4.0K / root/cmake-2.8.6/CMakeGraphVizOptions.cmake

32K / root/cmake-2.8.6/Makefile

52K / root/cmake-2.8.6/bootstrap

4.0K / root/cmake-2.8.6/cmake_uninstall.cmake

4.0K / root/cmake-2.8.6/ http://CTestCustom.cmake.in

4.0K / root/cmake-2.8.6/Copyright.txt

52K / root/cmake-2.8.6/CMakeCache.txt

170M / root/cmake-2.8.6/

three。 Show text file contents 3.1 cat

Format: cat [File name] / / View the contents of the file

Example:

[root@localhost hh] # cat ss

Hspowudoabc

Skajcwu

Jaicboa

3.2 less

Format: cat [file name] | less / / you can turn the page to view all the contents of the file

3.3 more

Format: cat [File name] | more / / View all the contents of the file and cannot turn the page

3.4 tail

Format: tail [options] [File name] / / View the contents of the file

Common option

Tail-# file / / View the last # line of the file

Tail-f file / / View what is added to the file in real time

Head-# file / / View the first # lines of the file contents

Example:

[root@localhost hh] # cat ss

Hspowudoabc

Skajcwu

Jaicboa

[root@localhost hh] # tail-1 ss

Jaicboa

four。 Directory and file operations 4.1 wc

Format: wc [command] [file absolute path] / / A pair of files for statistics

Common commands:

Wc [absolute path] / / count the number of lines, size, and characters

Wc-l [absolute path] / / count rows

Wc-w [absolute path] / / count the number of characters

Example:

[root@localhost hh] # cat ss

Hspowudoabc

Skajcwu

Jaicboa

[root@localhost hh] # wc ss

4 3 29 ss

4.2 find

Format: find [path] [option]

Common command options

-name: [file name] / / find a file by its name

-user: [user name] / / find the file by the user owner of the file

-group: [group name] / / find the file according to the group owner of the file

-type: [file type] / / find files by file type

-size: n [ckMG] / / find files of size n, where n is a number, c is a byte, and k-generation KB,M stands for MB,G and GB

Example:

[root@localhost ~] # find /-name w

/ var/lib/yum/yumdb/w

/ usr/share/terminfo/w

/ usr/bin/w

4.3 mkdir

Format mkdir [directory name] / / create directory

Common command options

Mkdir dir1 / / create a directory called 'dir1'

Mkdir dir1 dir2 / / create two directories at the same time

Mkdir-p / tmp/dir1/dir2 / / create a directory tree

4.4 touch

Format touch [file name] / / create a file

4.5 cp

Format: cp [options] [Source path] [destination path] / / copy the contents of the source path to the destination path

Common command options

-r: recursive replication

-p: copied with attributes

-a: all copies of the directory

Example:

[root@localhost ~] # cp-r / root/etc / root/ww / / copy all the contents of the etc directory under root to the ww directory under the root directory

[root@localhost] # cp-r / root/*. / / copy all files in the root directory to the current directory

4.6 ln

Format: ln-s [directory or file] [link name] / / create a soft link to a directory or file. If the source file changes, the link becomes invalid.

Ln-l [directory or file] [link name] / / create a hard link to the file. Changes to the source file do not affect the link.

Example:

[root@localhost ~] # ln-s / root/media/Centos / root/cdrom / / create a soft connection cdrom pointing to the Centos image directory under the root directory

[root@localhost ~] # ln-l / root/media/Centos / root/cdrom / / create a soft connection cdrom pointing to the Centos image directory under the root directory

4.7 rm

Format: rm [options] [file or directory] / / delete file or directory

Common command options

-f file1 / / forcibly delete a file called 'file1'

-rf dir1 / / forcibly deletes a directory called 'dir1' and deletes its contents at the same time

-r dir1 / / Recursively delete the directory and the contents in the directory (need to confirm in turn)

4.8 mv

Format: mv [source file or directory] [destination file or directory] / / move the file or directory under the current working directory

Example:

[root@localhost ~] # ls

A b hh

[root@localhost ~] # mv a b

[root@localhost ~] # ls

Hh b

[root@localhost ~] # cd b

[root@localhost b] # ls

A

4.9 grep

Format: grep [options] [find Mode] [File] / / find and display the line containing the specified string in the file

Common command options

-I: lookup ignores case

-v: reverse lookup and output lines that do not match the condition

Find condition settin

1. The string to be found is enclosed in double quotation marks

2. "^." / / denotes with. The beginning

3. ". $" / / denotes as. End

4. "^ $" / / represents a blank line

4.10 gzip 、 bzip2

Format: gzip [options] [File] / / create and decompress gzip compressed documents

Bzip [options] [File] / / create and decompress bzip compressed documents

Common command options

-Q: indicates the high pressure ratio, usually at the time of creation

-d: used to unlock compressed files

Example:

[root@localhost hh] # gzip kk

[root@localhost hh] # ls

Kk.gz

4.11 tar Archive

Format: tar [option] [compressed package name .tar] to create a compressed package

Common command options

-c: create a package file for tar

-x: unlock the package file in tar format

-f: use archive files

-z: compress with gzip

-j: compress with bzip2

Example:

Tar-cvf [compressed package name .tar] file1 / / create an uncompressed tarball

Tar-cvf [compressed package name .tar] file1 file2 dir1 / / create an archive file containing 'file1',' file2' and 'dir1'

Tar-tf [compressed package name .tar] / / displays the contents of a package

Tar-xvf [compressed package name .tar] / / release a package

Tar-xvf [package name .tar]-C / tmp / / release the package to the / tmp directory

Tar-cvfj [compressed package name .tar] .bz2 dir1 / / create a compressed package in bzip2 format

Tar-xvfj [compressed package name .tar] .bz2 / / decompress a compressed package in bzip2 format

Tar-cvfz [compressed package name .tar] .gz dir1 / / create a compressed package in gzip format

Tar-xvfz [compressed package name .tar] .gz / / decompress a compressed package in gzip format

4.12 chmod

Format: chmod [options] [mode] [file] / / change the mode of a file or directory

Chmod [options] [File]

Common option

-v: process output diagnostics for each file

-R: recursively change files and directories

Operation object

U: user owner

G: group owner

O: other users

A: all users

Operation symbol

+: add a permission

-: cancel a permission

Authority

R: read permission

W: write permission

X: executable permission

Example:

Chmod Ubunw hh / / add user owner write permissions to the hh file

4.13 sed

Format: sed [options] [commands] file name / / non-interactive editor

Common option

-n: cancel default input

-e: multiple editors

-I: directly modify the contents of the read file and do not display

Common command

A: add a line after the current line

I: add a line before the current line

C: replace lines with strings

S: replace one character with another

P: print out the selected data, usually used with sed-n

Example:

Sed-n "2 s/root/hh/g" passwd / / replace all root in the second line of the passwd file with hh

five。 Get help 5.1 man

Format: man [option (or empty)] [command]

Common options:

-M [path] / / specify the search path for the man man page

-a / / Show all man pages

Example:

[root@localhost hh] # man pwd

5.2 help

Format: help [option (or empty)] [command]

Common options:

-d / / display a short topic description of the command

-s / / displays a short syntax description of the command

Example:

[root@localhost hh] # help pwd

six。 Vi text Editor commands

Format: vim [file] / / enter the vi editor to edit the document

Shift: / / editor internal operation language

Example:

/ set nu / / View row serial number

/ nonu / / do not look at the serial number

6.1 cursor movement

Operation type operation key function cursor movement up and down left and right turn page Page Down or Ctrl+F flip down a whole page of content Page up or Ctrl+B flip up a whole page of content quickly jump home key or "^", The number "0" jumps to the beginning of the line End or the "$" key jumps to the end of the line quickly jumps to the first line of the file G jumps to the end of the file # G jumps to the # line number in the file: set nu displays the line number in the editor: set nonu does not display the line number in the editor

6.2 copy, paste, delete

Action type operation key function deletes a single character at the x or Del delete cursor dd deletes the current cursor line # dd deletes all characters from the beginning of the cursor to the beginning of the line d ^ deletes all characters before the current cursor to the beginning of the line & deletes all characters from the current cursor to the end copy yy copies the contents of the current line to the clipboard # yy copies the contents of the # line starting at the cursor pastes p to the buffer After pasting the contents of the cursor to the cursor position, P pastes in front of the cursor position.

6.3 File content lookup

The operation key function / word looks up the string "word" in the file from top to bottom. Word looks for the string "word" n in the file from the bottom up to locate the next matching found string "word" N to locate the last matching found string "word"

6.4 undo edits and save exit

Operation key function u press once to cancel the most recent operation, press u key repeatedly to restore the multi-step operation U used to cancel all edits made to the current line ZZ saves the current file contents and exits the vi editor

6.5 Save the file and launch the vi editor

Operation type operation key function save file: W save modified file: W / root/newfile save as other file exit vi:q unmodified exit: Q! Discard changes, exit save and exit vi:wq

6.6 Open a new file or read in other file contents

Operation key function: e ~ / install.log opens a new file for editing: r / etc/filesystems reads other file contents in the current file

6.7 File content replacement

Operation type operation key: s / old/new replaces the first character "old" string found in the current line with "new": s / old/new/g replaces all strings "old" found in the current line with "new": #, # s / old/new/g in line number "#" # "replace all strings" old "with" new ":% s / old/new/g replace all strings" old "with" new "throughout the file: s / old/new/c add c at the end of the replace command

This is the end of the introduction to "what are the basic commands in linux". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report