[Super beginner's guide in 3 minutes] Done! Creating and deleting directories

table of contents
Hello!
I'm Inoue, the Persian cat at Beyond Shikoku office.
at the company orientationLinuxI heard the word
After joining the company,LinuxI encountered this
This time, I'll talk about the command "mkdir," which was my favorite when I first joined the company!
"mkdirEvery time I created a directory with theI would be so happy I'd grin... (・´з`・)
As a result, a huge number of directories were created on my Persian cat's AWS instance,
and it became a real pain to delete them later... ((; ゚Д゚)) Oh dear.
"rm" and "rmdirI'll also write about
mkdir command
"mkdir" is a command used to create directories.
First, let's 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,-museat the same time as creating the directory
to specify the directory's permissions (authority).
$ mkdir -m 500 blog2 $ ls -l dr-x------ 2 ec2-user ec2-user 6 Aug 4 05:51 blog2
Permissions are here
r read w write x execute
Finally-p, add thesimultaneously create child directories under the parent directory.
$ 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
We tested whether it was possible to create deep directories all at once
$ cd blog3/cat $ mkdir -p cat2/cat3/cat4/cat5
We were able to create subdirectories "cat2" through "cat5" under the "cat" directory all at once.
In this case, "cat2" would be followed by "cat3", and so on.
Delete a directory
"rmTo delete a directory using the
to recursively delete the directory tree-rspecify the
$ cd cat2/cat3/cat4/ $ rm -r cat5 $ ls -l total 0
In this case, 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
If you delete the "cat2" directory,
its subdirectory "cat3" will also be deleted, resulting in an error message saying "that directory doesn't exist."
Therefore, if you're unsure,-iyou can add the
confirmation before deleting, asking "Are you sure you want to delete?".will prompt you for
"y (yes)Enteringn (no)" will cancel the deletion. Very convenient!
$ rm -ri cat remove directory 'cat'?yes
To delete an empty directory,rmdiryou can use the
$ rmdir blog3
`rmdir`commandif there are files already in the directory
will result in an error`rmdir`The main difference between
when there is a file named `bydcat` inside the `haruka` directoryrmdir`you try to execute
$ 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, "You can't delete it because there's a file in the directory."
So, in cases like this,rmyou need to use the
"rmdir" command is that it deletes empty directories, so if
it essentiallyhidden files that start with a "."tells you "you can't delete this."
This prevents accidental deletion of hidden files without realizing it.
summary
When you think about work efficiency, options are really important!
Creating subdirectories one by one is inefficient.
To be honest, until I started writing this blog,rm" and "rmdirI didn't really understand the difference between
, "Basically, they're both commands to delete things" (;'∀')
I hadn't really been actively using options, so it was a good learning experience and a good review. I hope I
like this that give Linux beginners like me the feeling of "I did it!can write blogs
I'm getting used to the terminal (the black screen)
clicking the mouse a lot
now,
but I still find myself
Growing every day, moving forward every day.
I must update myself every single day!!!
Thank you for reading to the end.
2
