Several examples of Linux file Management command summary and wildcard

Source: Internet
Author: User
Tags aliases diff touch touch command

Linux File Management Class command summary

1. text File View class command: Cat,tac,more,less,tail,head

Cat (TAC): Forward (reverse) display

Cat [OPTION] ... [FILE] ...

-E: Display line terminator $
-N: Numbering each line displayed

More [OPTIONS ...] FILE ...

Features: Turn the screen to the end of the file automatically exit;

-D: Show page flipping and exit tips
Space: Page Down
Enter: Turn down one line
B,ctrl+b: Turn Back Page
/string: Query the string down
Q: Leave

Less: one page, one page flip screen

Less[options ...] FILE ...

Usage:

Space,ctrl+v PAGE Down
b ctrl+b turn the screen to the file header
D ctrl+d half-screen to the tail of the file
U ctrl+u turn half screen to file header

Enter: Flip a line to the file header

Ctrl+k: Flip a line to the file header
Q: Exit
# Jump to # # line
1 g: Back to File header
G: Back to file tail

Head: View Front # lines (default 10 lines)

Head [OPTIONS ...] [FILE ...]

-N #: Specifies the first # line to get
-#: Specifies the first # line to get

Tail: View the following # lines (default 10 lines)

Tail[options ...] [FILE ...]

-N #: Specifies the # line after fetch
-#: Specifies the # line after fetching
-F: View file to tail not exit, continue to observe the contents of the file.

File management tools: CP, MV, RM

CP NAME

cp-copy Files and directories

CP command: Copy source file; target file;

Single source copy: CP [OPTION] ... [-T] SOURCE DEST
Multi-source replication: CP [OPTION] ... SOURCE ... DIRECTORY
CP [OPTION] ...-t DIRECTORY SOURCE ...

Single source copy: CP [OPTION] ... [-T] SOURCE DEST
If Dest does not exist: The file is created in advance and the data stream of the source file is copied to dest;
If dest exists:
If the dest is a non-directory file: overwrite the target file;
If Dest is a directory file: first create a file with the same name as the source file in the Dest directory and copy its data stream;

Multi-source replication: CP [OPTION] ... SOURCE ... DIRECTORY
CP [OPTION] ...-t DIRECTORY SOURCE ...

If the dest does not exist: error;
If dest exists:
If Dest is a non-directory file: error;
If Dest is a directory file: Copy each file to the target directory separately and keep the original original;

Common options:
-I: Interactive replication, that is, before overwriting to remind users to confirm;
-F: Force overwrite the target file;
-R,-r: recursive copy directory;
-D: Copies the symbolic link file itself, not the source file it points to;
-a:-dr--preserve=all, archive, for archiving;
--preserv=mode: Permissions
Ownership: A group of owners and genera
Timestamps: Time stamp
Context: Security label
Xattr: Extended Properties
Links: Symbolic Links
All: All of the above properties

MV Command: Move

MV [OPTION] ... [-T] SOURCE DEST
MV [OPTION] ... SOURCE ... DIRECTORY
MV [OPTION] ...-t DIRECTORY SOURCE:

Common options:

-f:force
RM Command: Remove
RM [OPTION] ... FILE ...

