Linux base - file management commands

File management commands:

  1. touch: 创建或更新文件时间
    创建文件
    [root@bogon ssx-linux]# touch file{1..6}
    [root@bogon ssx-linux]# ls
    a b c d e file1 file2 file3 file4 file5 file6
    [root@bogon ssx-linux]# touch file{a,b,c}
    [root@bogon ssx-linux]# ls
    a b c d e file1 file2 file3 file4 file5 file6 filea fileb filec
    [root@bogon ssx-linux]# rm -f file{a..c}
    [root@bogon ssx-linux]# ls
    a b c d e file1 file2 file3 file4 file5 file6
    [root@bogon ssx-linux]# touch file{a..z}
    [root@bogon ssx-linux]# ls
    a c e file2 file4 file6 fileb filed filef fileh filej filel filen filep filer filet filev filex filez
    b d file1 file3 file5 filea filec filee fileg filei filek filem fileo fileq files fileu filew filey
    [root@bogon ssx-linux]#

        ***更新文件时间***

    [root@bogon ssx-linux]# ll
    total 0
    drwxr-xr-x 3 root root 15 Feb 1 06:41 a
    drwxr-xr-x 2 root root 6 Feb 1 06:41 b
    drwxr-xr-x 2 root root 6 Feb 1 06:41 c
    drwxr-xr-x 2 root root 6 Feb 1 06:41 d
    drwxr-xr-x 2 root root 6 Feb 1 06:41 e
    -rw-r--r-- 1 root root 0 Feb 1 07:08 file1
    -rw-r--r-- 1 root root 0 Feb 1 07:08 file2
    -rw-r--r-- 1 root root 0 Feb 1 07:08 file3
    -rw-r--r-- 1 root root 0 Feb 1 07:08 file4
    -rw-r--r-- 1 root root 0 Feb 1 07:08 file5
    -rw-r--r-- 1 root root 0 Feb 1 07:08 file6
    [root@bogon ssx-linux]# touch file{1..6}
    [root@bogon ssx-linux]# ll
    total 0
    drwxr-xr-x 3 root root 15 Feb 1 06:41 a
    drwxr-xr-x 2 root root 6 Feb 1 06:41 b
    drwxr-xr-x 2 root root 6 Feb 1 06:41 c
    drwxr-xr-x 2 root root 6 Feb 1 06:41 d
    drwxr-xr-x 2 root root 6 Feb 1 06:41 e
    -rw-r--r-- 1 root root 0 Feb 1 07:12 file1
    -rw-r--r-- 1 root root 0 Feb 1 07:12 file2
    -rw-r--r-- 1 root root 0 Feb 1 07:12 file3
    -rw-r--r-- 1 root root 0 Feb 1 07:12 file4
    -rw-r--r-- 1 root root 0 Feb 1 07:12 file5
    -rw-r--r-- 1 root root 0 Feb 1 07:12 file6
    [root@bogon ssx-linux]#

  2. stat
    [root@bogon ssx-linux]# stat file6
    File: ‘file6’
    Size: 0 Blocks: 0 IO Block: 4096 regular empty file
    Device: fd00h/64768d Inode: 18796551 Links: 1
    Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
    Access: 2019-02-01 07:12:12.448044258 +0800
    Modify: 2019-02-01 07:12:12.448044258 +0800
    Change: 2019-02-01 07:12:12.448044258 +0800
    Birth: -
    [root@bogon ssx-linux]# vi file6
    [root@bogon ssx-linux]# stat file6
    File: ‘file6’
    Size: 6 Blocks: 8 IO Block: 4096 regular file
    Device: fd00h/64768d Inode: 18796553 Links: 1
    Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
    Access: 2019-02-01 07:15:25.168046803 +0800
    Modify: 2019-02-01 07:15:25.168046803 +0800
    Change: 2019-02-01 07:15:25.173046803 +0800
    Birth: -
    [root@bogon ssx-linux]#

  3. lrzsz
    --yum install -y lrzsz

- Upload
rz -E
- After selecting the file you want to upload Enter
sz test.txt
- Select the location to store downloaded files after a carriage return

4.file查看文件类型
[root@wll ~]# file file
file: cannot open (No such file or directory)
[root@wll ~]# file file1
file1: empty
[root@wll ~]# echo "123" > file2
[root@wll ~]# file file2
file2: ASCII text
[root@wll ~]#

The file copy command CP
CP [the OPTION] ... [-T] the SOURCE DEST
CP [the OPTION] ... ... the SOURCE DIRECTORY
CP [the OPTION] ... ... -t DIRECTORY the SOURCE

