Linux instructions [1] [note] From the Tianjin Linux Hotline

Source: Internet
Author: User
Tags time and date touch command
Cat CD
Chmod chown
CP cut

Name: Cat
Permission: All Users
Usage: CAT [-abeensttuv] [-- help] [-- version] filename
Note: connect the archive string and upload it to the Basic output (screen or add> filename to another archive)
Parameters:
-N or -- number indicates the number of all output rows starting from 1.
-B or -- number-nonblank is similar to-N, but is not numbered for blank rows.
-S or -- Squeeze-blank when there are two consecutive blank rows or more, it is replaced by a blank row
-V or -- show-nonprinting

Example:
Cat-N textfile1> textfile2: add the row number to the file content of textfile1 and enter textfile2.
Cat-B textfile1 textfile2> textfile3 adds the file content of textfile1 and textfile2 to the row number (blank rows are not added) and then attaches the content to textfile3

Name: CD
Permission: All Users

Usage: CD [dirname]

Note: change the working directory to dirname. Dirname can be an absolute or relative path. If the directory name is omitted, it is changed to the user's home directory (that is, the directory where the login is located ).

In addition ,"~ "It also indicates the Home Directory," .. "indicates the current directory, and" .. "indicates the previous directory at the current directory location.

Example: Skip to/usr/bin /:
CD/usr/bin

Jump to your home directory:
Cd ~

Jump to the top two layers of the current directory:
CD ../..

Command name: chmod
Permission: All Users

Usage: chmod [-CFVR] [-- help] [-- version] mode file...

Note: file access permissions for Linux/Unix are classified into three levels: file owner, group, and others. Chmod can be used to control how files are accessed by others.

Calculation:

Mode: permission setting string in the following format: [ugoa...] [[+-=] [rwxx]...] [,...], U indicates the owner of the file, G indicates that the owner of the file belongs to the same group, O indicates that the owner of the file belongs to other people, and a indicates that all three are.
+ Adds a permission,-Indicates canceling the permission, and = indicates a unique permission.
R indicates that the file can be read, W indicates that the file can be written, and X indicates that the file can be executed only when the file is a subdirectory or the file has been set to executable.
-C: if the permission of the file has been changed, the change action is displayed.
-F: Do not display an error message if the file permission cannot be changed.
-V: displays details of permission changes.
-R: Change the permissions of all files and sub-directories in the current directory in the same way (that is, change one by one in the way of delivery)
-- Help: displays auxiliary instructions
-- Version: displays the version.

Example: Set the file file1.txt to readable by all users:
Chmod Ugo + R file1.txt

Set file1.txt to readable:
Chmod A + R file1.txt

Set file1.txt and file2.txt as the owner of the archive, which can be written to the same group to which the archive belongs, but not to others:
Chmod ug + W, o-w file1.txt file2.txt

Set ex1.py to only the owner of the file to execute:
Chmod U + x ex1.py

Set all files and subdirectories in the current directory to be readable by anyone:
Chmod-r a + R *

In addition, chmod can use numbers to indicate permissions, such as chmod 777 file.
Syntax: chmod ABC File

Each A, B, and C is a number, indicating the permissions of the user, group, and other respectively.

R = 4, W = 2, x = 1
If you want the rwx attribute, 4 + 2 + 1 = 7;
If the RW-attribute is required, 4 + 2 = 6;
If you want the R-x attribute, 4 + 1 = 7.

Example:
Chmod A = rwx File

And
Chmod 777 File

Same effect
Chmod ug = rwx, O = X file

And
Chmod 771 File

Same effect

If you use chmod 4755 filename, you can grant root permissions to this program.

Command name: chown
Permission: Root

Usage: chmod [-cfhvr] [-- help] [-- version] user [: Group] file...

Note: Linux/Unix is a multi-person, multi-job operating system. All archives have owners. Chown can be used to change the owner of an archive. Generally, this command is only used by the system administrator (Root). Generally, users do not have the permission to change the owner of another user's archive or change their owner to another user. Only the system administrator (Root) has such permissions.

Calculation:

User: User idgroup of the new owner: User Group of the new owner (Group)-C: if the owner of the file has indeed changed, the change action is displayed-F: if the archive owner cannot be changed, do not display the error message-H: only the link is changed, not the file that the link actually points to-V: show owner change details-R: perform the same owner change on all files in the current directory and sub-directories (I .e., change one by one in the way of delivery) -- help: show auxiliary description -- version: display version