Common options:
-i:interactive
-f:force
-r:recursive
Delete directory: Rm-rf/path/to/dir
Hazardous operation: RM-RF/*

Note: All unused files are recommended not to be deleted directly but moved to a dedicated directory; (simulated Recycle Bin)

File Rights Management Class command Chown,chgrp,umask

Chown command:

chown [OPTION] ... [OWNER] [: [GROUP]] FILE ...
chown [OPTION] ...--reference=rfile FILE ...
Options:
-R: Recursive modification

CHGRP command:

CHGRP [OPTION] ... GROUP FILE ...
CHGRP [OPTION] ...--reference=rfile FILE ...
Note: Only administrators can modify the owner and owner group of the file;

Umask

File permissions reverse mask, mask code; File: 666-umask directory: 777-umask

Note: The file is reduced by 666, which means that the file cannot have Execute permission by default, and if there is execution permission in the result, it needs to be added 1;
umask:023
666-023=644
777-023=754

Umask command:
Umask: View current Umask
Umask MASK: Set umask

Note: This type of setting is only valid for the current shell process;

Text Processing tool Wc,sort,uniq,diff,path

Wc:word count WC [OPTION] ... [FILE] ...

-l:lines

-w:words

-c:bytes

Cut:cut OPTION ... [FILE] ...

-D CHAR: Delimiter with the specified character;
-F Fields: the selected field;
#: Single field specified
#-#: multiple consecutive fields;
#,#: discrete multiple fields;

Sort:sort [OPTION] ... [FILE] ...

-N: Sort based on numeric size instead of characters;
-T CHAR: Specifies the delimiter;
-K #: The field used for sorting comparisons;
-R: Reverse order;
-F: Ignore character case
-U: Duplicate lines retain only one copy;

Uniq: report or remove duplicate rows

Uniq [OPTION] ... [INPUT [OUTPUT]]
-C: Shows the number of repetitions per line;
-U: Displays only rows that have not been duplicated;
-D: Displays only the rows that have been repeated;

Diff:compare Files line by line

diff [OPTION] ... FILES

Diff/path/to/oldfile/path/to/newfile >/path/to/patch_file
-U: Using the unfied mechanism, which displays the context of the row to be modified, the default is 3 rows;

Patch: Patching Files

Patch [OPTIONS]-i/path/to/patch_file/path/to/oldfile

Patch/path/to/oldfile </path/to/patch_file

File content Type View commands: File-determine file type

F: Normal file D: directory file
L: Symbolic Link file
B: Block device files
C: Character device file
P: Pipeline File
S: Socket file

Timestamp management tool for files: Touch,stat

Stat command: Stat-display file or file system status

Stat FILE ...

Files: Two types of data
Meta Data: Metadata
Statistics: Data

Time stamp:
Access time:2015-12-10 16:12:22.776423693 +0800
Modify Time:2015-12-10 16:12:22.776423693 +0800
Change time:2015-12-10 16:12:22.776423693 +0800

Touch command:
Touch-change file Timestamps

Touch [OPTION] ... FILE ...
-C: The specified file path does not exist when not created;--no-create
Do not create any files


-M: Modify modify time only;
-T STAMP
[[Cc]yy] MMDDHHMM[.SS]
Date format when time is set: Date [MMDDHHMM[[CC]YY][.SS]]

2.bash working characteristics the command execution status return value and command-line expansion are involved in the content and its examples demonstrate the underlying features of bash: command execution status results

Status result of the command execution:
Bash outputs this result with a status return value:
Success: 0
Failed: 1-255

After the command execution completes, its status return value is saved in Bash's special variable $?

Bash's underlying features: command line expansion ~: Automatically expands to the user's home directory, or the specified user's home directory;

{}: A comma-delimited list of paths can be hosted and can be expanded to multiple paths;
For example:/tmp/{a,b} is equivalent to/tmp/a/tmp/b

Use the command line expansion feature to complete the following exercises:

    1. (1), create the/tmp directory under: A_c, A_d, B_c, B_d mkdir/tmp/{a,b}_{c,d} (2), create/tmp/mylinux directory: mylinux/├──bin├──boot│└──grub├─ ─dev├──etc│├──rc.d││└──init.d│└──sysconfig│└──network-scripts├──lib│└──modules├──lib64 ├──proc├──sbin├──sys├──tmp├──usr│└──local│├──bin│└──sbin└──var├──lock├──log└──run

[Email protected] ~]# mkdir-pv/tmp/mylinux/{bin,boot/grub,dev,etc/{rc.d/init.d,sysconfig/network-scirpts},lib/ Modules,lib64,proc,sbin,sys,tmp,usr/{local,bin,sbin},var/{lock,log,run}}

4, what is the metadata information of the file, what does it mean, how to view it? How to modify timestamp information for a file.

Files: Two types of data
Meta Data: Metadata
Statistics: Data

A. The metadata of a file refers to the file's attributes, size, creation time, access time, and other information that belongs to the main group.

B. Three timestamps:

Access time: Atime, read and write file contents


Change time: Changing times, ctime, meta data changes

C. Time stamp to modify a file: Touch

Touch [OPTION] ... FILE ...

-a:only Atime

-m:only Mtime

You cannot modify CTime individually, whether you modify access time or modify Time,change time always changes

-S STAMP [[CC]YY]MMDDHHMM[.SS]

-C: If the file does not exist, it is not created

5, how to define the alias of a command, how to reference the execution result of another command in the command? 1. Command aliases: Alias

Alias: Displays all the available command aliases for the current shell process alias name= "VALUE": Named aliases

Note: Aliases defined on the command line are valid only for the current shell process, and if you want to permanently work, define the configuration file

For the current user only: ~/.BASHRC

Valid for all:/ETC/BASHRC

To reference the execution result of another command in a command: Typically, the output of the previous command is used as input to another command with the help of a pipeline.

[Email protected] ~]# CAT/ETC/PASSWD | Wc-l

[[email protected] ~]# 43

6. Display all files or directories in the/var directory that start with L, end with a lowercase letter, and have at least one digit (can have other characters) appear in the middle.

[[email protected] ~]# ls-d/var/l*[[:lower:]]

7. Displays files or directories that start with any number in the/etc directory and end with a non-numeric number.

[Email protected] ~]# ls-d/etc/[[:d igit:]]*[^0-9]

8, Show/etc directory, start with a non-letter, followed by a letter and any other arbitrary length of any character file or directory.

[Email protected] ~]# ls-d/etc/[^a-z][a-z]*

9. In the/tmp directory, create a file that starts with Tfile, followed by the current date and time, with a filename such as: tfile-2016-05-27-09-32-22.

~] #touch "tfile- date +%F-%H-%M-%S "

10. Copy all the files or directories in the/etc directory to the/tmp/mytest1 directory that begin with P and do not end with a number. [Email protected] ~]# mkdir/tmp/mytest1 [[email protected] ~]# cp-r/etc/p*[^0-9]/tmp/mytest1/

11. Copy all files or directories ending with. D in the/etc directory into the/tmp/mytest2 directory.

[Email protected] ~]# MKDIR/TMP/MYTEST2 [[email protected] ~]# cp-r/etc/*.d/tmp/mytest2

12. Copy all files in the/etc/directory that begin with L or M or N and end with. conf to the/TMP/MYTEST3 directory.

[Email protected] ~]# MKDIR/TMP/MYTEST3 [[email protected] ~]# cp-r/etc/[1,m,n]*.conf/tmp/mytest3


Several examples of Linux file Management command summary and wildcard

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.