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

Chapter III knowledge of commonly used linux commands-centos7.5

2025-01-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

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

The Linux Command

SHELL

File located at/bin/bash

cat /etc/shells

LINUX command classification

internal command

external command

Special instructions integrated into the Shell interpreter program, also known as Built-in instructions

A script file or binary program that performs a specific function in Linux.

Part of Shell

Commands outside the Shell interpreter program

There is no separate corresponding system file

Each external command corresponds to a file in the system

Automatic load memory, can be used directly

You must know the corresponding file location, which can only be executed after it is loaded by Shell.

Echo $PATH

Common command line usage formats

command word

It's the most critical part of the whole order.

The only way to determine an order

option

Short Format Option: Use the "-" symbol to guide

Multiple single-character options can be combined for use

Long format option: use "--" symbol to guide

parameters

command word processing object

It can be a file name, directory (path) name, or user name.

The number can be zero to many

Editing Linux Command Line Auxiliary Operations

Tab key

backslash "\"

Ctrl+U shortcut key

Ctrl+K shortcut

Ctrl+L shortcut

Ctrl+C shortcut

How to Get Command Help

problem

How can I use commands quickly and correctly to complete operations?

How to get help

use the help command

Use the "--help" option

Using the man manual page

Directory and file basics

PWD command

CD command

LS command

du command

Show current working directory

Pwd

Change the user's working directory to another location

format

description

cd target position

Switch to target position

cd ~

cd

If no destination is specified, switch to the current user's host directory

cd -

Switch to the directory you were in before the last cd command was executed

directory operation

Absolute Directory: Representation of paths from the root directory

Relative Directory: Representation of the path from the current directory

Example: cd.. Relative path notation goes into the parent directory.

―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――

Displays the contents of the directory, including subdirectories and attribute information about files

ls [options] [file or directory… ]

ls -l

flag

d stands for catalogue

- Representative documents

L stands for link

ls -a along with show hidden files to. file or directory at the beginning

ls -d Display information about the directory itself

ls -h Display information in a friendly way

common options

-l 、 -a 、 -A 、 -d 、 -h 、 -g 、 --color

associative wildcard

"? ": Matches an unknown character in the filename

"*": matches any number of characters in the filename

Simplify common, longer commands through alias mechanisms

alias command alias = command

Set myls to alias ls - alh

alias myls = 'ls - alh'

Permanently save the way you define aliases

Edit ~/.bashrc

alias la='ls -a -l'

Counts the amount of disk space occupied by a specified directory (or file)

du [options] [file or directory… ]

option

example

-a

Disk space usage statistics include all files, not just directories

-h

Displays the directory or file size (K, M), the default size unit is bytes (KB)

-s

Only count the total size of space occupied by each parameter, not the size of each subdirectory and file.

df -h Displays remaining disk space

mkdir rmdir

Create a new empty directory

mkdir [options] directory location and name

-p: Create nested multi-level directories at once

Rmdir must be empty when deleting subdirectories.

Create Empty File- touch

Update time stamp of file

Often used to create multiple new empty files

touch file…

Create link file- ln

Create links to files or directories File

file type

Soft links, also known as symbolic links

hard links

ln [-s] source file or directory…link file or destination location

soft link-s

hard links

After deleting the original file

failure

still available

scope of use

For files or directories

Available for files only

save location

The original file can be located in a different file system

Must be in the same file system as the original file (e.g. a Linux partition)

Cancel soft link

Unlink Link Name

For example: unlink aa1.txt

Finds hardlink files with specified inode number

ll -i

find / -inum 16810953

-------------------------------------------

Rebuild a copy of the file or directory (source) that needs to be copied and save it as a new file or directory

cp [options]…source file or directory…destination file or directory…

option

description

-f

Overwrite target files or directories with the same name without warning, directly force copy

-i

Remind users to confirm when overwriting target files or directories with the same name

-p

Keep the permissions, ownership, and time stamp attributes of the source file unchanged when copying

-r

This option must be used when copying directories, indicating recursive copying of all files and subdirectories

Note:

When copying multiple files or directories, the destination location must be a directory and the destination directory must already exist

Copy the style of the file

Cp file name subdirectory

For example: CD /ROOT

cp initial-setup-ks.cfg a1

cp filename New filename

Copy a new file from the current directory

Support Wildcard *?

Copy one directory and all files in it to another directory

Cp -r b3 b34

Delete the specified file or directory

rm [Options] File or directory to delete…

common options

-f(mandatory), -i (friendly hint), -r (with subdirectories)

RF can be used in combination.

Guess what the following command does.

rm -rf public_html/grub/

rm -i public_html/apg.conf

Note:

Do not delete directories or configuration files that already exist on the system to avoid unexpected failures

Move files or directories mv

mv [options] …source file or directory…destination file or directory

Moves the specified file or directory to a new location

If the destination location is the same as the source location, it is equivalent to a rename operation

mv mytouch mkfile

mv mkfile public_html/

Find command/file directory

The search scope is determined by the PATH environment variable (echo $PATH)

the which command| program name

which -a command| program name

Find files or directories-find

By recursion, fine search is carried out according to different attributes such as name, type and size of the target.

find [find range] [find conditional expression]

find type

keyword

description

Search by Name

-name

Search according to the name of the target file, allowing "*" and "? "Wildcards

Search by file size

-size

Search by target file size

Generally use "+" and "-" to set more than or less than the specified size as the search condition

Common units of capacity include kB (note k is lowercase), M, G

Search by file owner

-user

Find files based on whether they belong to the target user

Search by file type

-type

Search by file type

File types include ordinary file (f), directory (d), block device file (b), character device file (c), etc.

Block devices refer to devices that read data in blocks (such as hard disks, memories, etc.), and character devices refer to devices that read data by single characters (such as keyboards, mice, etc.)

For example:

find / -name "aa*.log" -ls

find / -size +100M -ls

find /etc -size -10k -ls

find / -user abc -ls

find /root/b35 -type f -ls

Use logical operators between expressions

"-a" means and (and)

"-o" stands for or

find /boot -size +1024k -a -name "vmlinuz*"

find /boot -size +1024k -o -name "vmlinuz*"

Knowledge sorting

View and switch directories (pwd, cd, ls, du, df)

Create directories and files (mkdir, touch, ln)

Copy, delete, move directories and files (cp, rm, mv)

Find directories and files (which, find)

Assignment:

1. Create a subdirectory/root/abc, create new subdirectories a1,b1,c1 and files a1.txt,b1.txt,c1.txt below, copy the/etc/resolv.conf file to the a1 directory named r1. conf, and soft link this file in the/root/abc/b1 directory.

2. Find the hostname file in the system, copy it to/root/abc/c1, copy the new file h2.conf from this directory, and then delete the/root/abc/c1/hostname file.

3. Use 2 methods to find ls commands in the system and display detailed information.

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

Network Security

Wechat

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

12
Report