Creating directories
To create a new, empty directory in linux you can use the mkdir command.
$mkdir dirName
Remember, the directory will be made in the directory you are in.
Removing directories
To remove directories there are two commands available. rmdir and rm.
The first, rmdir will remove a directory only if it is empty.
$ rmdir dirName
If you want to remove a directory that is not empty (e.g. with contents in) yo ucan use the rm command with the -r option. The -r option tells rm to remove a directory recursively.
$ rm -r dirName
Be careful not to remove incorrect files. It may be worth adding the -i command so that you are prompted before each file in the directory is removed.
$ rm -ir dirName
Copying and moving directories
Copying and moving directorys uses the cp and mv commands.
If you have previously tried using the cp command, you will find that it complains at you. To stop this complaint, you need to use the -r option. This says to copy the directory with its contents (e.g. copy recursively).
$ cp -r dirName newDirName
This creates a directory named newDirName whose contents will be identical to dirName.
NOTE: If newDirName already exists, nothing will be overwritten - the directory dirNamewill be copied into newDirName directory under the name newDirName/dirName.
To renaming directories, you use the mv command exactly the same way as with files:
$ mv dirName newDirName
When dealing with directories, mv works a lot like cp does. If newDirName doesn't exist, the above will rename dirName to newDirName, but if newDirName exists, the directory dirName will be moved into the newDirName directory under the name newDirName/dirName.
Posted by OLLIE at 01:23am
No comments yet. Be the first to add one!