Example:
Set the owner of the file file1.txt to user Jessie of the Users Group:
Chown JESSIE: Users file1.txt

Set all files in the current directory and sub-directory owner to user Lamport of Users Group:
Chmod-r Lamport: Users *

Name: CP
Permission: All Users

Usage:

CP [Options] source dest
CP [Options] source... directory

Note: copy one file to another or copy several files to another directory.

Count

-A tries its best to copy the file status, permissions, and other information as they are.
-R if the source contains the directory name, the files under the directory are also copied to the destination in sequence.
-F if the destination already has an archive with the same file name, delete it before copying.
Example:
Copy the file AAA (already exists) and name it BBB:
CP aaa bbb

Copy all C language programs to the finished subdirectory:
Cp *. c finished

Name: Cut

Permission: All Users

Usage: Cut-cnum1-num2 filename

Description: displays the text of each row starting from num1 to num2.

Example:

Shell> cat Example
Test2
This is test1
Shell> cut-c0-6 example # the first 6 characters starting with print
Test2
This I

Name: Find
Usage: Find
Instructions for use:

List the files that match the expression in the file system. You can specify a combination of different information such as the name, category, time, size, and permissions of an archive. Only the information that matches the information is listed.

Find judges the path and expression according to the following rules, and first-() in the Command column -(),! The previous part is path, followed by expression. If path is a Null String, use the current path. If expression is a Null String, use-print as the default expression.

There are more than 20 or 30 options available in expression. Here, we will only introduce the most commonly used options.

-Mount,-xdev: Only checks the files in the same file system as the specified directory to avoid listing the files in other file systems.
-Amin N: Read in the past n minutes
-Anewer file: The file that has been read later than the file.
-Atime N: files that have been read in the past n days
-Cmin N: modified in the past n minutes
-Cnewer file: The file that is updated than the file.
-Ctime N: Files modified in the past n days
-Empty: empty file-gid N or-group name: GID is N or group name is name
-Ipath P,-path P: The file whose path name is P-compliant. ipath ignores case sensitivity.
-Name,-INAME name: name of the file that matches the name. INAME ignores case sensitivity.
-Size N: the file size is n units. B indicates the block of the 512-bit tuples. C indicates the number of characters, K indicates kilo bytes, and W indicates two-bit tuples. -Type C: the archive type is C.
D: Directory
C: font Device File
B: block device Archives
P: named storage Column
F: General Files
L: Symbolic Link
S: Socket
-Pid N: file whose process ID is n

You can use () to separate the operators and use the following operations.
Exp1-And exp2
! Expr
-Not expr
Exp1-or exp2
Exp1, exp2
Example:
List all files with C extension files under the current directory and Its subdirectories.
# Find.-Name "*. c"

List all common files in the subdirectories of the current directory
# Find.-FTYPE F

List all files updated in the last 20 minutes in the current directory and Its subdirectories.
# Find.-ctime-20

Name: less

Permission: All Users

Usage:

Less [Option] filename

Note:
The role of less is very similar to that of more. It can be used to browse text files. The difference is that less allows users to scroll back.
In order to browse the parts that have already been viewed, And because less does not read the entire file from the very beginning, when opening a large file, it will be like a general file editor (such as VI).

Example:

Command name: ln
Permission: All Users

Usage: ln [Options] source Dist, where the option format is:

[-Bdfinsvf] [-s backup-suffix] [-V {numbered, existing, simple}]
[-- Help] [-- version] [--]
Note: there is a so-called link in the Linux/Unix File System. we can regard it as the alias of the file, and the link can be divided into two types: hard link) symbolic Link indicates that a file can have multiple names, while a soft link generates a special file, the content of this file points to another file. Hard links exist in the same file system, but soft links can span different file systems.
Ln source dist is used to generate a connection (DIST) to the source. As for hard link or soft link, it is determined by the parameter.

No matter whether it is a hard link or soft link, it will not copy the original file, it will only occupy a very small amount of disk space.

