Linux Programming 5 (Directory rename with move mv, delete file rm, directory creation mkdir delete rmdir, view file,cat,more,tail,head)

Source: Internet
Author: User
Tags mkdir

I. File rename and move (MV)  

In Linux, renaming files is called moving (moving). The MV command can move files and directories to another location or rename them.

  1.1 Using the MV Rename
Below/usr/local create an empty file as test, using the MV command to rename to Test1, viewing the inode number and time will remain the same, because the MV only affects the file name. As shown in the following:
      

1.2 Moving position with MV

The following uses the MV to move the local test1 file to the/SRC directory, the inode number and time will remain unchanged, just move the location, as shown in:
      
When you move a file, you can also rename it, move the test1 to the/SRC directory below, and rename it to test2 file. As shown below:
      
The MV command can also move the directory (folder), and only the location is moved, and the inode number and time will remain unchanged. No more demonstrations here.

two. Delete Files (RM)

2.1 Using Rm-i

Rm-i parameter will prompt you whether to really delete the file, base shell does not have recycle Bin, delete cannot retrieve, add-I parameter develop good habit. Below the src directory to delete the test file, prompt whether to delete, enter n is not deleted, as shown in:
      
 2.2 Using wildcard characters
   
Use the wildcard character "?" To delete, delete the test file below, beginning with the character T, the middle two wildcard characters "?", ending with the end character T.
      

three. Create a directory (mkdir)

  3.1 Creating a single new directory

   Create a directory in Linux use mkdir, below the USR directory to create a new directory file1, the new directory long list is the beginning of D, indicating that this is a directory. As shown below:
      
 3.2 Creating a new catalog in bulk

If you need to create directories and subdirectories in bulk, you need to use the Mkdir-p parameter to do so, and then create the file1/log below in the USR directory, as shown below:
      


four. Delete directory (RM or rmdir)

  4.1 Rm-ri

Delete Directory is rmdir, but only empty directory, if there are files in the directory will prevent the deletion. To solve this problem, the files in the directory must be deleted before the empty directory can be deleted using RmDir. You can use the Rm-ri command parameter to delete files under the directory and the directory itself. Delete file1/log/1.txt all directories and files below, use Rm-ri to complete
      

five. View Files

  5.1 View File Types files

Before displaying the contents of a file, you should confirm the file type. Use the file command to view it as follows:
    

In addition to viewing the file type, you can also confirm that it is a symbolic connection, as shown in:
    
  5.2 View Entire file cat

Below, use Cat-b to view the contents and line numbers as follows:
    

 5.3 View File page flip more

For large files, use more to control the following operations, can be displayed per page, press SPACEBAR to page, press Q to exit.
    
There are more advanced less commands than more to view the files, which are no longer shown here.
  5.4 Viewing the number of file trailing lines tail
    
Using the tail command, if you do not add any parameters, the first 10 lines of the file footer are displayed by default. Use the parameter-N to determine the number of rows displayed. Use the-f parameter to allow other processes to consume files while viewing the contents of the file. The following demo-N 5来 confirms that the trailing 5 lines of the file are displayed as shown in:
    
5.5 Viewing file header rows Head
The command is exactly the opposite of tail and has the-N and-f parameters. The following demo-N 5来 confirms that the first 5 lines of the file are displayed as shown in:
    

Linux Programming 5 (Directory rename with move mv, delete file rm, directory creation mkdir delete rmdir, view file,cat,more,tail,head)

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.