Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A detailed explanation of the use of linux system commands

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "detailed explanation of the use of linux system commands", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "linux system commands complete use of detailed explanation" bar!

Cat cd

Chmod chown

Cp cut

Name: cat

Permissions: all users

Usage: cat [- AbeEnstTuv] [--help] [--version] fileName

Description: connect the file string to the basic output (screen or add > fileName to another file)

Parameters:

-n or-- number numbers all output lines starting with 1

-b or-- number-nonblank is similar to-n, except that blank lines are not numbered

When-s or-- squeeze-blank encounters blank lines with more than two consecutive lines, replace them with blank lines of one line

-v or-- show-nonprinting

Example:

Cat-n textfile1 > textfile2 enter the contents of the textfile1 file with a line number into the textfile2 file

Cat-b textfile1 textfile2 > > textfile3 appends the contents of textfile1 and textfile2 files to textfile3 after adding line numbers (blank lines are not added)

Name: cd

Permissions: all users

Usage: cd [dirName]

Description: change the working directory to dirName. The dirName representation can be an absolute path or a relative path. If the directory name is omitted, change to the user's home directory (that is, the directory where you were just login). In addition, "~" also means "home directory." Indicates the directory in which it is currently located, ".." Represents the directory above the current directory location.

Example: skip to / usr/bin/:

Cd / usr/bin

Jump to your own home directory:

Cd ~

Skip to the top two layers of the current directory:

Cd.. /..

Instruction name: chmod

Permissions: all users

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

Description: Linux/Unix file access is divided into three levels: file owner, group, and others. Chmod can be used to control how files are accessed by others.

Set up a plan:

Mode: permission setting string, in the following format: [ugoa...] [[+-=] [rwxX]...] [,...], where u indicates the owner of the file, g indicates that the owner belongs to the same group (group) as the owner of the file, o indicates other people, and an indicates all three.

+ means to increase permissions,-means to cancel permissions, and = means to set permissions uniquely.

R indicates readable, w indicates writable, x indicates executable, and X indicates only if the file is a subdirectory or if the file has been set to executable.

-c: if the permission of the file has indeed been changed, the change action will be displayed.

-f: do not display an error message if the file permissions cannot be changed

-v: displays the details of permission changes

-R: make the same permission changes for all files in the current directory as well as subdirectories (that is, change them one by one recursively)

-- help: displays auxiliary instructions

-- version: display version

Example: set the file file1.txt to be accessible to everyone:

Chmod ugo+r file1.txt

Set the file file1.txt to be accessible to everyone:

Chmod Aguilr file1.txt

Set the file file1.txt and file2.txt as the owner of the file, which can be written by those who belong to the same group, but not by others:

Chmod ug+w,o-w file1.txt file2.txt

Set ex1.py to be executed only by the owner of the file:

Chmod upright x ex1.py

Make all files and subdirectories in the current directory readable by anyone:

Chmod-R aquir *

In addition, chmod can also use numbers to represent permissions, such as chmod 777 file

Syntax is: chmod abc file

There is a number for a User,Group and a number for Other respectively.

Renew4, want2, 2, 3, 1, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4

If you want the rwx property, then 4, 2, 1, 7.

If you want the rw- property, then 4 / 2 / 6

If you want the rmurx attribute, then 4, 1, 7.

Example:

Chmod a=rwx file

And

Chmod 777 file

The effect is the same

Chmod ug=rwx,o=x file

And

Chmod 771 file

The effect is the same

If you use chmod 4755 filename, you can make this program have the permission of root

Instruction name: chown

Permission: root

Usage: chmod [- cfhvR] [--help] [--version] user [: group] file...

Description: Linux/Unix is a multi-person multi-work system, all files have owners. With chown, the owner of the file can be changed. Generally speaking, this directive is only used by the system administrator (root). The average user does not have the permission to change someone else's file owner, nor does he have the permission to change his own file owner to someone else. Only the system administrator (root) has such permissions.

Set up a plan:

User: the user of the new file owner IDgroup: the user group of the new file owner (group)-c: show the change action only if the file owner has indeed changed-f: do not display an error message if the file owner cannot be changed-h: change only for the link Instead of the file that the link really points to-v: shows the details of the owner's changes-R: make the same owner changes to all files and subdirectories in the current directory (that is, change them one by one by recursion)-- help: display auxiliary instructions-- version: display version

Example:

