Day 07 Learnings: File Operations and Compression in Linux
As I continued my journey into the Linux ecosystem, I learned about file operations and compression techniques today. I explored the find
and tar
commands, which are vital for managing files and archives in Linux. Here's what I learned and accomplished today.
What I Learned This Week
find
Command in Linux:
Thefind
command is used to search for files and directories based on various criteria, such as name, type, and size.tar
Command in Linux:
Thetar
The (tape archive) command compresses multiple files into a single archive file, making them easier to store or transfer.
Steps I Followed
Using the
find
Command:Searched for files by name:
find /path/to/search -name "filename"
Searched for files by type, e.g., directories:
find /path/to/search -type d
Found files modified in the last 7 days:
find /path/to/search -mtime -7
Using the
tar
Command for Compression:Created a compressed tar archive:
tar -cvf archive.tar file1 file2
Extracted files from an archive:
tar -xvf archive.tar
Created a compressed archive with gzip:
tar -czvf archive.tar.gz file1 file2
Extracted files from a gzip archive:
tar -xzvf archive.tar.gz
Problems I Encountered
A large Number of Search Results with
find
:
Searching without specifying the exact path resulted in an overwhelming number of results.Remembering
tar
Command Options:
Thetar
command has many options, and I initially found it challenging to remember the correct combinations for different tasks.
How I Solved These Problems
Filtering
find
Results:
I used additional filters, such as-maxdepth
and-exec
, to limit and refine the search results. For example:find /path/to/search -name "*.txt" -exec ls -lh {} \;
Practicing
tar
Options:
I practiced common scenarios and created a cheat sheet with the most frequently used options. Using the--help
option and consulting the manual (man tar
) also helped clarify any doubts.
Resources I Used
find Command Documentation
tar Command Documentation
Tutorials from Linux Handbook and online forums.
Conclusion
Learning the find
and tar
commands opened up new possibilities for efficient file management and compression. The find
command allows precise searches, while tar
is an indispensable tool for creating and extracting archives.
I’m looking forward to building on these skills and exploring more Linux capabilities in the days to come. Stay tuned for Day 08 learnings!