Interacting with Files and Directories
Interacting
Here is a list of common commands used for interacting with files and directories:
mkdir command
mkdir
– make a new directory of
the given name, as permissions allow.
mv command
mv
– move files, directories, or both
to a new location.
This can also be used to rename files:
Use wildcards like *
to move all files of a specific
type to a new location:
You can always verify that the file was moved with ls
.
cp command
cp
– copy files, directories, or both
to a new location.
You can give the copy a different name than the original in the same command:
To copy a directory, use the -r
option (recursively).
In this case, both the source and the destination are directories,
and must already exist.
rm command
rm
– removes files or directories permanently
from the system.
When you issue
rm
to remove a file, it is difficult to impossible to recover removed files without resorting to backup restore.
With the -r
or -R
option, it will
also remove/delete entire directories recursively and permanently.
*
.
For instance, the example below will remove all of the files and subdirectories within your current directory, so use with caution.
To remove an empty directory, use rmdir
touch command
touch
– changes a file's modification timestamp
without editing the contents of the file. It is also useful for creating
an empty file when the filename given does not exist.
Try these commands to get more familiar with Linux files and directories.