1. Basic Linux Command Learning 01

Source: Internet
Author: User
Tags clear screen new set parent directory switches file transfer protocol

=============================================================================
Unix/linux's most important application areas are the basic server applications,
such as DNS server (domain Name System), DHCP server (Dynamic Host Configuration Protocol), Web server (Web server), FTP server (File Transfer Protocol), firewall, etc.

The X window System is not a necessary component of the Unix/linux operating system, but an optional application component.
The plain character interface is also called text mode
=============================================================================
-RWXRWXRWX all users can read and write executable
-rwx------files belong to the user can read and write execution, but other users are not read and write execution
-rwxrwx---Files belong to users and users within the group can read and write execution, but other users are not read and write execution
----------All users are not read and write executable
The first digit indicates the meaning of the file:
"-" represents a regular file, "D" means a directory, "C" means a character device file, "B" represents a block device file; "S" represents a pipe file; "L" represents a linked file.

File access permissions: From left to right, each 3 bits is a group, which in turn represents the access rights of the file owner, the same group of users, and other users.
Typically, the file has 3 permissions, "R" means read-only, "w" means writable; "X" means executable; "-" means not set.
=============================================================================
A Linux file or directory name can be up to 265 characters long. Represents the current directory,.. Represents the previous level of the directory,
Files starting with. Are hidden files and need to be displayed with the-a parameter
-a displays all subdirectories and files in the specified directory, including hidden files
-l display file details in long format
They can also be used in combination, for example: Ls-al
=============================================================================
* represents all characters in the file name
? represents any character in a file name

LS d* find all files that start with the letter D
LS a*b find all files that begin with the letter A and end with B

LS a? Find a start, file name is only 2 letters, the second character any file name
LS [abc]* Find A or B or C, followed by any file name
LS [a-f]* find any file name starting from A to F
LS [1-7]* find any file name starting from 1 to 7

Note: When "-" is outside the square brackets, or "?" and "*" in square brackets without using the escape character, you have lost the role of a wildcard. As follows:
LS [*] to find the file name starting with *
LS a-f find file named A-f

If you want to use wildcards as normal characters, you can precede them with the escape character \ below:
LS \*1 find this file name
=============================================================================
REDIRECT Command
> Output redirection: Redirect The execution result of one command to another file
>> Additional output redirection
< input redirection
ls > A.txt Store the results of the LS display into the file a.txt
LS >> a.txt, Chase-weighted orientation, if a.txt already has content, will not overwrite existing content, but append to A.txt
=============================================================================
More features are: Display file content, when the file content too much, there will be a quick scrolling screen, so that users can not see the contents of the file,
At this point, you can use the more command, only one page at a time, press the SPACEBAR to display the next page, press the Q key to exit the display, press the H key to get help.
For example: if there is a special number of files in a directory, now to put all the file name display, there will be a scrolling screen, how to solve it?
A: You can use a stupid method to redirect the directory to a file, and use more to display the contents of the file.
But, more cumbersome and verbose, we can do it all at once, using | Pipe character.

