8. File and folder management in Linux
File and folder management in Linux is primarily accomplished through the command line interface (CLI) using various commands and utilities. Here are some common commands and techniques for managing files and directories in Linux:
Navigating the File System:pwd: Print the current working directory.
ls: List files and directories in the current directory.
ls -l: List files and directories in long format, providing detailed information.
ls -a: List all files and directories, including hidden ones.
cd: Change the current directory.
cd < directory >: Change to a specific directory.
cd ..: Move up one level in the directory hierarchy.
cd ~: Change to your home directory.
mkdir: Create a new directory.
mkdir <directory_name >: Create a new directory with the specified name.
Working with Files and Directories:
touch: Create an empty file or update the timestamp of an existing file.
touch <file_name >: Create an empty file with the specified name.
cp: Copy files and directories.
cp <source > < destination >: Copy the file or directory from the source to the destination.
mv: Move or rename files and directories.
mv <source > <destination >: Move or rename the source to the destination.
rm: Remove files and directories.
rm <file >: Remove a file.
rm -r <directory >: Remove a directory and its contents recursively (use with caution).
Viewing File Contents:
cat: Display the contents of a file.
cat <file >: Output the entire content of a file to the terminal.
less or more: View file contents one screen at a time.
less <file >: Scroll through a file with backward and forward navigation.
head and tail: Display the beginning or end of a file.
head <file >: Display the first few lines of a file.
tail <file >: Display the last few lines of a file.
Searching for Files:
find: Search for files and directories.
find <directory -name "<filename>": Search for a file with the specified name in the given directory.
grep: Search for text within files.
grep "<search_term>" <file>: Search for the specified text in a file.
Permissions and Ownership:
chmod: Change file permissions.
chown: Change file ownership.
chgrp: Change group ownership.
Archiving and Compression:
tar: Archive files and directories.
tar -cvf <archive_name >.tar <file_or_directory>: Create a tarball.
tar -xvf <archive_name >.tar: Extract a tarball.
gzip and gunzip: Compress and decompress files.
gzip <file >: Compress a file.
gunzip <file.gz >: Decompress a compressed file.
No comments:
Post a Comment