Linux Basic Knowledge Comprehensive summary __linux

Source: Internet
Author: User
Tags chmod disk usage file permissions

The importance of learning Linux should be needless to say, I would like to make a comprehensive and simple summary of the basics of Linux. However, it is recommended to install a Linux system more practice, usually preferably only in the Linux environment programming, this will greatly improve.

Features of Linux

-Free/Open source
-Multithreading/multiuser support
-Good security
-Superior to memory and file management

shutdown Command
Shutdown-h now (shutdown immediately) Shutdown-r Now (restart your computer) reboot (restart your computer)

go to Desktop

StartX

User Login

log in as little as possible with the root account login, because it is the system administrator, the greatest authority, unavoidable operation error. You can log on as a normal user, and then use the "Su-" command to switch to system administrator status

User Logoff

Enter the logout at the prompt

Linux file system is a hierarchical tree directory structure , the top of this structure is the root directory "/", and then create other directories under this directory, a deep understanding of the Linux file directory is very important

- /
-Root, store root user related files
-Home, storing files for ordinary users
-Bin, a directory where common commands are stored, such as Vi,su
-Sbin, you must have certain permissions to use the command
-MNT, default mounting directory of optical drive and floppy drive
-etc, storage of configuration related files
-Var, storing frequently changing files, such as sock files for network connections
-Boot, storing related files for boot system boot
-usr, install a default directory of software, equivalent to Windows program files

Here are some of the more common commands and how to use them:

pwd, showing which path is currently under

User Management for Linux

useradd user name, adding user

"Case" Useradd xiaoming

passwd user name, set password for new user

"Case" passwd xiaoming, change Xiao Ming's password

Userdel user name, delete user

"Case" Userdel xiaoming, delete user but save user home directory
"Case" userdel‐xiaoming, delete user and user home directory

logout, current user launches

Who am Iand who is the current user


CDs, changing directories

ls, listing files and directories

Ls‐a, displaying all files in the directory, including hidden files

ls‐l, displaying long column table style

mkdir, create a directory

rmdir, delete empty directory

Touch, create an empty file

cp, copy command

"Case" Cp‐r dir1 dir2, recursive replication command (copy subdirectory information)

mv, moving files and changing file names

rm, deleting files and directories

RM‐RF *, delete all contents, include Directories and files, R indicates recursion, F indicates coercion

Ln, a symbolic connection, similar to creating a shortcut to a file

ln‐s Source target

"Case" Ln‐s/etc/inittab Inittab,inittab point to the actual file/etc/inittab Inittab

More, show the contents of the file with pagination, CTRL + PAGE UP turn, Sky grid down

less, displaying file content with pagination

grep, querying content in text

The "case" assumes that there is a Hello keyword in a file test.cpp, which can be found using the grep name command, and the grep n "Hello" test.cpp,n indicates that it appears in the nth row

|, Pipeline command, in Linux and UNIX systems, give the results of the previous command to the following command processing

"Case" ls‐l/etc/| More

Man [command], assistance, similar to help in DOS


Find, search for files and directories. In Linux, because file systems are made up of hierarchical structures, it is not easy to find specific files and directories throughout the system. and the "Find" command solves the problem.

searches for and displays files and directories of the specified name in a specific directory

"case" found/-name man: means to search for a file or directory that has a name of man from the root directory

Search for files or directories that have been accessed/changed over a period of time

"Case" find/home-amin-10: Files or directories accessed within 10 minutes
"Case" find/home-atime-10: Files or directories accessed within 10 hours
"Case" find/home-cmin-10: Files or directories that have changed in 10 minutes
"Case" Find/home-ctime + 10: A file or directory that was changed 10 hours ago

Search for files of a specified size

"Case" find/home-size +10k: means to find files with a size of 10k in the/home directory

REDIRECT command

ls-l > A.txt, the contents of the list are written to the file A.txt (overwrite write)

Ls-al >> Aa.txt, the contents of the list are appended to the end of the file Aa.txt

Enter information from the file: Database_program < Database_data

En, view environment variables

Compression and decompression

Handling. zip files in zip and unzip

Basic usage of Zip command

Zip File.zip *:zip After the compressed file name, then enter the file to compress after it

Automatically delete the original file after compression

"Case" Zip m file.zip to.txt: Compress to.txt file into File.zip file, To.txt automatically delete

To compress subdirectories together

"Case" zip‐r file.zip *: Compressing subdirectories in the current directory

Ignore contents of subdirectories

"Case" zip‐j file.zip *

Remove compressed or unnecessarily compressed files

"Cases" zip‐n. mpg:. jpg:. gif: The first file should be separated by ":" In the middle.

Compress a file after a day

"Case" Zip‐t 080915 file.zip: File compression after August 9, 2015 in the current directory

Do not compress the original file of the linked file

"Case" Zip‐y file.zip *

Compression rate problem, -1~-9, which-9 of the highest compression rate

"Case" zip-9 file.zip *

Exclude files that do not need to be compressed

Case Zip File.zip *-x file2.txt: Exclude file2.txt files from the current directory when compacting

Unzip the. zip file with the unzip command

Extract files directly

"Case" unzip File.zip

Exclude files that do not need to be decompressed