| Pipe break: The output of one command can be piped as input to another command
ls | More the results of the LS display with a split screen display, that is, the output of LS as more input to use
=============================================================================
CD ABC enters the ABC subdirectory from the current directory
Cd.. Returns to the previous level directory, the parent directory
Cd. Returns the current directory (the same as no action) but also makes sense (as later studies will find)
The CD can be followed by an absolute path, or with a relative path. If you omit the directory, the default is to switch to the current user's home directory.
=============================================================================
View current directory commands
PWD Displays the current path, using the PWD command to display the current working directory, the command is simple, enter PWD directly, without parameters
=============================================================================
MKDIR ABC new set up a folder, named ABC
RMDIR ABC Delete folder Abc,rmdir can only delete empty directory, if there are files in the directory, then delete failed
RM a.txt Deleting files A.txt
=============================================================================
ln source File Link file
ln A.txt A creates a linked file named A, linked to a.txt, creating a hard link
Ln-s Source File Link file
Ln-s a.txt b Creates a link file named B, linked to A.txt, creates a soft link
Hard links will take up disk space, soft links will not, if the target file does not exist, then the hard link file can also be accessed, but the soft link is not
=============================================================================
Cal View current Calendar
Date Display or set time
Date ' +%y,%m,%d,%h,%m,%s ' year, month, day, time, minute, second
=============================================================================
Cat This command can be used to view or merge file contents
Cat A.txt Viewing the contents of a file a.txt, but does not automatically split the screen
Cat A1.txt a2.txt > A3.txt Merge the contents of A1.txt a2.txt into A3.txt
=============================================================================
grep Hello a.txt Find string Hello in a.txt (specify file search for specified character content)
grep printf stdio.h Find rows in stdio.h that contain printf
Grep-v printf stdio.h to find rows in stdio.h that do not contain printf
Grep-n printf stdio.h Find all lines and line numbers in stdio.h that contain printf
Grep-i printf stdio.h finds rows in stdio.h that contain printf (ignores case-finding)
grep ' ^a ' stdio.h find lines starting with a in the stdio.h file
grep ' a$ ' stdio.h find line ending with a in stdio.h file
grep ' ^a.b ' stdio.h find lines that start with a, any character, and B in a stdio.h file
=============================================================================
Wc-l A1.txt Calculating the number of rows a.txt a file
Wc-w A1.txt Calculate the number of words a.txt a file
Wc-c A1.txt Calculating the number of characters a.txt a file
=============================================================================
Find./-name 1.txt Search All subdirectories starting from the current directory, with the name 1.txt
Find/-name 1.txt Search All subdirectories starting from the root directory, with the name 1.txt
=============================================================================
Rm-i 1.txt asks whether to delete files 1.txt
Rm-f 1.txt forcibly delete files 1.txt, ignoring nonexistent files, without prompting
Rm-r 1.txt recursively deletes the contents of the directory
RM-RF * Force deletion of all files and subdirectories in the current directory
=============================================================================
CP [parameter] source file or directory destination file or directory
CP./2/a.txt./1/a.txt copy the current directory under 2 directory a.txt to the 1 directory under the current directory
mv./2/a.txt./1/a.txt to move a.txt from the current directory under 2 directory to the current directory under 1 directory
MV 123.txt 1.txt renamed 123.txt to 1.txt (file rename)
=============================================================================
Files under Windows generally have extensions, but many files under Linux do not have extensions, that is, Linux does not rely on extensions to differentiate between file types
All file types under Windows are implemented by extension of the file
The Linux extension is just a name and does not represent a file type.
-----------------------------------------------------------------------------
File 1.exe The command gets the type
=============================================================================
Clearlinux's clear screen
Clswindows's clear screen
=============================================================================
Ps-a shows all processes on the terminal, including the processes of other users
Ps-u Show the detailed status of the process
Ps-x shows no control of the terminal process
Ps-w display widening to show more information
Ps-r only the running processes are displayed
Ps-aux View all the processes, including the front-end background. Note: In the parameters-can have, also can not OH
=============================================================================
The top command is used to dynamically display a running process. The top command is able to update the display information at a specified time interval after it is run.
You can specify a time interval for displaying information updates by adding-D <interval> when using the top command.
=============================================================================
Keil Port number forcibly terminating a program
=============================================================================
Study questions: How to display the content as I want it.
Multiple commands combined (TIPS)
Ls-l | grep ' ^d ' only displays the directory.
Ls-l | grep ' ^-' only shows the files.
=============================================================================
WhoAmI This command to view the user name of the current system current account
Reasons for using this command:
Because system administrators often need to log on to the system with multiple identities (because Linux is a multiuser system)
For example, you typically log on to the system with a normal user, and then manage the system by switching to the root identity with the SU command.
At this point, you can use WhoAmI to view the current user's identity
----------------------------------------
Who command
This command is used to view the current user information for all logged-on systems
----------------------------------------
W command
The command can also view user information logged on to the current system.
The W command is more powerful than the WHO command, and it can not only show which users are currently logged on to the system,
You can also show what these users are doing and give more detailed and scientific statistical data.
=============================================================================
TAR-CVF A.tar A package directory A as a file A.tar, without compression (note: "-" can be used before its parameters, or it may not be used.) )
TAR-XVF A.tar to restore A.tar
Tar-t A.tar lists the files included in the A.tar
=============================================================================
Gzip A.tar compress A.tar to get a.tar.gz (this compression ratio is very high)
Gzid-d a.tar.gz extract, Get A.tar
TAR-XVF A.tar will A.tar restore, get inside the file
=============================================================================
Pack with tar first, then compress with gzip
Unzip with Gzip, then extract the file with tar
=============================================================================
How can I execute multiple programs at the same time on the command line? How do you do it? (that is, the background job method)
If the program wants to be executed in the background in the first place, use the command & for example: VI &, Top & (but note that top & will be terminated)
Law two: If the program is already in operation, first use CTRL + Z to move the program into the background, and then use jobs to view the program running in the background,
Then go back to the previous program by FG number.
=============================================================================
Man in the general use of the Man command, you do not have to carry the option, you can directly query the command Help manual to get the exact use of query commands
=============================================================================
Reboot for restarting the operating system
Init 6 for restarting the operating system

Shutdown–r now restarts immediately, but with hints
Shutdown–h now shuts down, but with hints

Init 0 shuts down immediately, but without prompting

