3 - Creating & Deleting a directory
Posted in Linux , Linux CommandsToday lets talk about creating and deleting directories.
mkdir - create a new directory.
command syntax
mkdir [option] directory
directory - give the name of the directory you wish to create.
-m mode - Set permission mode (as in chmod), not rwxrwxrwx - umask.
-p - No error if existing, make parent directories as needed.
-v - Print a message for each created directory
-Z - (SELinux) set security context to CONTEXT
ex :
creates a directory named "dirName"
"dirName" named directory has been created.
ex :
This example use the -m option to set the permissions to all users having read, write, and execute permissions.
Shows the permission of "dirName" directory
changing permission through GUI
chmod command is used to change the permission of a file through CLI. In the future lets talk about chmod.
r - Read the file.
w - Write or edit the file.
x - Execute or run the file as a program.
rmdir - Remove directory(s)
command syntax
rmdir [option] directory
directory - give the name of the directory you wish to delete.
options used with rmdir
--ignore-fail-on-non-empty - ignore each failure that is solely because a directory is non-empty.
-p, --parents - Remove DIRECTORY and its ancestors. E.g., `rmdir -p a/b/c' is similar to `rmdir a/b/c a/b a'.
-v, --verbose - output a diagnostic for every directory processed.
--version - output version information and exit.
ex :
delete "dirName" directory.
"dirName" directoty has been deleted.
If there were files inside "dirName" directory "rmdir dirName" command wont allow us to delete that directory.
Therefore to remove a directory, even if files existed within that directory use
rm -rf directory/
ex :
If you gain some knowledge from this lesson and if you think this is useful leave a comment to encourage us. Good comments or bad comments all are important to usLets meet from a new lesson soon, have a nice day!!!
0 comments :