Manipulate files and directories using commands like cp, mv, rm, and chmod.
Context: GNU/Linux command examples.
Manipulate files and directories using commands like cp, mv, rm, and chmod.
Certainly! Here are examples of GNU/Linux commands for manipulating files and directories:
Copy Files and Directories (
cp
):- Copy a file to another location:
cp /path/to/source/file /path/to/destination/
- Copy a directory and its contents to another location:
cp -r /path/to/source/directory /path/to/destination/
- Copy a file to another location:
Move or Rename Files and Directories (
mv
):- Move a file to another location (also used for renaming files):
mv /path/to/source/file /path/to/destination/
- Move a directory and its contents to another location (also used for renaming directories):
mv /path/to/source/directory /path/to/destination/
- Move a file to another location (also used for renaming files):
Remove Files and Directories (
rm
):- Remove a file:
rm /path/to/file
- Remove a directory and its contents (recursively):
rm -r /path/to/directory
- Remove files or directories interactively with confirmation prompts:
rm -i /path/to/file
- Remove a file:
Change File Permissions (
chmod
):- Change file permissions using octal representation (e.g.,
chmod 644 file
):chmod 644 /path/to/file
- Change file permissions using symbolic representation (e.g.,
chmod u+r file
):chmod u+r /path/to/file
- Change permissions recursively for files and directories:
chmod -R 755 /path/to/directory
- Change file permissions using octal representation (e.g.,
These commands will allow you to manipulate files and directories in GNU/Linux. Remember to replace /path/to/source
and /path/to/destination
with the appropriate paths for your specific use case.