Common Linux commands

Source: Internet
Author: User

Common Linux commands (BASICS)

1. Man provides help explanations for familiar or unfamiliar commands

For example: man ls, you can view the LS-related usage.

Note: Press Q or Ctrl + C to exit. in Linux, you can use Ctrl + C to terminate the current program.

2. ls view the directory or file owner * and list the files under any directory

Eg: ls/usr/man

Ls-l

A. D indicates the directory. If it is a "-", it indicates a file. If it is l, it indicates a connection file (link)

B. Permission for file or directory permission. Read (R), write (w), and run (x) respectively ).

3. Copy files using CP

Eg: CP filename1 filename2 // copy filename1 to filename2

CP 1.C netseek/2.c // copy 1.C to the netseek directory and name it 2.c.

4. rm delete files and directories

Eg: Rm 1.C // Delete the. c file.

5. Remove the directory or change the file name.

Eg: MV filename1 filename2 // rename filename1 to filename2

MV qib. tgz ../qib. tgz // move to the upper-level directory

6. Change the current directory pwd on CD to view the complete path of the current directory

Eg: Pwd // view the current directory path

CD netseek // enter the netseek directory

CD // exit the current directory

7. Cat, more command

Displays the content of a file. The two commands are different: cat prints the file content all the time, and more is displayed on the split screen.

For example; CAT> 1.C // You can paste the code into the. c file and press Ctrl + D to save the code.

Cat 1.C or more 1.C // you can view the content in it.

Gcc-O 1 1.C // compile 1.C into the. exe file. We can compile the Code with this command.

8. Modify the CHMOD command permission usage: chmod one-digit octal number filename.

Eg: chmod U + x filenmame // you only want to run the command for yourself.

// U indicates the file owner. G indicates the group of the file. O indicates others; r table readable; W table writable; X table can run

Chmod g + x filename // the same group of people to execute

9. Clear, date command

Clear: clear screen, equivalent to CLS in DOS; date: displays the current time.

10. mount a hardware device

Usage: Mount [parameter] device load point to be loaded

Eg: Mount/dev/CDROM

CD/mnt/CDROM // enter the CD directory

11. Su switches to another person's identity without logging out.

Usage: su-l user name (if the user name defaults, the user name is switched to the root state)

Eg: su-l netseek (switch to the netseek user and the user will be prompted to enter the password)

12. whoami, whereis, Which, ID

// Whoami: confirm your identity

// Whereis: queries the directory where the command is located and the directory where the help document is located

// Which: query the directory where the command is located (similar to whereis)

// ID: print your UID and GID. (UID: the unique ID of a user. GID: the unique ID of a user group. Each user can have only one unique UID and gid)

Eg: whoami // display your login user name

Whereis bin: the directory where the bin is located. The directory is/usr/local/bin.

Which Bin

13. grep, find

Grep: Text Content Search; find: file or directory name and permission owner matching search

