Bash shell Command (1), bashshell command
Address:Http://www.cnblogs.com/archimedes/p/bash-shell1.html, Reprinted, please specify the source address.
Ls command
Ls is used to list the contents of a directory. It is one of the most commonly used commands. The format of ls is as follows:
Ls [Option] [directory name or file name]
Main parameters:
. Options Main Parameters
-A, -- all: Do not hide any items starting with the "." character.
-A, -- almost-all: list any projects except "." and.
-- Author: prints the author of each file.
-B, -- escape: an octal overflow sequence to indicate non-printable characters.
-- Block-size = size: the block is in the specified bytes.
-B, -- ignore-backups: do not list any ~ The project whose character ends.
-F: No sorting is performed. The-aU parameter takes effect and the-lst parameter is invalid.
-F, -- classify: add the file type indicator (*/= @ | one of them ).
-G: like-l, but do not list owner.
-G, -- no-group: inhibit display of group information.
-I, -- inode: List inode numbers of each file.
-I, -- ignore = style: do not print any items that match the Shell universal character.
-K: -- block-size = 1 K.
-L: Used to list information in a long format.
-L, -- dereference: when the file information of the symbolic link is displayed, the object indicated by the symbolic link is displayed, not the information of the symbolic link itself.
-M: All items are separated by commas (,) and the whole row width is filled.
-N, -- numeric-uid-gid: similar to-l, but list UID and GID.
-N, -- literal: List unprocessed project names, for example, not specially processed control characters.
-P, -- file-type: add the file type indicator (/= @ | one of them ).
-Q, -- quote-name: Enclose the project name in double quotation marks.
-R, -- reverse: in reverse order.
-R, -- recursive: Lists All Sub-directory layers at the same time.
-S, -- size: Order the block size.
When using the ls command, there will be several different colors, in which Blue indicates a directory, Green indicates an executable file, red indicates a compressed file, and light blue indicates a linked file, the bold black indicates the symbolic link, and the gray indicates other format files ,:
The most common use of ls is ls-l ,:
The start of the file type is a string consisting of 10 characters. The first character indicates the file type. It can be one of the following types:
-(Common files), d (directory), l (symbolic link), B (Block device files), and c (character device files ). The following nine characters indicate the object access permissions. They are divided into three groups, each with three characters.
The first group indicates the permissions of the file owner, the second group indicates the permissions of users in the same group, and the third group indicates the permissions of other users.
The three characters in each group indicate the read (r), write (w), and execution permission (x) of the object respectively ). For a directory, it indicates the access permission. S indicates that when the file is executed, the UID or GID of the file is assigned to the UID (User ID) or GID (group ID) of the execution process ). T indicates that the flag is set (left in memory and not swapped out ). If the file is a directory, the files in the directory can only be deleted by the Super User, directory owner, or file owner. If it is an executable file, after the file is executed, the pointer pointing to its body segment remains in the memory. In this way, the system will be able to mount the file more quickly when you execute it again. The file size, generation time, file or command name is displayed.
Pwd and cd commands
Pwd is used to display the absolute path of the current working directory. Format: pwd
Cd is used to change the working directory. The format is cd.
Mkdir command
Used to create a new directory in the format:
Mkdir [Option] Directory Name
Role: The mkdir command is used to create a subdirectory named dirname. Similar to the md command in ms dos, the command has the permission to use all users.
[Option] Main Parameters
-M, -- mode = mode: Set permissions, similar to chmod.
-P, -- parents: Create the upper-level directory when necessary. If the directory already exists, it is not treated as an error.
-V, -- verbose: information is displayed every time a new directory is created.
-- Version: displays the version information and leaves.
Cp command
Function: copy a file or directory.
Note: The cp command is used to copy files or directories. If you specify more than two files or directories at the same time, and the last destination is an existing Directory, then it copies all the previously specified files or directories to this directory. If multiple files or directories are specified at the same time, but the last destination is not an existing Directory, an error message will appear.
Parameters:
-A or -- archive: the effect of this parameter is the same as that of the "-dpR" parameter.
-B or -- backup deletes and overwrites the destination file. The backed up file or directory is also established as a symbolic link and points to the source file or directory link. If this parameter is not added, if a symbolic link is encountered during the copy process, the source file or directory will be copied directly.
-F or -- force forcibly copies a file or directory, regardless of whether the target file or directory already exists
-I or -- interactive ask the user before overwriting the file
-L or -- link creates a hard link to the source file instead of copying the file.
-P or -- preserve retains the attributes of the source file or directory, including the owner, group, permission, and time.
-P or -- parents retains the path of the source file or directory. This path can be an absolute or relative path, and the target directory must already exist in
-R recursive processing: processes the files in the specified directory along with subdirectories. If the source file or directory does not belong to a directory or symbolic link, it will be treated as a normal file.
-R or -- recursive processing, which processes the files and subdirectories under the specified directory together
-S or -- symbolic-link creates a symbolic link to the source file instead of copying the file.
-S <backup suffix string> or -- suffix = <backup suffix string> after you use the "-B" parameter to back up the target file, a backup string is added at the end of the backup file. The default backup suffix is a symbol "~ "
-U or -- update: After this parameter is used, the file will be copied only when the source file's Modification Time (Modification Time) is newer than the target file, or the target file with the corresponding names does not exist.
-V or -- verbose displays the execution process
-V <backup mode> or -- version-control = <backup mode> specifies the naming method of the backup file name when the backup file is created. The following three methods are available:
1. numbered or t, the backup number will be used, and ~ will be added at the end of the word ~ 1 ~ String, whose numbers are incremented in turn
2. simple or never will use simple backup. The default backup character string is ~, You can also use-S to specify
3. existing or nil will use the current method. The program will first check whether there is a backup number. If yes, the backup number will be used. If not, a simple backup will be used.
-X or -- one-file-system: the file system in which the file or directory is copied must be the same as the file system in which the cp command is executed; otherwise, the file system will not be copied, files in other partitions are not processed.
-- Help displays online help
-- Sparse = <> set the time to save the xishu File
-- Display version
Example:
. Copy the file. The file is copied only when the source file is modified later than the target file.
Cp-u-v file1 file2
. Copy file file1 to file file2
Cp file1 file2
. Copy file file1 to file file2.
Cp-I file1 file2
. Copy the file file1 to file2. Because the target file already exists, use the forced copy mode.
Cp-f file1 file2
. Copy the directory dir1 to the directory dir2
Cp-R file1 file2
. Copy the file file1, file2, file3, and directory dir1 to dir2.
Cp-R file1 file2 file3 dir1 dir2
. File attributes are retained during replication.
Cp-p a.txt tmp/
. The directory structure of the file is retained during replication.
Cp-P/var/tmp/a.txt./temp/
. Backup files generated during replication
Cp-B a.txt tmp/
. The backup file is generated during replication ~ 1 ~ Format
Cp-B-V t a.txt/tmp
. Specifies the tail mark of the backup file
Cp-B-S _ bak a.txt/tmp
Mv command
Purpose:
The mv command is used to rename a file or directory, or move the file from one directory to another. Its permission is granted to all users. This command is like a combination of ren and move in the doscommand.
Format:
Mv [options] source file or directory, target file or directory
[Options] main parameters:
-I: interactive operation. If the mv operation will overwrite the existing target file, the system will ask whether to rewrite the file and ask the user to answer "y" or "n" to avoid overwrite the file by mistake.
-F: Disable interactive operations. When an mv operation overwrites an existing target file, no indication is given. If this parameter is specified, the I parameter will no longer work.
Application instance:
(1) Rename the file test. c to test1.c:
$ Mv test. c test1.c
(2) Move the test1.c file to the Ccode Folder:
$ Mv test1./Ccode
Rm command
Rm is a common command used to delete one or more files or directories in a directory. It can also delete all files and subdirectories in a directory. For linked files, only the links are deleted, and the original files remain unchanged.
Rm is a dangerous command. Be careful when using it, especially for beginners. Otherwise, the entire system will be destroyed in this command (for example, in the/(root directory) run rm *-rf ). Therefore, before executing rm, we 'd better first check which directory we are in and what we want to delete and keep a high degree of clarity during operations.
1. Command Format:
Rm [Option] file...
2. command functions:
Delete one or more files or directories in a directory. If the-r option is not used, rm will not delete the directory. If you use rm to delete a file, you can restore it to its original state.
3. command parameters:
-F, -- force ignores non-existing files and never gives a prompt.
-I, -- interactive for interactive Deletion
-R,-R, -- recursive indicates that rm recursively deletes all directories and subdirectories listed in the parameter.
-V, -- verbose detailed display steps
-- Help: displays the help information and exits.
-- Version: Output version information and exit
Instance:
To delete the file test, the system will first ask whether to delete it.
Delete all files in sub-directories and sub-directories of projects
Cat command
The cat command is used to connect files or standard input and print. This command is often used to display the file content, connect several files, or read and display the content from the standard input. It is often used with the redirection symbol.
1. Command Format:
Cat [Option] [file]...
2. command functions:
Cat has three main functions:
(1) display the entire file at one time: cat filename
(2) create a file from the keyboard: cat> filename can only create new files, but cannot edit existing files.
(3) Merge several files into one file: cat file1 file2> file
3. command parameters:
-A, -- show-all is equivalent to-vET.
-B, -- number-nonblank: number of non-empty output rows
-E is equivalent to-vE.
-E, -- show-ends is displayed at the end of each line $
-N, -- number indicates the number of all rows output, starting from 1.
-S, -- squeeze-blank has more than two rows of blank rows in a row.
-T is equivalent to-vT.
-T, -- show-tabs: display the Skip character as ^ I
-U (ignored)
-V, -- show-nonprinting use ^ and M-reference, except LFD and TAB
How to Understand bash shell?
To understand bash shell, you must first understand bash and shell respectively.
Shell is a shell that serves as a bridge between the operating system (kernel) and the user. It acts as a command interpreter and translates user input commands to the system for execution. Like DOS in Windows, some built-in commands are provided for users to use. You can use these commands to write shell scripts to complete complex work.
Besides bash, there are several popular shell types: tcsh, csh, bash, and ksh. I will not talk about the differences between them here, I believe you can find relevant information on the Internet (including bash refers to the Bourne-again shell), but I would like to say that many linux distributions currently include the bash shell by default.
Reference: sername
How to run shell commands? Why is the first line #! /Bin/sh?
Because the shell program is interpreted and executed, it does not need to be compiled and assembled into the target program. According to the shell programming Convention, for example, the first line of the program is generally "#! /Bin/bash ", where # indicates that the row is a comment and the exclamation point"!" Tell the shell to run the command after the exclamation mark and use the rest of the file as the input, that is, run/bin/bash and let/bin/bash execute the shell program content. There are three methods for executing shell programs: 1. sh shell program file name. The command format of this method is bash shell program file name. This is actually to call a new bash command interpreter, and pass the shell program file name as a parameter to it. The newly started shell will read the specified file and execute the commands listed in the file. When all the commands are completed. The advantage of this method is that the shell debugging function can be used. 2. sh