5 Linux file directory management command

Posted by fullyloaded on Mon, 27 Dec 2021 17:27:45 +0100

catalogue

1. touch command

2. mkdir command

3. cp command

4. mv command

5. rm command

6. dd command

7. file command

1. touch command

touch The command is used to create a blank file or set the time of the file in the format“ touch [ option ] [ file ] ".
In creating a blank text file, this touch The command is quite simple, for example, touch linuxprobe Command can create a file named linuxprobe A blank text file. yes touch In terms of command, the difficult operation is mainly reflected in setting the modification time (mtime) of file content )Change time of, file permissions or attributes (ctime) )And file read time( atime )Above. touch The parameters and functions of the command are shown in the table below 2-11.
[root@linuxprobe ~]# ls -l anaconda-ks.cfg 
-rw-------. 1 root root 1213 May 4 15:44 anaconda-ks.cfg 
[root@linuxprobe ~]# echo "Visit the LinuxProbe.com to learn linux skills" >> 
anaconda-ks.cfg 
[root@linuxprobe ~]# ls -l anaconda-ks.cfg 
-rw-------. 1 root root 1260 Aug 2 01:26 anaconda-ks.cfg 
[root@linuxprobe ~]# touch -d "2017-05-04 15:44" anaconda-ks.cfg 
[root@linuxprobe ~]# ls -l anaconda-ks.cfg 
-rw-------. 1 root root 1260 May 4 15:44 anaconda-ks.cfg

2. mkdir command

mkdir The command is used to create a blank directory in the format“ mkdir [ option ] Directory.

In Linux system, folder is one of the most common file types. In addition to creating a single blank directory, the mkdir command can also recursively create a file directory with nested stack relationship in combination with the - p parameter.

[root@linuxprobe ~]# mkdir linuxprobe 
[root@linuxprobe ~]# cd linuxprobe 
[root@linuxprobe linuxprobe]# mkdir -p a/b/c/d/e 
[root@linuxprobe linuxprobe]# cd a 
[root@linuxprobe a]# cd b 
[root@linuxprobe b]#

  

3. cp command

The cp command is used to copy files or directories in the format "cp [options] source file destination file". You should be familiar with file copying. In Linux system, copying can be divided into three situations:

  • If the destination file is a directory, the source file is copied to that directory
  • If the target file is also a normal file, you are asked if you want to overwrite it
  • If the target file does not exist, perform the normal copy operation

    Next, use touch to create a file called install Log, and then copy it into a backup file named x.log. Finally, use the ls command to view the files in the directory:

    [root@linuxprobe ~]# touch install.log 
    [root@linuxprobe ~]# cp install.log x.log 
    [root@linuxprobe ~]# ls 
    install.log x.log

4. mv command

mv The command is used to cut or rename a file in the format“ mv [ option ] source file [ Target path | Destination file name ] ".
The cut operation is different from the copy operation, because it will delete the source file by default and only keep the cut file. If you cut a file in the same directory, you are actually renaming it:
[root@linuxprobe ~]# mv x.log linux.log 
[root@linuxprobe ~]# ls 
install.log linux.log

5. rm command

rm Command to delete a file or directory in the format“ rm [ option ] File.
stay Linux When deleting a file in the system, the system will ask you whether to delete it by default. If you don't want to always see this repeated confirmation information, you can click rm Command followed by -f parameter to force deletion . In addition, you need one after the rm command - r parameter to delete a directory Otherwise, it cannot be deleted. Let's try to delete the previously created install Log and Linux log File:
[root@linuxprobe ~]# rm install.log 
rm: remove regular empty file 'install.log'? y 
[root@linuxprobe ~]# rm -f linux.log 
[root@linuxprobe ~]# ls 
[root@linuxprobe ~]#

6. dd command

dd Command is used to copy or convert files according to the specified size and number of data blocks. The format is“ dd [ parameter ] ".
dd Command is an important and characteristic command. It allows users to copy the contents of files according to the specified size and number of data blocks. Of course, if you like, you can also convert the data during the replication process. There is a file named / dev/zero in the Linux system Every time I explain it in class, it is full of the color of philosophical theory. Because this file does not occupy the system storage space, but can provide endless data, it can be used as the input file of the DD command to generate a file of a specified size. dd The parameters and functions of the command are shown in table 2-13.

For example, we can use the dd command to take a 560MB data block from the / dev/zero device file and save it as 560MB_ File. After understanding this command, you can create files of any size at will:

[root@linuxprobe ~]# dd if=/dev/zero of=560_file count=1 bs=560M 
1+0 records in 
1+0 records out 
587202560 bytes (587 MB) copied, 27.1755 s, 21.6 MB/s
dd The function of the command is not limited to copying files. If you want to make the disc in the optical drive device into iso grid
Image file, in Windows The system needs the help of third-party software, but in Linux The system can directly
use dd Command to suppress the CD image file and program it into an immediately usable iso Mirror image:
[root@linuxprobe ~]# dd if=/dev/cdrom of=RHEL-server-7.0-x86_64-LinuxProbe.Com.iso 
7311360+0 records in 
7311360+0 records out 
3743416320 bytes (3.7 GB) copied, 370.758 s, 10.1 MB/s
Considering that friends will tangle bs Block size and count For the relationship between the number of blocks, the following is an example of eating goods
Explain. Suppose Xiao Ming's appetite (i.e. demand) is a fixed value, and the size of the spoon used to hold rice is bs Block size, and the number of times to serve with a spoon is count Number of blocks. If Xiao Ming wants to be full (meet the demand), he needs to be the size of a spoon( bs block size) and the number of times (count) of serving rice with a spoon Number of blocks). The larger the spoon, the fewer times it is used to serve rice. Visible on the, bs And count They are used to specify the capacity. As long as they can meet the demand, they can be combined and matched at will.

7. file command

file The command is used to view the type of file in the format“ file File name.
stay Linux In the system, text, directory, equipment, etc. are all collectively referred to as files, and we can't know the specific file type just by the suffix. In this case, we need to use file Command to view the file type.
[root@linuxprobe ~]# file anaconda-ks.cfg 
anaconda-ks.cfg: ASCII text 
[root@linuxprobe ~]# file /dev/sda 
/dev/sda: block special

Topics: Linux