Basic Commands and Simple Shell Scripts
84
DirectoriesLet’s start by creating a directory to keep some working files.
We can do so by running mkdir, short for make directory”:
[user@rhel-instance
]$ mkdir mydir[user@rhel-instance
]$ ls -ltotal 0drwxrwxr-x. 2 user user 6 Feb 13 19:53 mydirFolders can be
deleted with the rmdir command, short for remove directory”:
[user@rhel-instance
]$ ls -ltotal 0drwxrwxr-x. 2 user user 6 Feb 13 19:53 mydir[user@rhel-instance
]$ mkdir deleteme[user@rhel-instance
]$ ls -ltotal 0drwxrwxr-x. 2 user user 6 Feb 13 20:15 deletemedrwxrwxr-x. 2 user user 6 Feb 13 19:53 mydir[user@rhel-instance
]$ rmdir deleteme[user@rhel-instance
]$ ls -ltotal 0drwxrwxr-x. 2 user user 6 Feb 13 19:53 mydirHowever, rmdir will only delete empty directories:
[user@rhel-instance
]$ ls etc >
/mydir/etc-files.txt[user@rhel-instance
]$ rmdir mydirrmdir: failed to remove 'mydir': Directory not emptyHow can we delete a directory and all the other files and directories it contains using the remove (rm) command First, let’s just create
and remove a single file, var-files.txt:
[user@rhel-instance
]$ ls var >
/var-files.txt[user@rhel-instance
]$ ls -l var-files.txt-rw-rw-r--. 1 user user 109 Feb 13 15:31 var-files.txt[user@rhel-instance
]$ rm var-files.txtShare with your friends: