File and directory management is an essential aspect of working with Linux. Here are some common commands for creating, deleting, and renaming files and directories:
- Creating Files and Directories:
- To create a new directory:
mkdir directory_name
- To create a new file:
touch file_name
- To create a new directory:
- Deleting Files and Directories:
- To delete a file:
rm file_name
- To delete an empty directory:
rmdir directory_name
- To delete a directory and its contents:
rm -r directory_name
- To delete a file:
- Renaming Files and Directories:
- To rename a file:
mv old_file_name new_file_name
- To rename a directory:
mv old_directory_name new_directory_name
- To rename a file:
- Moving Files and Directories:
- To move a file to a different location:
mv file_name /path/to/destination
- To move a directory to a different location:
mv directory_name /path/to/destination
- To move a file to a different location:
- Copying Files and Directories:
- To copy a file to a different location:
cp file_name /path/to/destination
- To copy a directory to a different location:
cp -r directory_name /path/to/destination
- To copy a file to a different location:
- Listing Files and Directories:
- To list files and directories in the current directory:
ls
- To list files and directories in a specific directory:
ls /path/to/directory
- To list files and directories in the current directory:
- Viewing File Contents:
- To display the contents of a file:
cat file_name
- To display the contents of a file with pagination:
less file_name
- To display the contents of a file:
- Modifying File Permissions:
- To change file permissions:
chmod permissions file_name
- Example:
chmod +x script.sh
(to make a script executable)
- Example:
- To change file permissions:
- Checking File and Directory Information:
- To display detailed information about a file or directory:
ls -l file_name
- To display file and directory permissions:
ls -l file_name
- To display file size:
ls -l file_name
- To display detailed information about a file or directory:
These commands provide the basic functionality for managing files and directories in Linux. Remember to exercise caution when deleting or renaming files and directories, as these actions are not reversible and can result in data loss if done incorrectly.
SHARE