Linux Command Encyclopedia __linux

Source: Internet
Author: User
Tags chmod mkdir parent directory zip extension

If a user has a detailed understanding of a command, you can use the Man command. For example, to understand the details of the LS command, the command line writing format is as follows:

[Root @teacherroot]# Mans ls

Note: Commands are case-sensitive in Linux, such as LS and LS are different.

1.4.1 basic commands for file and directory operations

1, pwd command

The pwd command represents "Print working directory" (Print working directory). When you type PWD, you are asking your Linux system to display your current position. For example:

[root@teacherapache]# pwd

/tmp/apache

Indicates that you are currently in the/tmp/apache directory.

2. CD command

cd command to change the working directory. For example:

Command

function

CD ~

Will send you back to your login directory.

CD/

To take you to the root of the entire system.

Cd/root

Take you to the root user's home directory; You must be the root user to access the directory

Cd/home

Take you to the home directory where the user's login directory is usually stored

Cd..

Move up the level of a directory

Cd/dir1/subdirfoo

No matter which directory you are in, this absolute path will take you directly to the Subdirfoo, the Dir1 subdirectory.

Cd.. /.. /dir3/dir2

This relative path will move you up two levels, switch to the root directory, then go to dir3 and go to the DIR2 directory.

3, ls command

Use the LS command to display the contents of your current directory. The LS command has many options available. To see all the options for the LS command, you can read the instructions page by typing man ls at the shell prompt. The following is a short list of some common options used with LS. -a-(All). Enumerates all the files in the directory, including hidden files (. filename). At the beginning of this list. And. In turn, the parent directory and your current directory. -L-Length (long). Enumerates the details of the contents of the directory, including permissions (schema), owner, group, size, date created, whether the file is a link to other parts of the system, and the link's point. -f-file type. Add a symbol after each of the enumerated items. These symbols include:/indicate a directory; @ indicates a symbolic link to another file; * indicates an executable file. -r-reverse (reverse). Enumerates the contents of a directory from behind. -r-recursion (Recursive). This option recursively enumerates the contents of all directories (under the current directory). -s-(size). Sort by file size

4, locate command

Sometimes you know that a file or directory exists, but you don't know where to find it. You can use the Locate command to search for files or directories.

Using the Locate command, you will see each directory or file that includes the search criteria. For example, if you want to search for files with the word finger in all names, type:

Locate finger

The locate command uses a database to locate files and directories with the word finger in a file or directory name. The search results may include a file called Finger.txt, a file called Pointerfinger.txt, a directory named Fingerthumbnails, and so on.

5. Clear command

The clear command clears the terminal window.

6, Cat command

Cat is a shorthand for concatenate (chain), which means merging files. This command can display the contents of a file (often used with more), or combine multiple files into one file.

7. Head command

You can use the Head command to see the beginning of a file. This order is:

Head<filename>

The head is a useful command, but because it is limited to the first few lines of the file, you can't see how long the file actually is. By default, you can only read the first 10 lines of the file. You can change the number of rows to display by specifying a number option, as shown in the following command:

Head-20<filename>

8, tail command

The opposite of the head command is the tail command. Using the tail command, you can view the 10 lines at the end of the file. This helps to view the last ten lines of the log file to read important system messages. You can also use tail to observe the process of log files being updated. With the-f option, tail automatically displays new messages from the open file to the screen in real time. For example, to instantly observe/var/log/messages changes, type the following command at the shell prompt as the root user:

Tail-f/var/log/messages

9. grep command

The grep command is useful for finding the specified string in a file. For example, if you want to find every place in the Sneakers.txt file that mentions "coffee," you can type:

grep Coffee Sneakers.txt

You will see each line with "coffee" in the file.

10, chmod command

The chmod command is used to change the access rights of a file or directory.

Let's take a look at this document first. At the shell prompt, type:

Ls-lsneakers.txt

The previous command shows this file information:

-rw-rw-r--1test Test 39 March 12:04 Sneakers.txt

A lot of details are provided here. You can see who can read (R) and write (w) files, and who created the file (test), where the owner's group (test) is located. The information on the right side of the group includes the file size, the date and time created, and the file name.

The first column shows the current permission; it has 10 bits. The first digit represents the file type. The remaining nine bits are actually three sets of permissions for three different groups of users.

The three groups are: The owner of the file, the group to which the file belongs, and "Others", which are not previously included in the user and group.

-(rw-) (rw-) (r--) 1 Test

| | | |

Type owner Group Others

The first project specifies the file type, and it can display several of the following:

