Linux-- basic commands

First, change directory command

cd usr - switching to the usr directory under the directory
cd .. - Switch to the parent directory
cd / - switching to the root directory
cd ~ - switching to the user's home directory such as user wil, the user's home directory it is: / Home / Wil
CD - - is located before the directory to the previous directory time line, the directory will separate line and its gradual Contents

Second, a directory operation command (CRUD)

2.1 add directory

Command: mkdir directory name
Example:
Create a test directory in the root directory /mkdir test

2.2 View catalog

Command: ls [-al] directory name
Example:
ls directory name displayed subdirectories it contains ls /
subdirectories ls name of the current directory displayed subdirectories subdirectories contained in the current directory ls /boot
ls -a show all subdirectories of the current directory, including hidden the (根目录下)ls -a
ls -l displays all subdirectories in a two-dimensional table form (根目录下)ls -l

2.3 Looking directory (search)

Command: find the directory name of the parameters
Example:
Find / root related to the test directory under / filefind / -name '*test*'

2.4 modify the directory name

Command: mv new directory name directory name
Example:
to build a oldTest directory test directory, modified to newTestmkdir oldTest(回车)mv oldTest newTest

mv rename / shear directories, files, and other compressed

2.5 directory location movement (shear)

Command: mv directories at the new location
Example:
In the test directory newTest cut to / usrmv newTest /usr

2.6 copy directory

Command: cp -r directories at the new location - r Representative recursive copy (if there is a subdirectory of the directory, together with copy walking)
Example:
The newTest of / usr copied to the root directory of the testcp -r /usr/newTest /test

cp rename / shear directories, files, and so compressed, the latter two do not add -r

2.7 delete the directory

Command: rm [-rf] directory name must be added when the -r or -rf delete directories. Probably because security is a directory, the system not sure whether there were other documents taken
Example:
delete / newTest under usr(进入 usr 目录下)rm -r newTest

Third, the operation command file

3.1 Create a file

Command: touch the file name - empty file
Example:
Create an empty file in the test directory (进入 test 目录下)touch aaa.txt(.txt ending just easy to remember people, the same as the file type)

View Files 3.2

Command: cat / more / less / tail filename
Example:
Use cat View / lib / ufw / ufw-init file, can only display the last screen content (by screen resolution limits) cat /lib/ufw/ufw-init
use more View / lib / ufw / ufw- init file, the percentage may be displayed, down the transport line, to view the next exit spaces, q more /lib/ufw/ufw-init
using less View / lib / ufw / ufw-init file, using the keyboard PgUp PgDn page up and down, q exit Review less /lib/ufw/ufw-init
use tail -num (num is a number) to view / lib / ufw / ufw-init file, display the contents of the last num linestail -10 /lib/ufw/ufw-init

Command "tail -f filename" can achieve dynamic monitoring of files

3.3 modify the contents of the file

Command: vim filename
: Sample
aa.txt file in edit / testvim aaa.txt

The initial command mode, you can not edit

  • Commonly used commands:
  • dd: Delete cursor line
  • Digital d d: starting from the cursor line, delete specified number of rows down
  • u: Undo the last step
  • yy: copy cursor line
  • Digital y y: line starting from the cursor, down a specified number of rows replication
  • p: In the following line the cursor line insert one or more rows of replication
  • x: equivalent to delete
  • X: equivalent to backspace
  • dw: delete a word, the cursor attention should be placed on the first letter of the word you want to delete
  • yw: copy a word
  • ^: Move the cursor to the beginning of the line
  • $: Move the cursor to the end of the line
  • Rows G: to a specific line
  • G: to the last line
  • gg: move to the first row

Tap i / a / o / O into edit mode

  • i: current character is inserted before the cursor
  • a: the cursor back to the current cursor character by character, and then insert
  • o: In the line where the cursor next row new blank line, and then move the cursor to the blank line inserted
  • O: line in the row where the cursor new blank line, and then move the cursor to the blank line inserted

Esc tap into the line mode or command mode input :, /, ?this mode is entered (current page last row editable area)
:entering this mode, common commands

  • :set nu: Set the line number
  • :set nonu: Cancel the setting line number
  • :%s/old/new/g: The old string with the new string