Init 3 Switch to command-line mode
Init 5 switch to x Windows mode
=============================================================================
The DF command detects a disk space occupancy and availability for a file system
The du command is used to count the amount of disk space that a directory or file occupies
The MKFS command is equivalent to a formatted command in the Dos/windows system for creating the specified file system
=============================================================================
Installing applications using RPM tools (combination of parameters) but different Linux have different methods of loading and unloading software
RPM-IVH the file name of the installation package to install
=============================================================================
In Unix/linux systems, each system must have an account, whether it is a native or remote login system,
and has different usage rights for different system resources.

Standard account is when the operating system is installed, automatically created by the user to launch the appropriate application, the super-users in the system to add ordinary users,
Cannot have the same name as a standard user already in the system.

In most versions of Unix/linux, it is not recommended to log into the system directly using the root account.

When a system administrator needs to switch from a normal user to a superuser, you can use the SU or Su-command and then enter the root account password instead of logging in again.
=============================================================================
There is a problem: Ubuntu installed under the default is not set root password, but switch to the root user when you need to provide the root password, how to solve it?
A: Execute command set root password: sudo passwd root after entering the password can be set to complete the root user password.
If you need to return to the original normal user account, enter the Exit command directly.
(Note: CentOS and Redhat have already set the root password for you when they are installed.)

If you want to enter another normal user account, you can add another account directly after the SU command, and then enter the password.

If the SU command does not carry a user name, the system defaults from when the user switches to the Superuser and prompts the user to enter the superuser password.

The

Su and su– commands differ in that Su-switching to the corresponding user automatically converts the current working directory to the home directory of the switched user.
=============================================================================
When you add a user or group, only the root user has this permission
=============================================================================
Add/Remove a group:
Groupadd ABC Add a group named ABC
Groupdel ABC to delete a group,
========================================================================= = = =
Add a user account:
-D means: Specify the user's home directory, what is the user home directory? Is the first time users log on the default directory
Linux home directory is generally set in the root directory of the home directory, this is not a system requirements, but a rule. (important)
-----------------------------------------------------------------------------
Requirements: Add a user named Aabb, Specify the user's home directory in/home/aabb, (note: The directory name and user name of the home directory are generally the same)
-m means that if the home directory specified by-D does not exist, the home directory is created automatically. Examples are as follows:
-----------------------------------------------------------------------------
useradd-d/home/aabb Aabb-m Add a user named Aabb
Userdel AABB will be AABB user Delete, note: Specify the user's home directory is still in Oh
userdel-r aabb Delete aabb users, and automatically delete the user's home directory

useradd-d/home/aabb AABB-M-G ABC add a user aabb, home directory in the/home/aabb directory, the user in group ABC

-G means: Specify the name of the group
-----------------------------------------------------------------------------
Note: You need to set a password after each user account is added
In Unix/linux, a superuser can use the passwd command to set or modify a user's password for a normal user.
Users can also use the command directly to modify their own passwords without having to use the user name after the command. The command is as follows:
passwd AABB Set password for user Aabb
=============================================================================
Switch User's commands
SU User name
Su-user name
SU does not add-, only switch users, but does not change the current directory
Su time plus-, switch user, while the current directory is switched to the target user's home directory
-----------------------------------------------------------------------------
If you use root su to another user, you do not need to enter a different user password to enter
However, if the normal user between SU (ie: switch), you must enter the password
Exit Login Exit
-----------------------------------------------------------------------------
If you want Su to root
Su Root, but can also omit root, direct su
Su only switches the user to root, does not change the current directory
Su-Switch user to root while changing the current directory to the root user's home directory
=============================================================================
useradd-d/home/aabb aabb-m Add a user aabb, the home directory in the/home/aabb directory, the user does not specify a group name
If you do not specify a group name when creating a user, the system creates a group name with the same user name and puts the user in this group
-----------------------------------------------------------------------------
Example: Login zhujy user-"Login aabbcc user-" Login root user
Only one user is logged out to delete this user, and a logged-in user cannot delete
-----------------------------------------------------------------------------
How do I know (or view) the users and groups of the system?
A: Log into the system with root and then go to the ETC directory under the root directory to view the contents of the shadow File: Cat Shadow and Cat passwd
-----------------------------------------------------------------------------
View the last time the user entered the System Status command
Regardless of which user is logged in from, the administrator can be identified by the last command, and whether someone logged on illegally
-----------------------------------------------------------------------------
Note: the command "LL" under Linux is an alias for "Ls-l". Aliases are equivalent to shortcuts in Windows. So the functions of "ll" and "ls-l" are the same.
So the difference between "ll" and "LS" is actually the difference between "LS" and "ls-l". "LS" is the file that displays the current directory, "Ls-l" is the file details displayed in the current directory.
=============================================================================

1. Basic Linux Command Learning 01

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.