command usage and some small exercises for Linux files

Source: Internet
Author: User

1. What are the file management commands on Linux, their common use methods and their related display columns;

Cat: Show open files

-N: Number of rows for all outputs

-B: And-similar, but not for blank lines


TAC: In response to connection and printer



Head: Part of the output file


Tail: The last part of the output file


Less: Show headers and tails to flip to view

-N: Number of rows that can be specified


MORE: Show headers and tails to flip to view


Touch: Creating files (creating files is more secure)

-A: Change atime only

-M: Change Mtime only

-C: Do not create empty files


Stat: Displays metadata for a file

Time stamp:

Atime

Mtime

CTime


PWD: Displays information about the directory in which it resides


CD: Switch directories



CP: Copying Files and directories

-A: You can keep links, file attributes,

-D: Keep links when copying

-F: Directly overwrite the existing directory without prompting

-I: Exactly the opposite of-F

-r: Can copy all subdirectories and files under directory

-L: Do not copy files, just generate linked files

Copy files to/testdir/rootdir/to save root permissions and all subdirectories


MV: Change the name of the file

-I: Interactive

-F: Mandatory




RM: Deleting files

-I: Interactive

-F: Force delete

-F: Recursive


RmDir: Delete Empty directory

-P: Subdirectories are deleted and will become empty directories directly deleted



Echo: Echoing


2. Bash's work characteristics the command execution status return value and command line expansion are related to the contents and the presentation of the following columns;

Features of bash: command history

Save 1000 By default

Environment variable: histsize

Usage:

History: View Historical

-C: Clear command history

-D: Delete the specified entry

-A: Writes the current session's command history into the specified file


Features of BASH: Command completion (TAB)

Find commands that start with a user-specified string based on the lookup method of the built-in or external command

TAB key to complete the command two times tab to display the beginning of the specified string command

Features of bash: path completion:

Two Times Tab key


Features of bash: command line expansion

~: User Directory

~: Specify the user's home directory


Features of bash: input, output redirection, and piping


Output redirection:

COMMAND > POSITION: Overwrite output

COMMAND >> POSITION: Append output

Error redirection:

COMMAND 2> POSITION: Overwrite output

COMMAND 2>> POSITION: Append output

Merge redirection:

COMMAND &> POSITION

COMMAND > POSITION 2> &1

REDIRECT Separately

COMMAND > Postiion 2> POSTION2

Enter redirection:

COMMAND < POSITION



3, use the command line to expand the function to complete the exercise;


Create the/tmp/mylinux directory under the

mylinux/

Bin

Boot

Grup

Dev

etc

Rc.d

Init.d

Sysconfig

Network-scripts

Lib

Modules

Lib64

Proc

Sbin

Sys

Tmp

Usr

Local

Bin

Sbin

Var

Lock

Log

Run

Mkdir-pv/testdir/mylinux/{bin,boot/grup,dev,etc/{rc.d/init.d,sysconfig/network-scripts},lib/modules,lib64,proc , Sbin,sys,tmp,usr/loacl/{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

Stat: Used to display inode content

Atime

Mtime: Changes in data

CTime: meta-data changes


Touch change files Atime and Mtime

-A: Change atime

-M: Change Mtime

-C: Do not create empty files


Command aliases and command references for bash features:

Alias

Alias Alias=command


When aliases have the same name as the command:

Absolute path

\command

Effective Scope: The alias of the command line definition, which takes effect from the current session;

Unalias [ALIAS]

-A: Undo all aliases

References for bash support:

‘‘

""

": Reference to the execution result of a command

$()



BASH features filename wildcard (globbing):

*: Any character of any length

P*d, pad, PBD, PD

*ab*c

?: Match any single character

[]: matches any single character in the specified range

[ABC], [A-z], [0-9], [0-9a-z]

[^]: matches any single character outside the specified range

[^0-9a-z]


Character Set:

[[: Space:]]: all whitespace characters

[[:p UNCT:]]: All punctuation

[[: Lower:]]: All lowercase letters

[[: Upper:]]: Any size letter

[[:d Igit:]]: Any number, equivalent to 0-9

[[: Alnum:]]: any number or letter

[[: Alpha:]]: Any case letter


5, how to define the alias of a command, how to reference the execution result of another command in the command?

Alias: Aliases for setting directives

Grammar

alias[alias]=[directive name]

# alias Lx=ls

#lx

Root user-defined aliases:

/ETC/BASHRC: Valid for all users

Normal User:

. BASHRC: Valid only for yourself


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

ls/var/l*[[:d Igit:]]*[[:lower:]]


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

# ls-ld/etc/[0-9]*[^[:d igit:]]


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

# ls-ld/etc/[^[:upper:]]*[[:upper:]]*


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

# mkdir-pv/tmp/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

# cp/etc/p*[^[:d igit:]]/tmp/mytest1


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

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

Mkdir-p/tmp/mytest3*

Cp/etc/[lmn]*.conf




This article from the "Linux" blog, reproduced please contact the author!

command usage and some small exercises for Linux files

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.