D-Directory

-(stub)-Regular files (not directories or links)

L-a symbolic link to another program or file that is located elsewhere on the system

In the three groups after the first project, you can see the following types:

R-Files can be read

W files can be written

X-Files can be executed (if it is a program)

When you see a dash ("-") in the owner, group, or other person, this means that the corresponding permission has not been granted. Can see the following sentence

-rw-rw-r--1test Test 39 March 12:04 Sneakers.txt

The owner of the file (in this case, test) has permission to read and write to the file. The group test also has permission to read and write Sneakers.txt, and the other groups do not have any permissions. It is not a program, so neither the owner nor the group has permission to execute it.

Next we use chmod to change the permissions of the file, type the following command:

chmod o+wsneakers.txt

The O+w command tells the system that you want to write files to other people sneakers.txt permissions. To view the results, list the details of the file again. Now, this file looks like the following output:

-rw-rw-rw-1test Test 39 March 12:04 Sneakers.txt

Now, everyone can read and write to this file.

To remove read and write permissions from the Sneakers.txt, use the chmod command to suppress both read and write permissions.

chmod go-rwsneakers.txt

By typing GO-RW, you are telling the system to delete the read and write permissions of the group and other people in the file sneakers.txt. The result is similar to the following output:

-RW-------1test Test 39 March 12:04 Sneakers.txt

When you want to use the chmod command to change permissions, remember them as shorthand symbols, because all you really have to do is memorize a few symbols.

The following is a list of shorthand notation meanings:

Identity

U-owned file user (owner)

Group of G-Owners

o Other person (not the owner or owner group)

A-everyone or all (U, G, and O)

Permissions

R-Read Right

W Write Right

X Executive Power

Action

+-Add Permissions

--Delete permissions

=-makes it a unique privilege

Alternatively, you can change permissions by using numbers.

Each permission setting can be represented by a numeric value:

R = 4

W = 2

x = 1

-= 0

When these values are added together, the sum is used to set up specific permissions. For example, if you want to have permission to read and write, you will get a sum of 6, 4 (read) + 2 (write) = 6.

The digital permissions for the Sneakers.txt file are set as follows:

-(rw-) (rw-) (r--)

| | |

4+2+0 4+2+0 4+0+0

The sum of the owners is 6, the sum of the groups is 6, and the sum of the others is 4. This permission setting is read as 664.

If you want to change the permissions of the Sneakers.txt file, so that the people in your group do not have write rights, but can still read the file, subtract 2 from this set of numbers to remove the Write permission.

Then this set of values becomes 644.

To implement these new settings, type:

chmod 644 Sneakers.txt

Now, enumerate this file to check for changes. Type:

Ls-l Sneakers.txt

The output should be:

-rw-r--r--1 Test test 39 March 12:04 Sneakers.txt

Now, the group and others do not have the right to write to the file sneakers.txt.

Here is a list of some common settings, values, and their meanings:

-RW-------(600)-only the owner has read and write permissions.

-rw-r--r--(644)-only the owner has read and write permission, and the group and others have only read permission.

-RWX------(700)-only the owner has permission to read, write, and execute.

-rwxr-xr-x (755)-The owner has read, write, and execute permissions, and the group and others have only read and execute permissions.

-rwx--x--x (711)-The owner has read, write, and execute permissions; the group and others only execute permissions.

-rw-rw-rw-(666)-Everyone is able to read and write files. (please use these permissions carefully.) )

-RWXRWXRWX (777)-everyone can read, write, and execute. (Again, this permission setting can be dangerous.) )

Some common settings for the directory are listed below:

DRWX------(700)-only the owner can read and write in the directory.

Drwxr-xr-x (755)-Everyone can read the directory, but the content can only be changed by the owner.

11, CP Command

The CP (copy) command can copy files or directories to other directories, just as the copy command in DOS is very powerful. When using the CP command, you only need to specify the source file name and destination file name or destination directory. Format:

CP < source >< target >

12, MV Command

To move the file, use the MV command. Common options for MV include:

· -i-interaction. If the file you select will overwrite the existing file in the target, it will prompt you. This is a practical option because, like the-i option in CP, it gives you an opportunity to confirm the replacement of the saved file.

· -f-coercion. It goes beyond the interactive mode and moves the file without prompting. Unless you know what you're doing, this option is dangerous. Use this option carefully before you have confidence in your system.

· -v-details. Displays the progress of the file's movement.

If you want to move the file from your home directory to another existing directory, type the following command (you need to be in your home directory):

Mvsneakers.txt Tigger

