Linux First Knowledge Two

Source: Internet
Author: User
Tags aliases touch command

1. Common file management commands and usage on Linux
  • (1)CP Command:Copy a file or folder
    Syntax Format
           cp [OPTION]... [-T] SOURCE DEST            // 单源复制          cp [OPTION]... SOURCE... DIRECTORY         //多源复制
    Common Options
           -i,--interactive:交互式复制,如果要复制的目标文件存在,在覆盖之前提醒用户确认;       -f,--force:强制覆盖目标文件;       -r,-R,--recursive:递归复制,复制目录中的子目录;       -d:复制符号连接本身,而不是其指向的源文件;       -a,-dR --preserve=all:archive,用于实现归档;       --preserve=[ARRT_LIST]:复制文件时保留源文件的一些属性 如:mode,ownership, timestamps,context,links,xattr,all
    Note
    ?? When copying a file, if the target is a file, if the file exists, it prompts the user whether to overwrite the target, if the target does not exist, create a file with the same name as the source file, and copy the content, if the target is a directory, if the target directory does not exist, it will prompt the error, if the target directory exists, A file with the same name as the source file is created in the target directory and the contents of the file are copied in.
    Example
    [root @localhost ~]# cp/etc/fstab/tmp/ Fstab.bak //single source copy [Root @localhost ~]# cp/etc/fstab/e tc/passwd/tmp/test///multi-source replication      
  • (2)   mv command: move or rename file
    syntax format
     MV [ Option] ... [-t] SOURCE DEST mv [option] ... SOURCE ... Directory mv [Option]     
    Common options
    -f,--force: Forced Move, Do not prompt when overwriting;-i,--interactive: Prompt when overwriting;    
    Example
    [root @localhost ~]# mv Fstab Fstab.bak 
           
            //renamed [Root
             @localhost ~]# mv Fstab.bak./test///move   
              
  • (3) RM command: Delete files or directories
    Syntax format
           rm [OPTION]... FILE...
    Common options
           -f,--force:强制删除,不管文件存不存在都不提示;       -i,每删除一个文件都询问是否删除;       -r,-R,--recursive:递归删除,删除目录及子目录;
    Example
    [root@localhost ~]# rm  -r ./test/             //删除目录
2. Bash working features
  • (1) Command execution status return value
    ?? Will the shell program save the last command that was run and the return value of the function in $? This particular variable, can we view $? Value to confirm that the last command was executed successfully. Successful execution returns 0, and failure returns a number between 1~255.
    <br/>
    Note:The result of the execution state of the command and the execution result of the command is two different concepts, for example, the LS command, when we execute it, it may have a status result of 1, and its execution result is to list the files in the current directory.
    Example
    [root@localhost tmp]# lsinit.d  mylinux  scripts[root@localhost tmp]# echo $?0[root@localhost tmp]# lss-bash: lss: command not found[root@localhost tmp]# echo $?2
    ?? In addition, we can refer to the execution result of the command, using $ (command) or ' (command) ', such as when we want to create a directory based on the current time:
    [[email protected] ~]# mkdir $(date +H%-%M-%s)
  • (2) Command line expansion
    ?? Some special characters can be used in bash to represent a parameter string in a command.

           ~ :用户的家目录;       ~USERNAME:指定用户USERNAME的家目录;       {} :可以指定一个以逗号分隔的路径列表。

    Example

    [root@localhost ~]# cd  ~                        //切换至当前用户的家目录[root@localhost ~]# cd  ~Syuan                   //切换至Syuan的家目录[root@localhost ~]# rm /tmp/{a,b} //删除tmp目录下的a和b文件

    Application

    Ⅰ Create the A_c,a_d,b_c,b_d file in the/tmp directory;

    [root@localhost ~]# touch /tmp/{a,b}_{c,d}

    Ⅱ 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
    [root@localhost ~]# mkdir -pv /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}}[root@localhost ~]# tree /tmp/mylinux
3. Meta-data information for files

?? The data of a file can be divided into two categories, one is metadata (Matedata), which is used to record the property information of a file, such as size, type, permission, genus, timestamp, etc. The other is data, which records the contents of a file. On a Linux system, we can view the status of a file or file system through the Stat command.
Example

[[Email protected] ~]# Stat Functions File: ' Functions ' Size:13948 Blocks:IO Block:4096 regular filedevice:fd00h/64768d Inode:202424773 Links:1Access: (0644/-rw-r--r--) Uid: (0/root) Gid: (0/root) Context:unconfined_u:object_r:admin_home_t:s0access: 2016- 11-24  17: 48:04.752152528 +0800Modify: 2016-11-24 17 : 47:23.900148636 +0800Change: Span class= "Hljs-number" >2016-11-24 17:47:23.900148636 +0800 Birth:-            

?? We can also use commands to change some of the metadata information for a file, such as permissions, genus, timestamps, and so on. Here's a look at the command touch to change the file timestamp.
Touch Command : Modifies the timestamp of the file and creates an empty file when the file does not exist.

Syntax format

            touch [OPTION]... FILE...

Common options

            -a:仅修改访问时间;            -c:文件不存在是不创建;            -m:仅修改修改时间;            -t STAMP:指定时间而不是使用当前的时间,格式[[CC]YY]MMDDhhmm[.ss]

Example

[[email protected] ~]# ll functions -rw-r--r--. 1 root root 13948 Nov 24 17:47 functions[[email protected] ~]# touch functions [[email protected] ~]# ll functions -rw-r--r--. 1 root root 13948 Dec 11 05:27 functions
4. Aliases for commands

?? On a Linux system we can define an alias for the command's common options, which is equivalent to using a specific option for this command. This is very handy for use with aliases when it's very long or a lot of special options for this command. Aliases are defined on a Linux system using the alias command, which is an inline command of the shell.
Alias command : Define or display aliases
Syntax format

            alias [name[=value] ... ]

Alias displays all aliases defined on the system without parameters.
Example

[root@localhost ~]# alias clear=‘clr‘

Note : Aliases defined with the alias command are valid only for the current shell process, and when a system restart defines an alias that does not work, you can edit the ~/.bashrc file to make the defined alias permanent. In addition, the unalias command can be used to revoke the definition of an alias.

Linux First Knowledge Two

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.