Four useful tips for Linux mkdir, tar, and kill commands (1)

Source: Internet
Author: User
Tags touch command

Four useful tips for Linux mkdir, tar, and kill commands (1)

We have been doing a task in a regular way until we know there are better solutions. As a follow-up of the Linux tips and tricks series, I will introduce four tips that can help you in various aspects. Start!

Four useful Linux tips

1. Suppose you want to create a very long/complex directory tree similar to the following. What is the most effective way to achieve this?

Similar to the directory tree to be implemented below.

 
 
  1. $ cd /home/$USER/Desktop
  2. $ mkdir tecmint
  3. $ mkdir tecmint/etc
  4. $ mkdir tecmint/lib
  5. $ mkdir tecmint/usr
  6. $ mkdir tecmint/bin
  7. $ mkdir tecmint/tmp
  8. $ mkdir tecmint/opt
  9. $ mkdir tecmint/var
  10. $ mkdir tecmint/etc/x1
  11. $ mkdir tecmint/usr/x2
  12. $ mkdir tecmint/usr/x3
  13. $ mkdir tecmint/tmp/Y1
  14. $ mkdir tecmint/tmp/Y2
  15. $ mkdir tecmint/tmp/Y3
  16. $ mkdir tecmint/tmp/Y3/z

In the above case, you can simply run the following command line.

 
 
  1. $ mkdir -p /home/$USER/Desktop/tecmint/{etc/x1,lib,usr/{x2,x3},bin,tmp/{Y1,Y2,Y3/z},opt,var}

You can use the tree Command for verification. If not, you can use apt or yum to install the 'tree' software package.

 
 
  1. $ tree tecmint

Check the directory structure

We can use the above method to create any complex directory tree structure. Note that this is just a common command, but you can use '{}' to create a hierarchical directory. If necessary, it is very useful in shell scripts.

2. Create a file such as test on the Desktop/home/$ USER/Desktop) and enter the following content.
 
 
  1. ABC
  2. DEF
  3. GHI
  4. JKL
  5. MNO
  6. PQR
  7. STU
  8. VWX
  9. Y
  10. Z

In this case, what would a common user do?

A. He will first create a file. It is best to use the touch command, for example:

 
 
  1. $ touch /home/$USER/Desktop/test

B. He will open the file in a text editor, which may be nano, vim or other editors.

 
 
  1. $ nano /home/$USER/Desktop/test

C. Then he will input the above content to the file, save and exit.

Ignore the time used by him/her. It takes at least three steps for him/her to execute the above situation.

What can an experienced Linux User do? He will input the following text in the terminal to complete all the tasks. He does not need to perform each step separately.

 
 
  1. cat << EOF > /home/$USER/Desktop/test
  2. ABC
  3. DEF
  4. GHI
  5. JKL
  6. MNO
  7. PQR
  8. STU
  9. VWX
  10. Y
  11. Z
  12. EOF


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.