Set the owner of the file file1.txt as the user jessie of the users community:

Chown jessie:users file1.txt

Set the owner of all files and subdirectories under the current directory to the user lamport of the users group:

Chmod-R lamport:users *

Name: cp

Permissions: all users

Mode of use:

Cp [options] source dest

Cp [options] source... Directory

Description: copy one file to another, or copy several files to another directory.

Set up a plan:

-a copy the file status, permissions and other information as much as possible.

-r if the directory name is included in the source, all the files in the directory will be copied to the destination in order.

-f if a file with the same file name already exists at the destination, delete it before copying it.

Example:

Copy the archive aaa (already exists) and name it bbb:

Cp aaa bbb

Copy all C programs to the Finished subdirectory:

Cp * .c Finished

Name: cut

Permissions: all users

Usage: cut-cnum1-num2 filename

Description: displays the text of each line from num1 to num2 from the beginning.

Example:

Shell > > cat example

Test2

This is test1

Shell > > cut-c0-6 example # # print starts with the first six characters

Test2

This i

Usage: find

Instructions for use:

List the expression-compliant files in the file system. You can refer to a combination of different information such as the name, category, time, size, and permissions of the file, and only those that match will be listed.

Find judges path and expression according to the following rules, the first-(), on the command line! The first part is path, followed by expression. The current path is used if path is an empty string, and-print is used as the default expression  if expression is an empty string

There are as many as 20 or 30 options available in expression, and only the most commonly used ones are introduced here.

-mount,-xdev: only check and specify files under the same file system to avoid listing files in other file systems.

-amin n: read in the past n minutes

-anewer file: files that have been read later than the file file

-atime n: read files in the past n days

-cmin n: modified in the past n minutes

-cnewer file: files that are newer than file file

-ctime n: modified files 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: files whose path names match p. Ipath ignores case.

-name name,-iname name: files whose names match name. Iname ignores case

-size n: the file size is n units, b represents a block of 512 bytes, c represents the number of characters, and k indicates that kilo bytes,w is two bytes. -type c: files of type c.

D: directory

C: font device file

B: block device file

P: named storage column

F: general archives

L: symbolic link

S: socket

-pid n:process id is the file of n

You can use () to separate expressions and use the following operations.

Exp1-and exp2

! Expr

-not expr

Exp1-or exp2

Exp1, exp2

Example:

List all files with the extension name c in the current directory and its subdirectories.

# find. -name "* .c"

List all general files in its subdirectories of the current directory

# find. -ftype f

List all files that have been updated in the last 20 minutes under the current directory and its subdirectories

# find. -ctime-20

Name: less

Permissions: all users

Mode of use:

Less [Option] filename

Description:

The function of less is very similar to that of more, which can be used to browse the contents of text files, except that less allows users to scroll back

To browse the parts you have already seen, and because less does not read the entire file in the first place, it will be faster than ordinary document editors (such as vi) when opening large files.

Example:

Instruction name: ln

Permissions: all users

Usage: ln [options] source dist, where the format of option is:

[- bdfinsvF] [- S backup-suffix] [- V {numbered,existing,simple}]

[- help] [--version] [- -]

Description: Linux/Unix file system, there are so-called link (link), we can regard it as an alias for the file, and links can be divided into two types: hard link (hard link) and soft link (symbolic link), hard link means that a file can have multiple names, while the way of soft link is to generate a special file, the content of the file points to the location of another file. Hard links exist in the same file system, while soft links can span different file systems.

Ln source dist generates a dist to source, while the use of hard or soft links is determined by parameters.

Neither hard link nor soft link will make a copy of the original file and will only take up a very small amount of disk space.

-f: delete files with the same name as dist when linking-d: allow system administrators to hard-link their own directories-I: ask before deleting files with the same name as dist-n: when soft links are made Think of dist as a general file-s: soft link (symbolic link)-v: show its file name before the link-b: back up the files that will be overwritten or deleted at the time of the link-S SUFFIX: add the suffix SUFFIX-V METHOD: specify the backup method-help: display auxiliary instructions-version: display version

Example:

Generate a symbolic link:zz from the file yy

Ln-s yy zz

Generate a hard link:zz from the file yy

Ln yy xx

Name: locate

Permissions: all users

Usage: locate [- Q] [- d] [--database=]

Locate [- r] [--regexp=]

Locate [- qv] [- o] [--output=]

Locate [- e] [- f]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report