Common Linux commands (version 2) and common linux commands

Source: Internet
Author: User

Common Linux commands (version 2) and common linux commands
File Management commands

Not recommended: Follow books like command book!

There are about 200 Common commands.

 

File naming rules:

A) All characters except '/' are valid!

B) It is best not to use these characters.

1. space character, Tab character, return character

2. Connector

3. Special symbols: @ # $ & ()-and so on

C) Avoid using. As the start and use. As the start to indicate file hiding.

D) Note: It is case-sensitive, similar to C. Windows is not strictly differentiated.

E)linuxcan have no suffix, such as. EXE.

 

Command Format:

Command-option Parameter

Ls-la/etc

Note: 1. Multiple options can be written together. // or: ls-a-l/etc.

2. indicates the current directory.

.. Represents the parent directory // returns the parent directory: cd .. // contains spaces

3. The parameter indicates the operation object.

 

Note: different command storage directories determine different execution permissions:

Commands that can only be executed by the root user

/Sbin or/usr/sbin

Commands that can be executed by all users

/Bin or/usr/bin

[Most of them ...]

 

Appendix-Linux binary files refer to a wide range

Most of Linux's directory structures and commands come from abbreviations of English words...

Different file types have different colors, such as binary files: Black, true color; Directory: Blue

 

File Processing command:

1. ls [list]/bin/ls

Option:-aall

-L long # details

-D directory: view directory Properties

Part 1

Drwxr-xr-x

D: Mark the file type [d: directory;-: binary file; l: Soft link file link]

 

Rwxr-xr-x => rwx r-x: each three characters in length

R: read Permission

W: write Permission

X: execute execution permission

-: Indicates replacement. This permission is not granted.

 

There are also three types of users:

1. owner U: user

2. group G: group

3. others O: others

 

Part 2:

2-number of hard links

 

Part 3 and 4:

Root root4096

Directory size of the group to which the owner belongs: it does not accurately indicate the size of the Directory itself. # Many Linux directories are represented by data blocks, in 512 bytes, but its size can be adjusted according to the actual application. Data blocks can be understood as the smallest unit of data storage.

 

Part 5 and Part 6:

12-01 # Time of File Creation or last modification

 

Part 7

Bin: File Name

 

2. cd [change directory]

Cd [Directory]

E.g. ch // switch to the root directory

Cd .. // switch to the parent directory

3. pwd [print working directory]/bin/pwd

 

4. touch: create a file/bin/touch

Touch [file name]

 

5. mkdir [make directories]: create a directory.

Mkdir [directory name] // mkdir/test

// Mkdir test: create a directory in the current directory

 

6. cp [copy]: copy a file or directory/bin/cp

Syntax: cp-R [source file or directory] [destination Directory]

Cp-R [Copy Directory]

// If the file is copied,-R is not required and the number of files is not limited.

Appendix: Most of the files saved in the etc directory are configuration files.

Ctrl + c: Terminate the program running

7. mv [move]: move the file, rename it/bin/mv // similar to cut or rename

Mv [source file or directory] [target directory]

E. g. mv servers ser // rename

Mv/test/ser/tmp // move

Mv/test/testfile/tmp/file. test // move and rename

8. rm [remove]: delete a file/bin/rm

Rm-r [file or directory]

# Rm can only be used to delete files. to delete a directory, you must add-r, which is sometimes annoying...

# If you are sure that the file directory should be deleted, add-rf.

# If you do not want to bring up the confirmation information, add the-f option [force], which is not recommended, unlike UNIX

* 8.1rmdir is used to delete empty directories, which are not commonly used.

9. cat [concatenate and diplay files]/bin/cat # It is applicable to files whose content is not very long.

Cat [file name]

 

10. more/bin/more # display file content by PAGE

Command: f or Space Paging

Q or q quit

Enter next line

E. g. more/etc/servies

 

11. head/bin/head # view the first few lines of the file

Head-num [file name] // 10 rows by default if no number is added

E. g. head-20/etc/servirs

 

12. tail/bin/tail # view the last few lines of the file

Tail-num [file name]

-F // dynamically display the File Content

13. ln [link]:/bin/ln # generate a link file.

Syntax: generate a hard link directly without any options

Ln [source file] [target file]

-S [soft] is required to generate soft links.

Ls-s [source file] [target file]

E. g. ln-s/etc/issue. soft // soft link generated to the root directory

