Second week homework

Source: Internet
Author: User
Tags touch command

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

Cat, TAC, head, tail, less, cp,mv,stat


Cat [OPTION] ... [FILE] ...
-N: Displays the number of rows
-E: Display line terminator

[Email protected] tmp]# echo "Hello word" >> 333 [[email protected] tmp]# cat 333hello Word

TAC [OPTION] ... [FILE] ...

[[Email protected] tmp]# TAC 333hello Word

Head
Head [OPTION] ... [FILE] ...
-C #: Specify get before # bytes
-N #: Specifies the first # line to get

Rgqgr[[email protected] tmp]# head 333hello Wordwwqdwqdqqwdqdqdqqwdqwddweqdweewfqfqrrfqfrgqeqqtqtrtqtqfreqgrgegqgqqrgqegqeg[[email protected] tmp]# head-c 50 333hello WORDWWQDWQDQQWDQDQDQQWDQWDDWEQDW


Tail
tail [OPTION] ... [FILE] ...
-C #: Specifies the # bytes after fetching
-N #: Specifies the # line after fetch
-F: Trace displays new additions to the file

[Email protected] tmp]# tail 333qwdqdqdqqwdqwddweqdweewfqfqrrfqfrgqeqqtqtrtqtqfreqgrgegqgqqrgqegqegrgqgrgqqgqgqergegqrgqgqg

Cp

[[email protected] tmp]# cp 333 /var/[[email protected] tmp]# ls  /var/333      cache  cvs  empty  gdm   local  log   nis  preserve  spool  wwwaccount   crash  db   games  lib  lock   mail   opt  run       tmp    yp[[email  protected] tmp]# ls333                   orbit-cpl                   virtual-cpl.grFf4obin                   orbit-gdm                   virtual-cpl.hCmppH                       x

MV

[[EMAIL PROTECTED] TMP]# MV 333 /ETC/[[EMAIL PROTECTED] TMP]# LS1                      mytest1                     virtual-cpl.13la231.txt                 mytest2                     virtual-cpl.7tcqgK2                     mytest3                      virtual-cpl.f57ji7[[email protected] tmp]# ls /etc/333                       hp                              printcapabrt                      httpd                           profileacpi                      idmapd.conf                    profile.d

Stat

[[Email protected] etc]# Stat 333 file: "333" size:122 blocks:8 IO block:4096 Common Files device:fd00h/ 64768d inode:533803 links:1access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) access:2016- 08-14 01:02:40.350008585 +0800modify:2016-08-14 01:02:12.210008511 +0800change:2016-08-14 01:08:54.439008241 +0800


2. Bash's work characteristics the command execution status return value and command line expansion are involved in the content and its sample demonstration.
Bash uses a special variable $? Save the execution status result of the most recent command

0: Success

1-255: Failure

[[email protected] ~]# Pwd/root[[email protected] ~]# echo $?0[[email protected] ~]# Le-bash:le:command not Found[[email Protected] ~]# echo $?127


Command line expansion
~: Expand to the user's home directory
~username: Expand the home directory for the specified user
{}: Can host a comma-delimited list and expand it to multiple paths (multiplication by polynomial)

[Email protected] ~]# LS/TMP/{1,2}/TMP/1:/TMP/2:



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

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

[[email protected]/]# mkdir {a,b}_{c,d}


(2), create the/tmp/mylinux directory:

