Linux instructions (1)

Source: Internet
Author: User

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: will be overwritten at link end

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.