Note: the permissions of soft links are special. lrwxrwxrwx // All are rwx. He is very small, just a symbolic link, with an arrow pointing. The time value is different from the source file. It is similar to the shortcut in Windows.

Ln/etc/issue. hard // generate a hard link to the root directory

Note: Apart from different storage locations, all others are the same, such as the same size and time, but they are similar to copy but different. They are synchronously updated!

Therefore, cp has a-p option to save the time value. Otherwise, cp is similar to the newly generated file.

 

Different: a) the soft link of the deleted source file cannot be accessed, and the hard link can be accessed again, which is the same as the original source file.

B) hard links cannot be cross-file systems or partitions, but soft links do not matter!

 

Appendix-Why can he synchronize updates?

The ls-I // I [inode] I node is actually a digital identifier, because Linux does not recognize characters! Processing anything in Linux requires a digital ID. Therefore, all files must have an I node! However, the hard link has the same I node as the source file, and the kernel only knows the I node!


Common linux Commands include

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 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)

... The remaining full text>

Examples of common linux commands

There are a lot of commands, and I will forget what I learned at once. I can only accumulate them slowly. Many of them are generally not used. 1. File Viewing and connection commands
Connect the file together, use the ">" operation to combine several files into a new file, or use ">" to append the file to the end of the saved file.
Syntax:
Cat [parameter] filelist
-N or -- number: numbers the number of all output rows starting from 1
-B or -- number-nonblank: similar to n, but not numbered for empty rows
-S: two blank lines are displayed. replace them with one blank line.
-V: displays unprintable characters.
Filelist: an optional list used to combine files. 2. split-screen display command
Similar to cat, But it displays a page each time, displays the next page by space, exits by pressing the <q> key, and provides help information by pressing the Syntax
More [Options] <file>...
-Num: specifies the number of lines displayed per screen.
-D: a message is displayed below the screen.
-L: by default, more will suspend if it encounters a paper delivery character ^ L. You can use this option to cancel this function.
-F: calculate the actual number of rows.
-P: Not to display every page in a scroll mode, but to display the page first.
-S: two blank lines are displayed. replace them with one blank line.
-U: No underline is displayed.
+/<String>: Search for string in the file and display the content on the page where the string is located.
+/<Num>: displays data starting from row num.
File: the file to be displayed.
3. Display files by page. Similar to more, but can be moved before and after the file.
Syntax:
Less [parameter] File Name
-I: Case sensitivity is ignored during query.
-Num: specifies the number of lines displayed per page.
-P <string>: Search for the string in the file and display it from the first matching position.
-S: when the content of a column exceeds the width of the display screen, the excess part is directly truncated. By default, the excess part is folded back to display the commands for copying, deleting, and moving.
1. Copy an object.
Syntax:
Cp [Option] <source> <dest>
Cp [Option] <source>... <directory>
-R recursive copy directory
-F delete an existing target file and copy it again
-A tries its best to retain the structure and attributes of the source file in the backup.
2. Delete
Rm [Option] <name> ....
This command is used to delete specified files or directories one by one. By default, <name> is the file name. The rm command does not delete the directory. The directory can be deleted only when the-d option is specified.
Syntax:
-F force Delete, including read-only files, without prompting the user
-I prompt the user when deleting each file
-R recursively deletes contents in a directory to move or rename files and directories.
Syntax:
Target file of the mv [parameter] source file
-F forcibly overwrite existing files.
-I prompt the user before overwriting existing files.
-U does not overwrite the target file when the target file is earlier than the original file.
-V outputs relevant information when moving files. Create and delete directory commands
1. Create a directory command
Mkdir [parameter] Directory Name
-P if the parent directory does not exist, create all parent directories. 2. Delete the empty directory.
Syntax:
Rmdir [parameter] Directory List
-P indicates that after a specified directory is deleted, if the parent directory of the directory is empty, the switch working directory and display directory commands will be deleted.
1. Change the current working directory.
Syntax:
Cd directory name
If the directory name is not followed, the root directory of the user is returned. In addition, the user must have the permission to enter the directory. In addition, cd ~ Switch to your home directory. You can switch cd... to the upper directory 2 in front of the ticket to display the working or current directory name.
Pwd [parameter] 3. List contents in the directory.
Syntax:
Ls [parameter] [Directory]
-A shows all files, including hidden files... the remaining full text>
 

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.