"Case" unzip file.zip‐x File2: Other files are uncompressed except file2 files

Viewing the contents of a compressed package

Case Unzip‐z File.zip: View the contents of a File.zip package, or use "-l" "V" to view the contents of a compressed package

Processing. gz files with gzip and gunzip


Each user in Linux must belong to a group and not be independent of the group. Each file in Linux has the concept of owner, group, and other group .

1 Owner: Typically the creator of the file, who creates the file, becomes the owner of the file naturally. You can see the owner of the file with the Ls‐ahl command. You can also modify the owner of a file by using the Chown username file name.

2 File group: When a user creates a file, the group that contains the file is the group that the user is in, the Ls‐ahl command can see all of the files ' groups, or you can use the CHGRP group name file name to modify the group where the file resides.

3 other groups: except the owner of the file and the users of the group, other users of the system are other groups of files.


file Permissions

the contents of the ls-l are shown below:

-rwxrw-r‐-1 root root 1213 Aug 9 09:39 ABC

10 characters to determine what different users can do with a file

The first character represents a file (-), a table of contents (d), a link (l)

The remaining characters are in each of 3 groups (RWX), read (R), write (W), execute (x)

First set of rwx: File owner's permissions are read, write, and execute

Second group rw-: the permissions of the same group of users as the file owner are read, write, but not executed

Group III r--: The permissions of other users who are not in the same group as the file owner are read and write-unable and executed

The number can also be expressed as: R=4,w=2,x=1 so rwx=4+2+1=7

1 indicates the number of files connected

Root indicates that the user

The second root represents the group where the user is located

1213 indicates file size (bytes)

Aug 9 09:39 Indicates the date of last modification

ABC represents filename

commands to change permissions

chmod Change permissions on files or directories

chmod 755 ABC: Assigning ABC permissions Rwxr-xr-x

chmod U=RWX,G=RX,O=RX ABC: IBID. u= user Rights, g= group permissions, o= different groups of other user rights

chmod u-x,g+w ABC: To remove the permissions that the user performs for ABC, and to increase the group write permissions

chmod a+r ABC: Add read permissions to all users


Change owner (chown) and user Group (CHGRP) commands

Chown xiaoming ABC: Change the owner of ABC to Xiaoming

CHGRP Root ABC: Change the group that ABC belongs to root

Chown root/ABC: Change ABC the owner of this directory is root

Chown‐r root/abc: Changes to ABC this directory and all of the files and directories under it are owned by root


change user Group

When adding a user, you can specify which group to add the user to, as well as the admin rights of ROOT to change the group of a user

USERMOD‐G Group name User name

You can change the initial directory of the user login by using the Usermod‐d directory name.


Linux Partition detailed

The partitions of the hard disk are mainly divided into basic partitions (Primary portion) and extended partitions (Extension portion). For a single hard drive, the number of basic partitions and extended partitions cannot be greater than 4, and basic partitions can be used immediately but not partitioned. The extended partition must be partitioned again before it can be used, meaning it must be partitioned two times. So what's the point of having an extended partition? It is the logical partition (Logical portion), and the logical partition is not limited in number

For Windows users, several partitions have several drives, and each partition gets an alphabetic identifier, which can then be used to specify the files and directories on the partition. Their file structure is independent and very well understood. But for these users to start Linux, it is a bit annoying. Because for Linux users, regardless of the number of partitions, to which directory to use, it ultimately has only a root directory, a separate and unique file structure . Each partition in Linux is used to make up the entire file system. Because it employs a processing method called "load" , its entire file system contains a complete set of files and directories, and links a partition to a directory. The partition to be loaded will make its storage available in this directory.

Here are a few important commands

mount Command

Mount [-parameters] [device name] [Mount Point]

Uninstall Command

Umount [Mount Point]

View disk usage

DF [-parameters]

Df-h

Df‐l

DF [Directory full path] to see which partition a directory is in

View Linux system partition specifics

Fdisk‐l


Shell Programming

In fact, the interactive interpretation and execution of user input commands as an imperative language is only one aspect of shell functionality. The shell can also be used for programming. It provides a means to define variables and parameters and a rich program control structure. Using shell programming resembles a batch file in DOS, called shell script, or shell program or shell command file.

Shell script file:

is a text file

A collection of commands

have permission to execute

Execution mode (./filename)

Export can be temporarily added to a system path, such as export path= $PATH home/bin:/root/test/t1, output environment path, referencing the original value $path, $HOME represents the work home directory,: is the path separator

Shell wildcard characters

* represents multiple letters or numbers

? Represents a letter or a number

"Case" ls * ls a? LS f080[1-6].tif

escape character \

"Case" ls/mnt/win1/my\documents

single quotes: Do not process any variables and commands

"Case" Echo ' Welcome $NAME, the date is date '

double quotes: Handling variables but not processing commands

"Case" echo "Welcome $NAME, the date is date"

Inverted quotation marks: use each word in quotation marks as a command, and if it is a variable, evaluate it first and then treat it as a command

"Case" Echo Welcome $NAME, the date is ' date '


Review History

History, view history of used commands

History 5, this description shows the last 5 commands used

!5, this description executes the command with history number 5

!ls, this note executes the last command that starts with "LS"


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.