Write a shell script that performs file and directory manipulation tasks.
```
bash`#!/bin/bash
# File and Directory Manipulation Script
# 1. Create a directory
mkdir mydir
# 2. Navigate to the created directory
cd mydir
# 3. Create files
touch file1.txt
touch file2.txt
# 4. List the files in the directory
ls
# 5. Rename a file
mv file1.txt newfile.txt
# 6. Copy a file
cp newfile.txt copiedfile.txt
# 7. Move a file to a different directory
mkdir newdir
mv copiedfile.txt newdir/
# 8. Change directory permissions
chmod 755 newdir
# 9. Remove a file
rm newdir/copiedfile.txt
# 10. Remove a directory
rmdir newdir
# 11. Retrieve the current working directory
current_dir=$(pwd)
echo "Current directory: $current\_dir"
# 12. Check if a file exists
if [ -f newfile.txt ]; then
echo "File exists"
else
echo "File does not exist"
fi
# 13. Check if a directory exists
if [ -d newdir ]; then
echo "Directory exists"
else
echo "Directory does not exist"
fi
# 14. List files in a directory using a loop
echo "Listing files using a loop:"
for file in $(ls); do
echo "$file"
done
# 15. Count the number of files in the directory
file_count=$(ls | wc -l)
echo "Number of files: $file\_count"
# 16. Archive the files in the directory
tar -czf archive.tar.gz *
# 17. Extract files from the archive
tar -xzf archive.tar.gz
# 18. Display file content
echo "File content:"
cat newfile.txt
# 19. Find files with a specific extension
echo "Files with .txt extension:"
find . -name ".txt"
# 20. Search for a specific string in files
echo "Files containing 'hello':"
grep -rnw . -e "hello"
# 21. Sort and display file content
echo "Sorted file content:"
sort newfile.txt
# 22. Compress files into a zip archive
zip files.zip *
# 23. Extract files from a zip archive
unzip files.zip
# 24. Change file ownership
chown username newfile.txt
# 25. Change file permissions
chmod 644 newfile.txt
# End of the script
echo "Script execution completed."`
```
This script demonstrates various file and directory manipulation tasks using shell commands. It creates directories, creates and renames files, copies and moves files between directories, changes permissions, removes files and directories, lists files, counts files, archives files, extracts files, searches for specific strings in files, sorts file content, compresses files into a zip archive, changes file ownership and permissions, and more.
Please note that this script serves as an example and may require modifications to fit your specific needs. Ensure that you have appropriate permissions and handle file and directory operations with caution.