0% found this document useful (0 votes)
0 views

Manipulating Files and Directories in Bash

The document provides essential Bash commands for manipulating files and directories, including creating (mkdir), updating timestamps (touch), copying (cp), moving or renaming (mv), and deleting (rm) files and directories. Each command is accompanied by syntax and examples for clarity. Mastery of these commands enables efficient file management from the terminal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Manipulating Files and Directories in Bash

The document provides essential Bash commands for manipulating files and directories, including creating (mkdir), updating timestamps (touch), copying (cp), moving or renaming (mv), and deleting (rm) files and directories. Each command is accompanied by syntax and examples for clarity. Mastery of these commands enables efficient file management from the terminal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

# Manipulating Files and Directories in Bash

This file covers commands for creating, copying, moving, and deleting files and directories.

1. mkdir: Make Directory


- Creates new directories.
- `mkdir <directory_name>`: Creates a single directory.
- `mkdir -p <path/to/new/directories>`: Creates parent directories if they don't exist.
- Example: `mkdir new_folder`, `mkdir -p project/src/include`

2. touch: Create Empty Files or Update Timestamps


- Creates an empty file if it doesn't exist, or updates the access and modification times if it
does.
- `touch <filename>`: Creates or updates the timestamp of the specified file.
- Example: `touch my_new_file.txt`

3. cp: Copy Files and Directories


- Copies files and directories from a source to a destination.
- `cp <source> <destination>`: Copies a file.
- `cp -r <source_directory> <destination_directory>`: Recursively copies a directory and its
contents.
- Example: `cp important.txt backup.txt`, `cp -r my_folder backup_folder`

4. mv: Move or Rename Files and Directories


- Moves files and directories to a new location, or renames them.
- `mv <old_name> <new_name>`: Renames a file or directory.
- `mv <source> <destination_directory>`: Moves a file or directory to a new location.
- Example: `mv old_file.txt new_file.txt`, `mv report.pdf Documents/`

5. rm: Remove Files and Directories


- Deletes files and directories. **Use with caution!**
- `rm <filename>`: Deletes a file.
- `rm -r <directory_name>`: Recursively deletes a directory and its contents.
- `rm -rf <directory_name>`: Forcefully and recursively deletes a directory (can be
dangerous).
- Example: `rm temp.log`, `rm -r old_project`

Mastering these commands allows you to efficiently manage your files and directories from
the terminal.

You might also like