-F: delete the file with the same name as Dist before link completion-D: Allow system administrators to hard link their directories-I: when deleting an archive with the same name as Dist, first ask-N: During Soft link, DIST will be treated as a general archive-S: perform soft link (symbolic link)-V: display file name B before link: Back up the file that will be overwritten or deleted at link end-s Suffix: add the backup file to the end of suffix-V method: Specifies the backup method -- help: displays the auxiliary instructions -- version: displays the version
Example:
Generate a symbolic link: ZZ
Ln-s YY ZZ

Generate a hard link: ZZ
Ln YY xx

Name: locate
Permission: All Users
Usage: locate [-q] [-D] [-- database =]
Locate [-R] [-- Regexp =]
Locate [-QV] [-O] [-- output =]
Locate [-E] [-F] <[-L] [-C]
<[-U] [-u]>
Locate [-VL] [-- version] [-- help]
Note:
Locate allows users to quickly search for specified files in the file system. The method is to first create a database that includes the names and paths of all files in the system. Then, you only need to query the database when searching, instead of going into the file system.

In general distribution, database creation is automatically executed in contab. Generally, users only need to use

# Locate your_file_name

. Parameters:
-U
-U

Create a database.-U starts from the root directory, and-u can specify the starting position.

-E

Set
Excluded from the search range.

-L
If it is 1, the security mode is enabled. In security mode, users do not see files that cannot be viewed by permissions. This slows down because the locate must obtain the permission information for the file in the actual file system.

-F
Exclude specific file systems. For example, we have no reason to put the files in the proc file system in the database.

-Q
Quiet Mode, no error message is displayed.

-N
Displays at most outputs.

-R
Use regular operators to search for conditions.

-O
Specifies the name of the data inventory.

-D

Path of the database

-H
Show auxiliary messages

-V
Show more messages

-V
Example of displaying the version information of a program:

Locate chdrv: search for all chdrv files.
Locate-N 100 A. Out: searches for all files named A. Out, but displays a maximum of 100 files.
Locate-u: Create a database

Name: ls
Permission: All Users

Usage: ls [-alrtafr] [name...]

Description: displays the contents of a specified working directory (list files and subdirectories contained in the current working directory ).

-A: displays all files and directories. (If the file name or directory name starts with "." is specified in LS, it is regarded as a hidden file and will not be listed)
-L in addition to the file name, the file type, permission, owner, and file size are also listed in detail.
-R: Display files in reverse order (originally in alphabetical order)
-T list archives in the order of creation time
-A is the same as-a, but does not list "." (current directory) and ".." (parent directory)
-F Add a symbol after the name of the file to be listed. For example, add "*" to the executable file and add "/" to the directory "/"
-R if the directory contains files, the following files are listed in sequence.

Example:
List all files whose names start with "S" in the current working directory:
Ls-ltr s *

List all the following directories and file details in the/bin directory:
Ls-LR/bin

List all files and directories under the current working directory. Add "/" after the directory name, and add "*" after the executable file name "*":
Ls-AF

Name: More
Permission: All Users
Usage: more [-dlfpcsu] [-num] [+/pattern] [+ linenum] [filenames ..]
Note: similar to CAT, but it will be displayed on one page for users to read on one page, and the most basic command is to display on the next page by pressing the Space key, press the B key to display the back page and search for strings (similar to VI). In the instruction file in use, press H.
Parameter:-num indicates the number of rows displayed at a time.
-D prompts the user to display [Press space to continue, Q to quit.] at the bottom of the screen. If the user presses the wrong key, [Press h for instructions.] instead of a beep will be displayed.
-L cancel the function that will be paused when a special character ^ L (Paper delivery character) is encountered
-F indicates the number of rows calculated based on the actual number of rows, rather than the number of rows after the automatic line feed (some rows with too long words will be extended to two or more rows)
-P does not display each page in a scroll mode, but clears the screen before displaying the content.
-C is similar to-P. The difference is that the content is displayed before other old data is cleared.
-S: if there are two or more blank rows in a row, it is replaced by a blank row.
-U does not display the quotation marks (it varies depending on the terminal specified by the Environment Variable term)
+/Search for this string (pattern) before each file is displayed, and then start to display it after this string.
+ Num is displayed from row num.
The number of files filenames want to display.
Example:
More-s testfile displays the file content of testfile page by page. If there are two or more lines of blank lines in a row, the lines are displayed as one line of blank lines.
More + 20 testfile: the content of the file testfile is displayed from row 20th.

