Just learn Linux file directory management commands

1、touch

The touch command is used to create a blank file or set the time of the file, the syntax format is "touch [parameter] file name".

In terms of creating blank text files, the touch command is so simple that it doesn't need to be explained. For example, the touch linuxprobe command creates a blank text file named linuxprobe. For the touch command, the difficult operations are mainly reflected in setting the modification time (Mtime) of the file content, the change time (Ctime) of the file permission or attribute, and the access time (Atime) of the file. The parameters and functions of the touch command are shown in the table.
insert image description here
Next, first use the ls command to check the modification time of a file, then modify the file, and finally check the modification time of the file to see if any changes have occurred:

ls -l anaconda-ks.cfg
echo "Visit the LinuxProbe.com to learn linux skills" >> anaconda.cfg
ls -l anaconda-ks.cfg

You can use the touch command to set the modified file time to the time before modification (this is what many hackers do):

touch -d "2020-05-04 15:44" anaconda-ks.cfg
ls -l ananconda-ks.cfg

2、mkdir

The mkdir command is used to create a blank directory, the English full name is "make directory", and the syntax format is "mkdir [parameter] directory name".

In addition to creating a single blank directory, the mkdir command can also be combined with the -p parameter to recursively create a file directory with a nested cascading relationship:

mkdir linuxprobe
cd linuxprobe
mkdir -p a/b/c/d/e
cd a
cd b
cd c

3、cp

The cp command is used to copy files or directories, the English full name is "copy", and the syntax format is "cp [parameter] source file name target file name".

Everyone should be familiar with the file copy operation, which is used almost every day. In the Linux system, the copy operation is specifically divided into three situations:
➢ If the target file is a directory, the source file will be copied to the directory;
➢ If the target file is also an ordinary file, it will ask whether to overwrite it;
➢ If If the destination file does not exist, a normal copy operation is performed.
The copy command is basically error-free, the only thing to remember is to add the -r parameter when copying the directory. The parameters and functions of the cp command are shown in the table.
insert image description here
Next, use the touch command to create a plain blank file called install.log, then copy it as a backup file called x.log, and finally use the ls command to view the files in the directory:

touch install.log
cp intsall.log x.log
ls

4、mv

The mv command is used to cut or rename files, the English full name is "move", and the syntax format is "mv [parameter] source file name target 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 and paste it into the current directory, it means renaming the file:

mv x.log linux.log
ls

5、rm

The rm command is used to delete files or directories, the English full name is "remove", and the syntax format is "rm [parameter] file
name".
When deleting a file in the Linux system, the system will ask you whether you want to perform the delete operation by default. If you don’t want to see this repeated confirmation message all the time, you can add the -f parameter after the rm command to force the delete. In addition, if you want to delete a directory, you need to add a -r parameter after the rm command, otherwise it cannot be deleted. The parameters and functions of the rm command are shown in the table
insert image description here
below. Let’s try to delete the install.log and linux.log files created earlier. Let’s feel the difference between adding and not adding the -f parameter:

rm install.log
rm -f linux.loh
ls

6、dd

The dd command is used to copy or convert files according to the specified size and number of data blocks. The syntax format is "dd if=
parameter value of=parameter value count=parameter value bs=parameter value".

The dd command is a more important and more distinctive command, which allows users to copy the contents of files according to the specified size and number of data blocks. Of course, you can also transform the data in it during the copy process if you wish. There is a device file named /dev/zero in the Linux system, and every time it is explained in class, it is full of philosophical theories. Because this file does not take up system storage space, but can provide endless data, it is often used as the input file of the dd command to generate a file of a specified size. The parameters of the dd command and their functions are shown in the table.
insert image description here
For example, use the dd command to take out a data block with a size of 560MB from the /dev/zero device file, and then save it as a file named 560_file. After understanding this command, you can create files of any size at will in the future

dd if=/dev/zero of=560_file count bs=560M

The function of the dd command is by no means limited to copying files. If you want to make the CD in the CD-ROM device into an image file in iso format, you need to use third-party software to do it in the Windows system, but you can directly use the dd command in the Linux system to suppress the CD image file and change it to into a ready-to-use iso image:

dd if=dev/cdrom of=RHEL-server-8.0-x86_64-LinuxProbe.Com.iso

7、file

The file command is used to view the type of the file, and the syntax format is "file file name".

In the Linux system, because text, directories, devices, etc. are collectively referred to as files, but they do not have suffixes like Windows systems, it is difficult to judge the specific file type at a glance by the file name. At this time, you need Use the file command to view the file type.

file anaconda-ks.cfg
file /dev/sda

The Linux system calls files according to the commands executed by the user, such as executing the cat command to view the text, executing the bash command to execute the script, etc., so there is no need to force the user to set a suffix for the file

8、tar

The tar command is used to pack and compress or decompress files, and the syntax format is "tar parameter file name".
On the Internet, people are more and more inclined to transmit files in compressed format, because the size of compressed files is small. Under the same network speed, the smaller the size, the shorter the transmission time. In the Linux system, the .tar, .tar.gz or .tar.bz2 formats are mainly used. You don’t have to worry about too many formats and you can’t remember them. In fact, most of these formats are generated by the tar command. The parameters of the tar command and their functions are shown in the table.

insert image description here
First, the -c parameter is used to create compressed files, and the -x parameter is used to decompress files, so these two parameters cannot be used at the same time. Secondly, the -z parameter specifies to use the gzip format to compress or decompress the file, and the -j parameter specifies to use the bzip2 format to compress or decompress the file. When users use it, they decide which format parameters should be used for decompression according to the suffix of the file. When performing some compression or decompression operations, it may take several hours. If there is no output on the screen, you will not be able to judge the progress
of the packaging on the one hand, and on the other hand, you may suspect that the computer is dead, so it is highly recommended to use -v The parameter continuously shows the user the progress of compression or decompression. The -C parameter is used to specify which specified directory to extract to. The -f parameter is particularly important, it must be placed at the end of the parameter, representing the name of the package to be compressed or decompressed. Generally use the "tar -czvf compressed package name.tar.gz directory to pack" command to pack and compress the specified file; the corresponding decompression command is "tar -xzvf compressed package name.tar.gz". Below we demonstrate the operations of packaging, compression and decompression one by one. First, use the tar command to package and compress the /etc directory in gzip format, and name the file as etc.tar.gz:

tar czvf etc.tar.gz /etc

Next, decompress the packaged compressed package file to the /root/etc directory (first use the mkdir command to create the /root/etc directory):

mkdir /root/etc
tar xzvf etc.tar.gz -C /root/etc

9. 5 processes

In the Linux system, there are the following five process names.
➢ R running: the process is running or waiting in the run queue.
➢S Interrupt: The process is dormant. When a certain condition is formed or a signal is received, it will leave this state.
➢D Non-interruptible: The process does not respond to system asynchronous signals, and cannot be interrupted even with the kill command.
➢ Z Zombie: The process has been terminated, but the process descriptor still exists, until the parent process calls the wait4() system function
and releases the process.
➢ Tstop: The process stops running after receiving the stop signal.

Guess you like

Origin blog.csdn.net/AdamCY888/article/details/131289474