Common Linux commands (version 2) and common linux commands
Shell application skills
TIPS:
1. Command completion function: <Tab> key
2. Clear screen: Ctrl + l
3. Delete all content before the cursor: Ctrl + u
4. Command history: history
At this time :! The command number listed by history to execute the command.
Example :! 188
In addition, you can press the arrow keys "dig" and "dig" to find commands previously executed.
Important skills:
1. Command alias:
Purpose: Make operations easier, and make commands easier to remember.
Alias: displays the alias defined by the system.
Define alias:
Alias copy = cp
Alias drm = "rm-rf" # defines the alias combination, which must be caused ""
Delete alias:
Unalias copy
Appendix-in most cases, these aliases are not set in UNIX systems!
2. Input/Output redirection:
0 (STDIN)-standard input, keyboard;
1 (STDOUT)-standard output, display;
2 (STDERR)-standard error output, display.
> Or> output redirection
Ls-l/tmp> test.txt // clear the original file content
Ls-l/tmp> test.txt // append
<Input redirection
Wall <test.txt // input redirection
2> error output redirection
Cp-R/usr/backup/usr. bak 2>/bak. error
3. Pipeline: Send the output of one command to another as the input of another command.
Ls-l/etc | more
Ls-l/etc | grep init # grep init/etc/inittab
Ls-l/etc | grep init | wc-l # The wc command is a counter.
4. Command Connector
1); # use; the separated commands are executed in sequence
Pwd; ls; date
2 )&&
Command1 & command2
Executed successfully
Failed to execute
# There is a logic and relationship between the execution of commands before and after the command is executed. Only after the successful execution of the command before and after the command is executed will the command be executed.
E. g.
Write Mary
Ls & pwd
Lskkk & pwd
3) |
Command1 | command2
Execute not run
Do not execute
# There is a logic or relationship between the execution of the preceding and following commands. Only after the execution of the preceding command fails is the execution of the preceding command.
E. g.
Write Mary
Ls | pwd
Lskkk | pwd
For details, refer to another series of blogs-four days proficient in Shell programming series:
Http://blog.csdn.net/zjf280441589/article/details/17455515
Http://blog.csdn.net/zjf280441589/article/details/17467069
Http://blog.csdn.net/zjf280441589/article/details/17487351
Http://blog.csdn.net/zjf280441589/article/details/17503985
5. Command replacement character
Command 1 'COMMAND 2' # Use the output of command 2 as the parameter of command 1 to simplify the operation.
E. g. ll 'which touch' # production view touch command details
Appendix-cat/etc/shells # list all shells supported by the current system
In Linux, bash/bin/bash is used by default.
Older UNIX bin/sh
Appendix-wc
Wc-l msg # check the number of lines in the msg File
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>