Linux basic commands

Source: Internet
Author: User
Tags parent directory disk usage

Beginner Linux, summed up the basic common Linux commands.

First, System management commands

1. Logout

Exit--> is used for character interface, user switch, and graphical interface to close the terminal window;

Logout--> only for text terminals

2. Restart: Reboot (no parameters can be received)

-F: Forced restart

3. Shutdown: Shutdown (minimum 2 parameters must be received)

-R Delay Minutes "prompt message": How many minutes later to shut down the system;

-R Now: indicates immediate shutdown

Second, user, group management

    1. Useradd Add Users:

Useradd User name: Create user without password

Useradd User name –p password: Create a password user

passwd User name: Add password to existing password-free user

2.usermod Modifying users

Usermod–l New user name –d new storage directory old user name

3.userdel Delete User

Userdel–r User Name

4. Switch User su, sudo

SU User name

sudo + command statement--Enables administrator permissions.

Example: $ sudo mkdir dir_ folder (normal user new folder)

5. Add Group Groupadd

GROUPADD–R Group Name

GPASSWD-A User Name Group name---Add the user to a group

Example: Gpasswd-a user001 grp_test

6. Modify Group Groupmod

GROUPMOD–G Group New Id–n group new name group old name

7. Delete Group Groupdel

Groupdel Group Name

Third, network configuration

1. Configure IP Address file storage directory:/etc/sysconfig/network-scripts/ifcfg-eth0

2. View IP Address: ifconfig

3. Set dns:/etc/resolv.conf

4. Set the network profile:/etc/sysconfig/network

5. Start/stop/Restart Network command: Service network Start/stop/restart

Iv. Linux Text Editing VI

Usage vi+ file name

Common operations are as follows:

Nyy Copy the downward n-line content of the cursor yw the word after copying the cursor, with the space as the boundary p paste the copied content at the cursor NDD deletes the contents of the down n line of the cursor
R: Replace current position character x: Delete current position character Set number: Display line numbers set Nonu: Suppress line number: 1,3y Copy the first row to the third row: 1,3d Delete the first row to the third row/+ the string search string to find: Wq Save exit: Q Exit: q! Mandatory Exit v. Common management Commands 1. File management Get help command: Whatis,-help, man, Info LS Enumeration ls-l View the detailed properties of all files in directory CD directory switch CD: Back to the current user's personal directory CD/: Go back to the root directory CD. /xx: Back to the parent directory of the XX directory CD.: Stay in the current directory CD. : Return to Parent directory cd–: Go back to the last Action directory CD ~: Back to the user's home directory pwd display the current path CP copy usage: CP [parameter options] [source] [dest]

"Parameter Options"-B back up existing files

–r Copy the source files directory and files to the destination directory

-F If the destination has duplicate files, overwrite the original file

Example: Cp-rf a.txt/tmp

MV Move file or file name change

Usage: mv[options] source file or directory destination file or directory

Parameter:-F: Move existing files without interactive reminders, directly overwrite

MV FileName New file name--Rename

RM Delete files/directories

Usage: RM [-IFR] Name

-r: Delete directory and sub-directories below

-F: Do not ask for direct deletion

-I: Ask for confirmation before deleting

RmDir Delete an empty folder

Cat display File/line number

Usage: Cat [Options] File 1 [File 2] ...

-N: Enter the contents of all lines in the file and make the line number

-B: Blank lines are not numbered

-S: Two consecutive lines of blank lines appear as one line:

Head displays the beginning of the file

Usage: head [parameter] ... [File] ...

-N (N for rows): Displays several lines of content with blank lines

Tail viewing the end of a file

Usage: tail [parameters] [file]

–n (n for number): Displays the Countdown line contents

-F Dynamic Read

Du file and directory disk usage space

Usage: du [options] [file]

-S: Show total

-m: Output in megabytes

Lsof list tools to open files for the current system

Usage: lsof [options] FileName

lsof + file name shows all processes for files

Lsof +d dir/The file opened by the process in the display directory

Lsof +d dir/Ibid., Search all directories under directory for a long time

chmod permission settings

Usage: chmod [options] [file] A. Assigning permissions in digital form: r=4, W=2,x=1 Read & write & Execute rwx:4+2+1;       Read & Execute r-x:4+1; Read-write rw-:4+2 B. Text mode

U – Owner of the file;

G-Persons belonging to the same group (group) as the owner of the file;

O-persons other than others;

A--all

+--Increase permissions

---Remove permissions

-R recursion, which is used primarily for a directory, to assign permissions to all files/folders under this directory

Example: chmod 777 filename Grants Read & Write & Execute permissions to a file

chmod G+RW ABC adds RW permissions to the group owner of the file ABC

chmod u-x ABC removes x permissions for the user owner of the ABC file

chmod o=rw-Other user rights for the specified file ABC are rw-

Chmod-r a+x ABC adds x permission for all files under file ABC and its subdirectories chgrp: Change file group usage: chgrp [options] [group] [file]-R recursive chown: Change file owner and owning group Law: chown [Options] User or group file name-R recursively alters the specified directory and all its subdirectories, the file's file main WC displays the number of rows, bytes, words, and other attributes of the file: WC [options] [file]-L: Count Rows-C: Statistics bytes Number-W: Count words 2. Search command grep: Display matching rows in a file usage: grep [parameter] string filename example: Grep-c "foo" a.txt ps-ef|grep httpd |gre      P-v "grep" Find: File usage under Lookup directory: The Find target directory search parameter action parameter-name file name: Can be followed by wildcard characters-ctime days: File last modified to a specified number of days before the negative numbers are indicated Example: Find/-name AAA File Locator: Locate Besttest.txt whereis MySQL which locate3. Archive compression

Gzip/gunzip Decompression/Decompression

gzip–c filename > filename.gz decompression

Gunzip filename.gz Decompression

Zip/unzip compressing zip package and compressing compressed files ending in. zip

Zip filename.zip filename (file to compress)

-R: Recursive compression

-M: Delete original file after compression

Unzip

-O: Overwrite existing files when extracting, no user confirmation required

-D directory Name: Unzip the compressed file to the specified directory

Example: Zip aaa.zip AAA Compression AAA file

Unzip Aaa.zip decompression Aaa.zip

Tar file packaging

tar [parameter] destination file source directory or file

-C: Create a new document

-X: Extracting archive files

-F: Using an archive file

-Z: Unzip with gzip

-V: Details output mode

Package: TAR–CVF Filename.tar file

Decompression: TAR–XVF Filename.tar

4. Process commands

PS shows the dynamics of the instantaneous process

-aux: Show all processes that contain other users

-EF: Show all processes and show relationships between different processes

Example: Ps-ef | grep httpd viewing process information for httpd

Ps-aux View All Processes

Kill terminates the process

Kill-9 Process Number

   

Linux basic commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.