6. touch create file command
The touch command is used to create a new blank file
-
Command format: touch [-option] filename
#Create an empty file in the current directory [root@localhost ~]# touch hello [root@localhost ~]# ls #Create multiple files at the same time in the current path [root@localhost ~]# touch t1 t2 t3 t4 [root@localhost ~]# ls #Create multiple files at the same time in the specified path [root@localhost ~]# touch /opt/test1 /opt/test2 /opt/test3 [root@localhost ~]# ls /opt rh student test1 test2 test3 xx #If a directory with the same name exists, it cannot be created [root@localhost ~]# mkdir test mkdir: cannot create directory 'test': file already exists #If there is a file with the same name, the touch command will not prompt, but the original file will not be overwritten [root@localhost ~]# touch t1 #For directories, when there is only a single directory, "/" is optional [root@localhost ~]# ls /opt/ rh student test1 test2 test3 xx [root@localhost ~]# ls /opt rh student test1 test2 test3 xx #For a directory, when viewing the contents of the directory, there must be "/" [root@localhost ~]# ls /opt/xx and #For files, there must be no "/" behind [root@localhost ~]# ls /opt/test1 /opt/test1 [root@localhost ~]# ls /opt/test1/ ls: cannot access /opt/test1/: not a directory
7. cp copy command
cp (full spelling in English: copy file) is used to copy files or directories, and the cp command can also modify the directory or file name when copying
-
Command format: cp [-option] source file or directory target directory
-
Common options:
-
-p Keep the source file attributes unchanged (such as: modification time, affiliation, permissions)
-
-r copy directory (including all subdirectories and files under this directory)
-
-
Use
.
with the cp command to perform copying (.
always indicate the current path)
#Copy the current directory file to the /opt directory (relative path copy) [root@localhost ~]# cp t1 /opt/ [root@localhost ~]# ls /opt rh student t1 test1 test2 test3 xx #Copy files to /opt directory (absolute path copy) [root@localhost ~]# cp /root/t2 /opt [root@localhost ~]# ls /opt rh student t1 t2 test1 test2 test3 xx # Copy multiple files at the same time [root@localhost ~]# cp t3 t4 /opt/ [root@localhost ~]# ls /opt #Create a directory [root@localhost ~]# mkdir abc # Use -r to perform a copy of the directory [root@localhost ~]# cp -r abc /opt [root@localhost ~]# ls /opt # Copy multiple directories at the same time [root@localhost ~]# mkdir abc1 abc2 abc3 [root@localhost ~]# cp -r abc1 abc2 abc3 /opt [root@localhost ~]# ls /opt #Copy the hello file to /opt and rename it to hello.txt [root@localhost ~]# cp hello /opt/hello.txt [root@localhost ~]# ls /opt #Copy the xxxx directory to /opt and rename it xxoo [root@localhost ~]# mkdir xxxx [root@localhost ~]# cp -r xxxx /opt/xxoo [root@localhost ~]# ls /opt #Use "." with the cp command to perform copying [root@localhost ~]# cd /etc/sysconfig/network-scripts/ [root@localhost network-scripts]# pwd /etc/sysconfig/network-scripts [root@localhost network-scripts]# cp /root/t1 . [root@localhost network-scripts]# ls #Copy files with the same attributes [root@localhost ~]# cp -p anaconda-ks.cfg /opt cp: overwrite "/opt/anaconda-ks.cfg"? the y [root@localhost ~]# ls -l /opt/anaconda-ks.cfg -rw-------. 1 root root 1800 Mar 13 17:34 /opt/anaconda-ks.cfg #Compare the detailed attribute information of the above two files (last modification time) [root@localhost ~]# ls -l anaconda-ks.cfg -rw-------. 1 root root 1800 Mar 13 17:34 anaconda-ks.cfg #What do these two operations mean? [root@localhost ~]# cp -r xxxx /mnt/oooo #copy and rename [root@localhost ~]# cp -r xxxx /mnt/oooo #copy
8. mv cut command
mv (full spelling in English: move file) is used to move files or directories to other locations, and can also be used to modify directories or file names
-
Command format: mv [-option] source file... target path
-
Use
.
with the mv command
#Move the current path hello file to the /mnt directory [root@localhost ~]# mv hello /mnt [root@localhost ~]# ls /mnt hello home oooo test # Move multiple files at the same time [root@localhost ~]# mv t1 t2 t3 t4 /mnt [root@localhost ~]# ls /mnt hello home oooo student1 t1 t2 t3 t4 test #Move the files in the /opt directory to /mnt root@localhost ~]# mv /opt/test1 /opt/test2 /opt/test3 /mnt/ [root@localhost ~]# ls /mnt hello home oooo student1 t1 t2 t3 t4 test test1 test2 test3 # move directory [root@localhost ~]# mv student1 /mnt [root@localhost ~]# ls /mnt hello home oooo student1 test #Move the file and rename it [root@localhost ~]# mv hello.txt /media/hello [root@localhost ~]# ls /media/ hello #Move directory and rename [root@localhost ~]# mv test /media/testxx [root@localhost ~]# ls /media/ hello testxx
9. cat view file content command
cat (English full spelling: concatenate) command is used to view the content of text files
-
Command format: cat [options] filename
-
Common options
-
-n #Display the file content in the form of line number when viewing the file
-
#View file content [root@localhost ~]# cat anaconda-ks.cfg [root@localhost ~]# cat initial-setup-ks.cfg [root@localhost ~]# cat /etc/hosts #View the content of the network card file, network card configuration file [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32 ... NAME="ens32" //Network card name UUID="16085f4c-f690-4058-b29e-d55c73387026" DEVICE="ens32" ONBOOT="yes" IPADDR="192.168.0.50" //Network card IP address PREFIX="24" //subnet mask GATEWAY="192.168.0.254" //Gateway DNS1="114.114.114.114" //DNS #View the content of the current system user basic information file [root@localhost ~]# cat /etc/passwd root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon : x : 2 : 2 : daemon : / sbin : / sbin / nlogin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin #View the content of the current system hostname configuration file [root@localhost ~]# cat /etc/hostname localhost.localdomain #View the content of the current system version information file [root@localhost ~]# cat /etc/centos-release CentOS Linux release 7.6.1810 (Core) #View the content of the current system boot configuration file automatically [root@localhost ~]# cat /etc/fstab #View the content of the basic information file of the system group [root@localhost ~]# cat /etc/group #Use "-n" to display the file content in the form of line numbers [root@localhost ~]# cat -n /etc/passwd [root@localhost ~]# cat -n /etc/hostname [root@localhost ~]# cat -n /etc/fstab [root@localhost ~]# cat -n /etc/group [root@localhost ~]# cat -n /etc/services
10. less command
The less tool is a tool for displaying the output of files in pages, and is often used to view files with large content
-
Command format: less [-option] file
-
Common options:
-
-N #Display the file content in the form of line number
-
-
skills:
-
Keyboard up and down keys to view line by line
-
pgdn : turn down one page (Fn + Down Arrow)
-
pgup : turn up one page (Fn + up key)
-
-
/string: Search for the specified string (n searches from top to bottom, N searches from bottom to top)
-
G: jump directly to the last line of the file
-
gg: jump directly to the beginning of the file line
-
: 1000 #Accurate positioning to a certain line
-
q : quit
-
[root@localhost ~]# less -N /etc/services