[[Email protected] tmp]# mkdir -pv mylinux/{bin,boot/grb,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:   Created directory   "Mylinux" mkdir:  created directory   "Mylinux/bin" mkdir:  created directory   "Mylinux/boot" mkdir:   Created directory   "MYLINUX/BOOT/GRB" mkdir:  created directory   "Mylinux/dev" mkdir:  created directory   "MYLINUX/ETC" mkdir:  created directory   "MYLINUX/ETC/RC.D" mkdir:  created directory   "MYLINUX/ETC/RC.D/INIT.D" mkdir:  created directory   "Mylinux/etc/sysconfig" mkdir:  created directory   "mylinux/etc/sysconfig/network-scripts" mkdir:  created directory   "Mylinux/lib" mkdir:  created directory   "Mylinux/lib/modules" mkdir:  created directory   "mylinux/lib64" mkdir:   Created directory   "Mylinux/proc" mkdir:  created directory   "Mylinux/sbin" mkdir:  created directory   "Mylinux/sys" mkdir:   Created directory   "mylinux/tmp" mkdir:  created directory   "MYLINUX/USR" mkdir:  created directory   "Mylinux/usr/local" mkdir:  created directory   Mylinux/usr/locAl/bin "mkdir:  created directory  " Mylinux/usr/local/sbin "mkdir:  created directory  " Mylinux/var "mkdir:  created directory   "Mylinux/lock" mkdir:  created directory   "Mylinux/log" mkdir:  created directory   "Mylinux/run" [[email  protected] tmp]# tree mylinux/mylinux/├── bin├── boot│ └── grb├──  dev├── etc│ ├── rc.d│ │ └── init.d│ └── sysconfig│      └── network-scripts├── lib│ └── modules├── lib64├── lock├──  log├── proc├── run├── sbin├── sys├── tmp├── usr│ └── local│      ├── bin│     └── sbin└── var24  Directories, 0 files



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: Made up of metadata and data
Meta Data: Metadate
Statistics: Data
Stat: View metadata information for a specified file

Stat [OPTION] ...          File ...-l: Support for symbolic connection-F: Show filesystem status instead of file status-T: Output information in a concise manner [email protected] tmp]# stat mylinux/file: "mylinux/" size:4096  Blocks:8 IO block:4096 directory device:fd00h/64768d inode:803023 links:17access: (0755/drwxr-xr-x) Uid: (0/root) Gid: (0/root) access:2016-08-13 17:21:16.000000000 +0800modify:2016-08-13 17:16:42.00000 0000 +0800change:2016-08-13 17:34:05.984017941 +0800

File: Name

Size: File size

Blocks: Block

IO Blocks:io Block

Device: File information

Links: Number of hard links

Access: File permissions

Access: Last Accessed time

Modify: Last Change time

Change: Last Modified Time


Touch command:
-A: Modify access time (Atime)
-M: Modification Time (Mtime)
-C: If the file does not exist, it is not created


            three timestamps:
             access time: atime, read file contents
             Modify Time: Modified, Mtime, change file contents (data)
             Change Time: Changes CTime, meta data changes

[[email protected] tmp]# touch-a mylinux/[[email protected] tmp]# stat mylinux/file: "mylinux/" size:4096 Bl    Ocks:8 IO block:4096 directory device:fd00h/64768d inode:803023 links:17access: (0755/drwxr-xr-x) Uid: ( 0/root) Gid: (0/root) access:2016-08-14 00:43:50.305009878 +0800modify:2016-08-13 17:16:42.000000000 +08 00change:2016-08-14 00:43:50.305009878 +0800

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

(1) Alias

Displays all command aliases available in the current shell process

(2) Alias Name= ' VALUE '

Defines the name of the alias, which is equivalent to executing the command value

Attention:

After the definition is only valid for the current shell process, want to be permanently effective, to be defined in the configuration file;

[[email protected] ~]# alias cdnet= ' cd/tmp ' [[email protected] ~]# Cdnet[[email protected] tmp]#


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*[0-9]*[[: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/[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.

[Email protected] ~]# ls-d/etc/[^[:alpha:]][[:alpha:]]*


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.

[[email protected]/]# Touch tfile-$ "(Date +%f-%h-%m-%s)"

Or

[[email protected]/]# 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&&cp-a/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] tmp]# mkdir/tmp/mytest2&&cp-a/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] tmp]# mkdir/tmp/mytest3&&cp-a/etc/[l,m,n]*.conf/tmp/mytest3

Or

[Email protected] tmp]# mkdir/tmp/mytest3&&cp-a/etc/[lmn]*.conf/tmp/mytest3


Second week homework

Related Article

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.