[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

[Super introductory 3 minutes] Done! Directory creation and deletion

Hello!
This is Inoue, a Persian cat from Beyond Shikoku Office.

Before joining the company, at a company information session, I heard a word I had never heard before,
Rinakusu ? ? ? After joining the company, I discovered " Linux " and we have been dating for 5 months.
mkdir which was my favorite command when I joined the company !
Every time a directory is created with the " mkdir I grin with joy...(・´з`・)
As a result, a large number of directories are created in the Persian cat's AWS instance, and
it becomes difficult to delete them later... ((; ゚Д゚))
I'm going to write about rm " and " rmdir at the same time

mkdir command

" mkdir " is a command that creates a directory.
First, try creating a directory without any options.

$ mkdir blog $ls -l drwxrwxr-x 2 ec2-user ec2-user 6 Aug 4 05:42 blog

A directory named "blog" has been created.

Next , add the -m
specify directory permissions at the same time as creating the directory .

$ mkdir -m 500 blog2 $ ls -l dr-x------ 2 ec2-user ec2-user 6 Aug 4 05:51 blog2

Click here for permissions

r read w write x execute

Finally , add the -p to create a child directory under the parent directory at the same time .

$ mkdir -p blog3/cat $ ls -l drwxrwxr-x 3 ec2-user ec2-user 17 Aug 4 05:55 blog3 $ ls -l blog3 drwxrwxr-x 2 ec2-user ec2-user 6 Aug 4 05:55 cat

Verify whether it is possible to create deep directories at once.

$ cd blog3/cat $ mkdir -p cat2/cat3/cat4/cat5

I was able to create child directories "cat2 to 5" at once under the "cat" directory.
In this case, "cat" is followed by "cat2", "cat3", and so on.

delete directory

To remove a directory with the
rm command specify the -r , which recursively removes the directory tree

$ cd cat2/cat3/cat4/ $ rm -r cat5 $ ls -l total 0

At this time, the files and directories in the directory "cat5" to be deleted will also be deleted.

$ rm -r cat2 $ ls -l total 0 $ cd cat3 No such file or directory

When you delete the "cat2" directory,
the child directory "cat3" under it is also deleted, so you will be told that "such a directory does not exist."
So, if you are unsure, you can add the
-i before executing the deletion you will be asked if you really want to delete it, so
enter " y(yes) You can abort the deletion by typing " n(no) convenience!

$ rm -ri cat remove directory 'cat'?yes

If you want to delete an empty directory, you can use the rmdir

$ rmdir blog3

The major difference between
" rmdir " command " rm if there are files in the directory,
an error will occur even if you try to delete them When I run rmdir when there is a file called "bydcat" in the "haruka" directory

$ ls -l haruka -rw-rw-r-- 1 ec2-user ec2-user 0 Aug 4 06:52 bydcat $ rmdir haruka failed to remove 'haruka': Directory not empty

It says, "There are files in the directory, so you can't delete them."
In this case, you need to use the rm

" rmdir " command is that it deletes empty directories, so
is a hidden file that starts with ".", it will say "I can't delete it".
This prevents you from accidentally deleting hidden files without realizing it.

summary

Options are important when considering work efficiency!
Creating child directories one by one is inefficient.
I didn't really understand the difference between
rm " and " rmdir until I started writing this blog ``In short, it's an erase command, isn't it?'' (;'∀')
I hadn't actively used options, so it was a good learning experience for me, as well as a refresher.
I wish I could write a blog
like this that makes Linux beginners like me feel like `` I made it! I'm getting used to the terminal (black screen), but
I can't help but click the mouse. CUI Persian cat.

I will continue to write blogs about my favorite commands and commands that I personally want to understand better, through trial and error

Growing every day, moving forward every day.
I have to update myself every day! ! !
Thank you for reading to the end.

If you found this article helpful , please give it a like!
1
Loading...
1 vote, average: 1.00 / 11
6,063
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

The person who wrote this article

About the author

Akika Inoue

Belongs to the System Solutions Department.
He joined Beyond as a founding member of the Shikoku office.
I jumped into the IT industry with no experience. As an education team, we create curriculum and conduct training for new graduates, mid-career, and existing members.
The main business is server operation and maintenance.
Either way, we value your content.
Also belongs to the Web Content Division and YouTube Team.