Another approach is to use the same command, but use an absolute path, such as:

Mvsneakers.txt/home/newuser/sneakers.txt/home/newuser/tigger

13. mkdir Command

The mkdir (make directory) command is used to create a directory. For example, to establish a datal subdirectory in the system:

[Root@teachertmp] #mkdir datal

14. RM Command

It is easy to create a file in Liunx so that there are any files that are at any time in the system, and users can delete them with the RM command. This command deletes the file or directory itself from the directory, and for the linked file, only the link is deleted and the original file remains unchanged. Options for deleting files and directories include:

· -i-interaction. Prompt you to confirm the deletion. This option will help you avoid accidentally deleting files.

· -f-coercion. Instead of interactive mode, delete files without prompting. Unless you know what you're doing, it's not always advisable to use this option.

· -v-details. Displays the progress of the file deletion.

· -r-recursion. A directory and all of its files and subdirectories will be deleted.

To delete a file piglet.txt using the RM command, type:

RM piglet.txt

Another command to delete a directory that is more secure than using RM is the RMDIR command. This command does not allow you to use recursive deletion, so you cannot delete the directory containing the files.

1.4.2 file compression and archive-related commands

1. compress,uncompress

This command is used to compress or decompress data.

2. Gzip,gunzip

This command is used to compress or extract files, where gzip is a compression and decompression command that is used frequently in Linux systems and is easy to use.

3. rpm

The RPM command is used to start the RPM package management operation.

4. Tar

The tar command is used to start the File Packager program.

5. Unzip

This command is used to decompress files with the. zip extension, that is, you can unzip windows with WinZip compressed files under Linux.

6. Zip

The zip command is used to package and compress files.

1.4.3 File system Commands

1.dd

The DD command is used to copy a file.

2.edquota

This command can be used to set the disk space limit for users and groups of users.

3. Fdisk

This command is used to perform disk partitions under Linux.

4.MKFS

This command is used to build a Linux file system.

5.mount

This command is used to assemble a file system.

6. Quota

This command restricts and displays the disk space available to the user.

1.4.4 commands related to system administration

1.free

This command is used to view the current system memory usage, which can display the remaining and used physical memory, swap memory, shared memory, and kernel buffers in the system.

2. Shutdown

This command is used to shut down or enter a single maintenance mode.

3.data

The data command can display the date and time of the current system. The clock command can also be used to display the current date and time of the system (by default, ordinary users cannot perform the clock command and must log on with the root account). For example:

[Root@teacherroot]$ Date

Monday June 09:18:37 CST 2003 Standard Time (Standard)

[Root@teacherroot]$ Clock

June 23, 2003 Monday 09:18 43 sec -0.832323 seconds

4.cal

This command displays a monthly calendar or calendar in your computer. For example:

[root@teacherroot]# Cal

June 2003

Day 123456

1 2 3 4 5 6 7

8 9 10 11 1213 14

15 16 17 1819 20 21

22 23 24 2526 27 28

29 30

[root@teacherroot]# cal–y parameter y display Almanac

5. Write

This command is used to send a message to a user in the system. If the user wants to exit the information sending status, press the combination key CTRL + C. For example:

[root@teacheretc]# Write Root

Message Fromroot@teacheron pts/0 at 08:50 ...

Whar are youdoing?

Whar are youdoing?

Eof

1.4.5 User Management Commands

1.groupadd

This command is used to create a new user group.

2. Groupmod

This command is used to modify the properties of a group.

3. Groups

This command is used to display the group where the current user is located.

4.passwd

The passwd (password) command allows the user to modify the password for the account. In general, there are several scenarios in which an account password failure is set: The password is too simple, the password is too short, and the characters in the password are mostly the same. For example:

[root@teacherroot]$ passwd

Changingpassword for user zjz.

Changingpassword for ZJZ

(current) UNIX Password:

New Password:

Badpassword:it ' s WAY too Short

New Password:

Badpassword:is too simple

New Password:

Badpassword:it does not contain enough different characters

Retype NewPassword:

Passwd:allauthentication Tokens updated successfully.

5.su

This command is very important to enable a general user to have Superuser or other user privileges, or to enable Superuser to do something as a general user. However, a general user must have the password of a superuser or another user when using this command. If you want to exit the current user's login, you can enter exit.

6.useradd

This command is the quickest and easiest way to create a user account.

7. Userdel

This command is used to delete user accounts and their associated files.

8. W.H.O.

This command lets you see which users are logged on to the current computer, for example:

[Root@teacherroot]$ Who

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.