Eg: grep success */* Find all files in the current directory that contain success characters

14. Kill can kill a running or DEST process.

Eg; PS ax

15. passwd can be used to set a password

16. commands used by the history user

Eg: History // displays the commands used by the user in the past.

17 .!! Execute the last command

18. mkdir command

Eg: mkdir netseek // create the netseek directory

19. Tar decompression command

Eg: tar-zxvf nmap-3.45.tgz // extract this to the nmap-3.45 directory

20. Finger allows users to query data of other users

Eg: Finger // view the user's usage information

Finger root // view the Root Information

Add User

Therefore, the process of creating a new account is dealing with these files, but do not be afraid,Use the useradd command to create a new account. The system will automatically perform operations with these files without manual changes, so you do not have to worry about errors.Haha.

Useradd syntax structure:

Finding a "man" is the most effective method in Linux. Let's take a look at the syntax structure of useradd, because I am using the fedora11 system, and its man statement uses Chinese directly, although it is easy to read, it is inevitable that there will be errors, but it is basically okay. Do not blame the following Chinese characters:

Useradd-Account creation or updating of new user information

Syntax useradd [-C comment] [-D home_dir]
[-E expire_date] [-F inactive_time]
[-G initial_group] [-G group [,...]
[-M [-K skeleton_dir] |-M] [-s shell]
[-U uid [-O] [-N] [-R] Username

Useradd-d [-G default_group] [-B default_home]
[-F default_inactive] [-e default_expire_date]
[-S default_shell]

First, let's take a look at this-D parameter. If this parameter is added, some default values for creating a new account are displayed when useradd is used, or the default value is updated by specifying the parameter content.Let's discuss it later.

It seems that there are no options for the-D parameter. The following is a brief description of the first and second items. I will not feel dizzy when I look at the example I gave the column. Haha.

Parameter Name Description
-U UID followed by a group of numbers. Specify a specific uid for this account.
-G The user group name that follows is the initial user group mentioned earlier.
The Group ID (GID) is placed in the fourth field of/etc/passwd.
-G The user group name that follows is the user group that this account can belong.
This parameter modifies the data in/etc/group.
-M Do not create a home directory.
-M You must create a home directory.
-C It is the user description in the Fifth Column of/etc/passwd. You can set it as needed.
-D Use the path specified after this parameter as the Home Directory of the new account, without using the default value.
-R The created account is a system account. The UID of this account is limited (/etc/login. defs)
-S Specify the default shell for the new account

Useradd example:

After talking about this for a long time, we also started to use the useradd command to create several accounts to improve our hands-on capabilities. In addition, let's make a demonstration. After all, we have a good idea. Oh, but I forgot what a great man said. Well.

# Create a new user chongpig by default without adding any parameters
[Simaopig @ xiaoxiaozi ~] $ Useradd chongpig
Bash:/usr/sbin/useradd: insufficient Permissions
[Simaopig @ xiaoxiaozi ~] $ Su
Password:
[Root @ xiaoxiaozi simaopig] # useradd chongpig
[Root @ xiaoxiaozi simaopig] # ls-L/home/
Total 24
Drwx ------. 4 chongpig 4096 07-21 21: 58 chongpig
Drwx ------. 2 root Root 16384 07-12 13: 08 lost + found
Drwxr-XR-X. 44 simaopig 4096 07-21 21: 21 simaopig

# Search for the Account chongpig in several files associated with the user

[Root @ xiaoxiaozi simaopig] # grep chongpig/etc/passwd/etc/shadow/etc/group
/Etc/passwd: chongpig: X: 501: 501:/home/chongpig:/bin/bash
/Etc/shadow: chongpig :!! : 14446: 0: 99999: 7 :::
/Etc/group: chongpig: X: 501: # create a new account simaopig2 and check that uid 888 does not exist. specify this account to simaopig2,
# And add it to the MySQL Group
[Root @ xiaoxiaozi simaopig] # grep 888/etc/passwd
[Root @ xiaoxiaozi simaopig] # useradd-u 888-G MySQL simaopig2
[Root @ xiaoxiaozi simaopig] # grep simaopig2/etc/passwd/etc/shadow/etc/group
/Etc/passwd: simaopig2: X: 888: 27:/home/simaopig2:/bin/bash
/Etc/shadow: simaopig2 :!! : 14446: 0: 99999: 7: # create a system account simaopig3 and check whether the system account is different.
[Root @ xiaoxiaozi simaopig] # useradd-r simaopig3
[Root @ xiaoxiaozi simaopig] # grep simaopig3/etc/passwd/etc/shadow/etc/group
/Etc/passwd: simaopig3: X: 490: 484:/home/simaopig3:/bin/bash
/Etc/shadow: simaopig3 :!! : 14446 ::::::
/Etc/group: simaopig3: X: 484:

The uid of the system account is different from the GID, And it corresponds to/etc/group.

Careful students will surely find that,The account created with useradd does not have the logon function because it cannot be logged on in the/etc/shadow password column! Start. So we will discuss how to change the password for users in Linux recently.

Useradd default value:

The above example shows that,In fact, the system has already standardized some parameters for new users. For example, I have not specified the user's home directory or the user's UID and GID, but the system will add them to the user, at the same time, the default shell is set to/bin/bash.And the useradd command must have the root permission. What is the default value of useradd when users are added?

The-D parameter of useradd above can display its default value. You can see that the value is exactly the same as that in the/etc/default/useradd file. OriginalIn Linux, when useradd is used to add users, some values in/etc/passwd will refer to the/etc/default/useradd file.. The file content is basically as follows:

# Useradd defaults File
# Default User Group
Group = 100
# Home Directory address
Home =/home
# Password Expiration grace time, corresponding to the seventh column of/etc/shadow
Inactive =-1
# Account expiration date, corresponding to the eighth column of/etc/shadow
Expire =
# Shell used by default
Shell =/bin/bash
# Reference files in the user's home directory (basically all of them are hidden files --> files starting)
SKEL =/etc/skel
# Create a user's mailbox
Create_mail_spool = Yes

Conclusion and comment:

This is a simple introduction. It is said that the adduser command can also be used to create an account in Linux. In fact, this is different from the useradd command. Because man adduser is used to access the introduction page of useradd. Of course there are simpler ways to create users through the graphic interface, but I will not teach you this.

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.