Linux second week jobs

Source: Internet
Author: User
Tags control characters parent directory

1. What are the file management commands on Linux, their commonly used methods and their related examples?

The Linux file management class commands include

View class: Cat,more,less

Edit class: Nano,vim

Other classes: MKDIR,RMDIR,RM,CP,MV

Cat

Description: Connect the file and print it on standard output

Format: Cat [OPTION] ... [FILE] ...

Option:-N Prints the contents of the file without wrapping.

-A print all the control characters in the file

Example: Cat-n test.txt

More

Description: Text file view filter (default by Space, Z page)

Format: more [OPTION] [-num] [+/pattern] [+linenum] [FILE ...]

Options:-num #指定每次翻页 (knocking spaces) The number of lines displayed

Ex:more-2 Mytest.txt #每敲一次空格显示3行内容

-S #将文本中连续的空行合并为一行

+/pattern #在文本显示前, filter the required keywords

Ex:more +/serverroot/etc/httpd/conf/httpd.conf

#显示apach配置文件中关键字ServerRoot所在行
+linenum #从文本第N行显示内容

Less

Description: Similar to more features, provides additional reverse movement for document viewing

Format: Less[file]

Nano

Description: Text view Editing Tool

Format: Nano [FILE]

Usage: ctrl+o Save ctrl+r Read new file ctrl+x exit Ctrl+w query Ctrl + V next page ctrl+y previous page

The specific usage can be seen below the Nano interface.

Vim

Description: Text View Editor

Format: Vim [options] [File ...]

Usage:

switching between different modes

Normal mode input I enter text editing mode, enter: Enter the command line mode. Press ESC in text-editing mode and command-line mode to return to normal mode.

commands in normal mode

1) n,my from N-line to M-line copy

2) U undo Last Action

3) GG moves to the first line of the buffer

4) G move to the last row of the buffer

5) Num G moves to the specified line

6) m undo the previous operation

7) DD Delete when moving forward

8) P Paste

9) yw copy words

y$ copy Entire row


Command mode command

1) Wq Save exit

2) wq! Force Save exit

3) q! Force quit does not save

4) Set NU display line number

mkdir

Description: Creating a directory, by default the parent directory must exist to create subdirectories

Format: mkdir [OPTION] ... DIRECTORY ...

Option:-p to create a directory at the same time, if the parent directory does not exist, create the parent directory

rmdir

Description: Delete an empty directory

Format: [OPTION] ... DIRECTORY ...

Option:-p to delete the directory at the same time, delete its parent directory, must be empty!

RM

Description: Delete a file

Format: RM [OPTION] ... FILE ...

Option:-RR Delete a directory and delete the files in the directory

-F Force Delete without prompting for any information

CP

Description: Copying files

Format: CP [OPTION] ... SOURCE ... DIRECTORY

Option:-I.

–r Copying the entire folder recursively

–l Create a hard link when you need to overwrite a file

–s Creating a soft link

-A preserves all properties of the source file

# # #ownship ( owner ), Mode(permission), timestamp(timestamp)Context(security context), link (link property), Xattr(extended property)

- p only retains ownship,mode,timestamp


Mv:

Description: Move (rename) file

Format: MV [OPTION] ... SOURCE ... DIRECTORY

Option:-I prompt to overwrite files

-F Overlay does not prompt


2. Bash's work characteristics the command execution status return value and command line expansion are involved in the content and its sample demonstration.

The execution of the Bash command results in a return value, saved in $0, or a number between 1-255 if the program performs normally.

echo $? You can print the return value of the command execution to the standard output, but remember to execute it immediately after the command has been executed.


3. Use the command line expansion function to complete the following exercises:

(1), create/tmp directory: A_c, A_d, B_c, B_d

MKDIR/TMP/{A,B}_{C,D}


(2), create the/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

Mkdir-p/tmp/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}


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.

the metadata for the file includes ownship ( owner ), Mode(permission), timestamp(timestamp) context(security context), link (link property), Xattr(extended property)

The Stat command allows you to view the file's system properties, stat/etc/issue

File: '/etc/issue ' #文件路径

size:47 blocks:8 IO block:4096 Regular file #大小, data block information

device:803h/2051d inode:393478 links:1 #所在设备, Inode and link info

Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) #权限位, belonging to and belonging to the group

ACCESS:2016-07-13 17:42:48.520712501 +0800 #访问时间

modify:2013-11-27 19:53:33.000000000 +0800 #修改时间

change:2016-07-12 00:22:56.583999905 +0800 #更改时间

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

Alias aliases = ' COMMADN + parameters [+ files] '

command can be used to reference the execution result


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-l/var/1*[0-9]*[a-z]

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

Ls-l/etc/[0-9]*[^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.

ls/etc/[^a-za-z][a-za-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-08-06-09-32-22.

touch/tmp/tfile-' Date +%y-%m-%d-%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*[^0-9]/tmp/mytest1/

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

cp/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.

cp/etc/{1,m,n}*.conf/tmp/mytest3/


Linux second week jobs

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.