Linux basic commands in a detailed

Source: Internet
Author: User
Tags parent directory touch command file permissions

1 Traversing a directory

Abbreviation of Cd:change Dicrectory

. Or./represents the current directory,.. Or.. /represents the previous table of contents, CD-Represents the last directory entered.

2 List of files and directories

Ls:list, the file under the directory is displayed.

Usage: ls [-LAFR] [dir], where-F indicates the addition/representation of the directory after the table of contents,-R is recursive display.

3 Working with files

3.1 Creating a file Touch

Command format: Touch [-ACDFMRT] File

Command parameters:

-A or--time=atime or--time=access or--time=use only change access time

-C or--no-create do not create any documents

-D uses the specified datetime instead of the current time

-F This parameter ignores non-processing and is responsible only for compatibility issues with BSD version touch directives

-M or--time=mtime or--time=modify only change the change time.

-R Sets the date and time of the specified document or directory to the same date and time as the reference document or directory.

-T uses the specified date time instead of the current time

Command function:

Touch command parameter to change the date and time of a document or directory, including access time and change time

Examples of Use:

Instance one: Create a file that does not exist

Touch A.log B.log Set up two log files at a time

3.2 Copying Files CP

Command format: CP [-IPRU] [File/dir]

Command parameters:

-I ask before overwriting a file

-P preserves the properties of the source file or directory, including the owner, the owning group, the permissions and the time

-r recursive processing of files and subdirectories in the specified directory, typically used as a copy directory

-U Use this parameter to copy a file only when the source file is modified (modification time) when the destination file is updated, or if the destination file for which the name corresponds does not exist

Command function:

CP can be used for copies of files or directories

Examples of Use:

[[email protected] data]# cp-p ett.xtx tte.txt reserved file attribute copy and renamed to Tte.txt

3.3 Moving or renaming files mv

Command format: MV [-bfiut] [File/dir]

Command parameters:

-F force coercion means that if the target file already exists, it will not be queried and overwritten directly

-I if the target file (destination) already exists, ask whether to overwrite

-U if the target file already exists and the source is newer, it will be updated (update)

Command function:

The MV command can be used to modify the name of a file or directory

Examples of Use:

[[Email protected] data]# mv Tte.txt changename.txt Modify Tte.txt's name

3.4 Deleting a file rm

Command format: RM [-IRF] [File/dir]

Command parameters:

-I must confirm before any delete operation

-F Force Delete

-R Recursive Delete

Command function:

RM is used to delete files, which are commonly used with find, which we'll talk about in the find usage.

Examples of Use:

[Email protected] data]# RM-FR test/

4 Working with Directories

4.1 Creating a directory MkDir

Command format: mkdir [-MPV] [dir]

Command parameters:

-m mode, specifying access permissions for the directory, similar to chmod

-P If the directory already exists, there is no error message. If the parent directory does not exist, the parent directory will be created. This option is commonly used to create cascading catalogs.

-V displays a message for each directory

Command function:

Create a single directory or cascading directory.

Examples of Use:

[email protected] data]# Mkdir-p Blog/{bin,lib,var/{etc,doc,logfile}}
[[email protected] data]# tree blog/
blog/
├──bin
├──lib
└──var
├── Doc
├──etc
└──logfile

4.2 Deleting a directory RmDir

By default, the RmDir command is used only to delete empty directories, and the deletion of non-empty directories requires RM-FR to be removed recursively, so the risk is very high, so it is commonly used in conjunction with find.

5 Viewing files

5.1 Cat Command

Command format: Cat [-NBT] [file]

Command parameters:

-N adds line numbers to all rows

-B Add line numbers to text only

-T does not display tabs, use ^i instead

Command function:

View entire file contents

5.2 more/less

Command function:

Page display, more convenient than cat.

5.3 Viewing some files

5.3.1 Tail command

Command parameters:

-N Displays the last number of rows of information

Command function:

Display Trailer XXX line information

Examples of Use:

[Email protected] data]# Tail-n 3 a.txt
18
19
20

5.3.2 Head Command

Command parameters:

With tail

Command function:

Show Header xxx line information

Examples of Use:

[Email protected] data]# Head-n 3 a.txt
1
2
3

6 Find Lookup commands

Command format: Find [path] [parameter options]

Command parameters:

-name finds files by file name.

Find/data-name FileName Locate the file named filename under the/data directory and its subdirectories
Find. -name "*.sh" in the current directory and its subdirectories (with "." To find any file with the extension "sh" in the

-perm to find files according to file permissions.

Find. -perm 755 Find files with file permission bit 755 in current directory

-prune Use this option to have the Find command not be found in the currently specified directory, and if you use the-depth option at the same time,-prune will be ignored by the Find command.

Find/apps-path "/apps/bin"-prune find files in the/apps directory, but do not want to find them in the/apps/bin directory

-user Find files According to the owner of the file

Find ~-user root finds files in the $home directory that belong to the main Sam file

-group Find files according to the group to which the files belong

-mtime to find files according to the time the file was changed

+7:7 days ago

-7: Last seven days

7: Day Seventh

-type Search by file type

B-Block device files
D-Catalog
C-Character device files
P-Piping File
L-Symbolic Link file
F-Normal file

-size N:[c] Find files with a file length of n blocks, with C indicating the length of the file in bytes

Find and Xargs

When a matching file is processed using the-EXEC option of the Find command, the Find command passes all matching files to exec execution. However, some systems have a limit on the length of the command that can be passed to exec so that an overflow error occurs after the Find command runs for a few minutes. The error message is usually "parameter column too Long" or "parameter column overflow". This is where the Xargs command is used, especially with the Find command.

The find command passes the matched file to the Xargs command, and the Xargs command takes only a subset of the files at a time instead of all, unlike the-exec option. This allows it to first process a portion of the file that was first fetched, then the next batch, and so on.

In some systems, the use of the-EXEC option initiates a corresponding process for processing each matching file, not all of the matching files are executed once as parameters, so that in some cases, there are too many processes and degraded system performance, so the efficiency is not high , while using the Xargs command, there is only one process. In addition, when using the Xargs command, whether to get all the parameters at once, or to obtain the parameters in batches, and each time the number of parameters obtained will be based on the options of the command and the corresponding tunable parameters in the system kernel to determine

Find Delete

    [[email protected] home]# find-type f-name "*.txt" | Xargs rm-f (recommended removal)

Find+sed

[[email protected] data]# find. -type f-name "*.sh" | Xargs sed ' s/oldboy/oldgirl/g '

Resources:

Https://www.cnblogs.com/skynet/archive/2010/12/25/1916873.html

Https://www.cnblogs.com/peida/archive/2012/11/16/2773289.html

Linux basic commands in a detailed

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.