Junior
What commands in Linux are used for working with files and directories?
sobes.tech AI
Answer from AI
ls: View directory contents.cd: Change the current working directory.pwd: Display the full path to the current working directory.mkdir: Create a new directory.rmdir: Remove an empty directory.touch: Create an empty file or update the modification date of an existing one.cp: Copy files or directories.mv: Move or rename files/directories.rm: Delete files or directories (with-roption for recursive deletion).cat: Output file contents to standard output, concatenate files.less/more: Paginate through file contents.head: Display the first lines of a file.tail: Display the last lines of a file.file: Determine the file type.find: Search for files and directories based on various criteria.grep: Search for lines matching a pattern within files.chmod: Change file and directory permissions.chown: Change the owner of a file or directory.chgrp: Change the group owner of a file or directory.ln: Create links (hard or symbolic).df: Show disk space usage information for filesystems.du: Estimate disk space used by files and directories.
Examples:
# View contents with details
ls -l
# Create a new directory
mkdir my_new_directory
# Copy a file
cp source_file target_directory/
# Move and rename a file
mv old_file new_name
# Delete a file
rm file_to_delete
# View the first 10 lines of a file
head my_log_file
# Find files with .txt extension in current directory and subdirectories
find . -name "*.txt"
# Change permissions to make a script executable for the owner
chmod u+x my_script.sh