[root@oldboy ~]# touch {1..3}.txt

// Copy the 1.txt file to the / tmp directory
[root @ oldboy ~] # cp 1.txt / tmp /

2.txt // Copy the file to the / tmp directory to change the name 2.txt.bak (Save As)
[root @ Oldboy ~] # cp 2.txt /tmp/2.txt.bak

// If you want to keep the original copy through the property, -p keep the property original file or directory
[root @ bogon SSx-Linux] # LL file1
-rw-r - r-- 1 root root 0 Feb 1 07:12 file1
[@ bogon SSx the root-Linux] file1 CP # B /
[@ bogon SSx the root-Linux] # LL B
Total 0
-rw-R & lt - r-- the root the root. 1. 1 0 On Feb 07:19 file1
[@ bogon the root SSx -linux] file1 CP C # / -p
[@ bogon SSx the root-Linux] # LL C
Total 0
-rw-R & lt - r-- the root the root. 1. 1 0 On Feb 07:12 file1
[@ bogon SSx the root-Linux] #

// Copy -r parameters only need to use the directory, recursive copy
[the root Oldboy @ ~] # A CP / tmp /
CP: omitting Directory 'A'
[Oldboy the root @ ~] CP # -ra / tmp /

// multiple copies of the same file directory, displays detailed information
[root @ Oldboy ~] # cp -v .txt / tmp /?
'1.txt' -> '/tmp/1.txt'
'2.txt' -> '/tmp/2.txt'
'3.txt' -> '/tmp/3.txt'
'4.txt' -> '/tmp/4.txt'

// mandatory coverage copy files without prompting; because the system at the time of installation, cp - cp alias is I, so cp command absolute path, or to remove the alias effect escape cp
[root @ wll ~] # cp - test.txt findtest RVF /
CP: Overwrite 'findtest / test.txt' Y?
'test.txt' -> 'findtest / test.txt'
[the root @ WLL ~] # Alias
Alias = CP 'CP -i'
Alias egrep = '= egrep --color Auto'
Alias fgrep = 'fgrep --color = Auto'
Alias = grep '= Auto --color grep'
Alias L. = '-d LS. --color * = Auto'
Alias LL = 'LS = Auto --color -l'
Alias = LS 'LS = Auto --color'
Alias Music Videos = 'Music Videos -i'
Alias RM = 'RM -i'
Alias Which = 'Alias | / usr / bin / Which - Alias-only---read -tty --show-DOT --show-tilde are '
[the root WLL ~ @] CP # Which
Alias = CP' CP -i '
/usr/bin/cp
[root@wll ~]# /usr/bin/cp test.txt findtest/
[root@wll ~]# /usr/bin/cp -v test.txt findtest/
‘test.txt’ -> ‘findtest/test.txt’
[root@wll ~]# \cp -v test.txt findtest/
‘test.txt’ -> ‘findtest/test.txt’
[root@wll ~]#

Wildcards:
? Any single wildcard character
* any number of wildcard characters
//

cp -v /etc/hosts /etc/hosts.bak

cp -v /etc/{hosts,hosts.bak}

cp -v /etc/hosts{,.bak}

6. The mobile directory commands Music Videos (cut), rename
Music Videos [the OPTION] ... [-T] the SOURCE DEST
Music Videos [the OPTION] ... ... the SOURCE DIRECTORY
Music Videos [the OPTION] ... -t DIRECTORY the SOURCE ...

// move the file to the tmp directory

mv file /tmp/

// move the file to the tmp directory and change the name to file_test

mv file /tmp/file_test

// move the directory to / tmp catalog

mv you / / tmp /

// move multiple files or multiple directories to the same directory

touch file{1..3}

mv file1 file2 file3 /opt/

mkdir you {1..3}

mv dir1/ dir2/ dir3/ /opt

7. The file directory delete the Remove command RM
RM [OPTION] ... FILE ...
-r recursive
-f Forces deletion
-v detailed process

// delete the file, the default will prompt you whether to delete the file

rm ananassa

// force delete a file, do not remind

rm ananassa -f

// delete directory will remind

rm -r dir /

// force delete directory, do not remind

rm -rf dir /

// Example

mkdir /home/dir10

touch /home/dir10/{file2,file3,.file4}

rm -rf / home / dir10 / * // does not include hidden files

ls /home/dir10/ -a

. .. .file4

// Example 2

touch file{1..10}

touch {1..10}.pdf

rm -rf file*

rm -rf *.pdf

Guess you like

Origin www.cnblogs.com/s-sx/p/11822359.html