/Entering this mode is mainly used to find
/查找的字符串: n to find the next matching string, N to find a matching string

?Entering this mode is mainly used to find
?查找的字符串: n find a matching string, N to find the next matching string

3.4 Delete Files

Delete the same directory: rm [-rf] filename

Fourth, the compressed file operation command

4.1 packaged and compressed files

Linux packaged files are generally ends in ".tar", compression commands generally ".gz" at the end. Under normal circumstances be packaged together and compress the file extension is packaged and compressed ".tar.gz"

Command: tar -zcvf after packing the compressed file name you want to pack all the file compression

  • z: call gzip compression to compress command
  • c: Packed file
  • v: display during operation
  • f: specify the file name

Example:
Packing and all the files in the / test, named xxx.tar.gz compressed tar -zcvf xxx.tar.gz aaa.txt bbb ccc.confortar -zcvf xxx.tar.gz /test/*

4.2-extracting archive

Command: tar -xvf archive
Example:
The xxx.tar.gz in / test extract to the current directory tar -xvf xxx.tar.gz
to the lower xxx.tar.gz / test to extract the root directory / usr lower tar -xvf xxx.tar.gz -C /usr- C on behalf of that location

Five other command

5.1 displays the current location

Command: pwd

5.2 Search command

Command: grep string to search for the file being searched
Example:
search / lib / ufw / ufw-init file if the character string contains the line grep if /lib/ufw/ufw-init(if the file contains the line string will be highlighted in the "if" Display)

5.3 View process

Command: ps -ef
Example: View processes that are currently running on the system (all)ps -ef

5.4 Pipe command

Command: | The output of the previous command as input for this directory
Example: View all processes in the system, including processes currently hold the stringps -ef | grep hold

5.5 End Process

PID kill -9 process: Command

5.6 Network Communications Command

View current system information of NIC: ifconfig
view the case is connected to a machine: ping IP address
to view the current system of port use: netstat -an

Sixth, authority to order

Permissions for each file / directory so has permissions can view the file in a directory / directory by ls -l command
either under a directory ls -l

wil@ubuntu:/$ cd boot
wil@ubuntu:/boot$ ls -l
total 145136
-rw-r--r-- 1 root root   218357 Jun 27 00:04 config-4.18.0-25-generic
-rw-r--r-- 1 root root   224446 Jul 29 08:46 config-5.0.0-23-generic
drwxr-xr-x 5 root root     4096 Aug  4 06:04 grub
-rw-r--r-- 1 root root 59792498 Jul 25 23:32 initrd.img-4.18.0-25-generic
-rw-r--r-- 1 root root 61980960 Aug  3 03:11 initrd.img-5.0.0-23-generic
-rw-r--r-- 1 root root   182704 Jan 28  2016 memtest86+.bin
-rw-r--r-- 1 root root   184380 Jan 28  2016 memtest86+.elf
-rw-r--r-- 1 root root   184840 Jan 28  2016 memtest86+_multiboot.bin
-rw------- 1 root root  4268427 Jun 27 00:04 System.map-4.18.0-25-generic
-rw------- 1 root root  4289273 Jul 29 08:46 System.map-5.0.0-23-generic
-rw------- 1 root root  8552184 Jun 26 21:32 vmlinuz-4.18.0-25-generic
-rw------- 1 root root  8707832 Jul 29 08:49 vmlinuz-5.0.0-23-generic

The first character in the first column is "D", the representative 目录; is "-", the representative 文件; is "L", on behalf of 链接, may be considered as a shortcut in Windows
followed by nine characters, each of three groups, Representative permission of the owner, the user rights of the current users in the same group, any user of
each character, R & lt representatives read access, write access on behalf of W x represents the execution right, - indicates no permission. r, w, x can be used in place of 4,2,1 digital
to conduct a first embodiment, the creator has the right to read and write access to a group of users and the other users have read access

Command authority to modify the file / directory: chmod
Example:
Modify permission aaa.txt under test / have full access to the owner, the owner's group have read and write access to other users only read access chmod u=rwx,g=rw,o=r aaa.txtor chmod 764 aaa.txt(each number is where digital rights on behalf of the group and)

Guess you like

Origin www.cnblogs.com/xxwang1018/p/11546690.html