Name: MV
Permission: All Users

Usage:

MV [Options] source dest
MV [Options] source... directory
Note: move one file to another or multiple files to another directory.
Parameter:-I if the destination already has a file of the same name, first ask whether to overwrite the old file.

Example:

Change the archive AAA to BBB:
MV aaa bbb

Move all C language programs to the finished subdirectory:
MV-I *. c

Name: Rm
Permission: All Users

Usage: Rm [Options] Name...

Delete files and directories.

Count

-I ask for confirmation one by one before deletion.
-F the original file is deleted directly even if its attribute is set to "read-only". You do not need to confirm the attribute one by one.
-R also deletes directories and the following files one by one.
Example:
Delete all C language files. Before deletion, ask for confirmation one by one:
Rm-I *. c

Delete all files in the finished subdirectory and subdirectory:
Rm-r finished

Name: rmdir
Permission: all users with the appropriate permissions in the current directory

Usage: rmdir [-p] dirname

Delete an empty directory.

Parameter:-P is used to delete a subdirectory that becomes an empty directory.

Example:

Delete the sub-directory named AAA in the working directory:
Rmdir aaa

In the BBB directory under the working directory, delete the subdirectory named test. If the BBB directory becomes empty after the test is deleted, the BBB directory is also deleted.
Rmdir-p bbb/test

Name: Split
Permission: All Users

Usage: Split [Option] [input [prefix]

Note:

Splits an archive into several. Split the output from the input file into a fixed-size file. The file names are prefixaa, prefixab...; the prefix value is 'X' by default. If there is no input file or '-', the data is read from the standard input.

Kuang Dou

-B, -- bytes = size

The size value is the size of each output file, in bytes.
-C, -- line-bytes = size

The maximum number of bytes in a single row in each output file.
-L, -- lines = Number

The number value is the number of columns in each output file.
-Number

It is the same as-l number.
-- Verbose

Print the error information to the standard error output before each output file is enabled.
-- Help

Displays the auxiliary information and leaves.
-- Version

List the version information and exit.
Size can be added to the unit: B Represents 512, K represents 1 K, and m represents 1 Meg.

Example:

Postgressql large database backup and storage:

Because Postgres allows tables to exceed the maximum file capacity of your system, it is possible that you need to dump the tables to a single file. Split the files to separate them.

% Pg_dump dbname | split-B 1 m-filename. Dump.

Reload

% Createdb dbname
% Cat filename. Dump. * | pgsql dbname

Name: Touch
Permission: All Users

Usage:
Touch [-ACFM]
[-R Reference-file] [-- file = reference-file]
[-T mmddhhmm [[CC] YY] [. SS]
[-D time] [-- date = time] [-- time = {atime, access, use, mtime, modify}]
[-- No-create] [-- help] [-- version]
File1 [file2...]

Note:
The touch command changes the time record of the file. Ls-l can display the time record of the file.

Parameters:
A. Change the reading time record of the file.
M changes the modification time record of the file.
C If the target file does not exist, no new file will be created. The same effect as -- no-create.
F is not used. It is reserved for compatibility with other UNIX systems.
R uses the time record of the reference file, which has the same effect as -- file.
D. Set the time and date in different formats.
T sets the time record of the file. The format is the same as that of the date command.
-- No-create does not create a new file.
-- Help lists the instruction formats.
-- Version: List version information.

Example:

The simplest way to use it is to change the record time of an archive to the current time. If the file does not exist, the system creates a new file.

Touch File
Touch file1 file2

Change the time record of the file to A.M. on January 1, May 6, two thousand. For the time format, refer to the date command. At least mmddhhmm must be input, that is, the time of the month, day, and minute.

Touch-c-t 05061803 File
Touch-c-t 050618032000 File

Change the time record of the file to the same as the referencefile.

Touch-r referencefile File

Change the time record of the file to A.M. on January 1, May 6, two thousand. The time can be in the AM, PM, or 24-hour format. The date can be in another format, such as 6 May 2000.

Touch-d "6:03 PM" File
Touch-d "05/06/2000" File
Touch-d "6:03 PM 05/06/2000" File

 

Related Article

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.