{"id":22481,"date":"2023-10-15T04:35:22","date_gmt":"2023-10-15T04:35:22","guid":{"rendered":"https:\/\/linuxways.net\/?p=22481"},"modified":"2023-10-19T02:14:48","modified_gmt":"2023-10-19T02:14:48","slug":"archive-compress-files-directories-setting-file-attributes-finding-files-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/linux-commands\/archive-compress-files-directories-setting-file-attributes-finding-files-linux\/","title":{"rendered":"How to Archive\/Compress Files &amp; Directories, Setting File Attributes and Finding Files in Linux"},"content":{"rendered":"<p>In this tutorial, we will look at the three important Linux file management tasks: archiving\/compressing files and directories, setting the file characteristics, and discovering the files. These activities are critical for effective file organization, storage, and retrieval. Whether we are a novice or an experienced Linux user, understanding these skills can significantly increase our productivity and effectiveness in file management. So, let&#8217;s get started and learn how to archive\/compress the files and directories in Linux, modify file attributes, and discover the files.<\/p>\n<h2><strong>Archiving\/Compressing the Files and Directories<\/strong><\/h2>\n<p>Archiving and compressing the files and directories is critical to save the disc space, transmit the data, and create backups. To do these operations, Linux provides a variety of command-line utilities such as tar and zip.<\/p>\n<h3><strong>1. Tar-based Archiving<\/strong><\/h3>\n<p>The most often used \u201ctar\u201d commands:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong> Long option<\/strong><\/td>\n<td><strong> Abbreviation<\/strong><\/td>\n<td><strong> Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>\u00a0 \u2013create<\/td>\n<td>\u00a0c<\/td>\n<td>Makes a tar archive<\/td>\n<\/tr>\n<tr>\n<td>\u2013extract or \u2013get<\/td>\n<td>x<\/td>\n<td>Files are extracted from an archive<\/td>\n<\/tr>\n<tr>\n<td>\u00a0 \u2013list<\/td>\n<td>\u00a0t<\/td>\n<td>The contents of a tarball are listed<\/td>\n<\/tr>\n<tr>\n<td>\u2013file archive<\/td>\n<td>\u00a0 f<\/td>\n<td>Makes use of an archive file or device: ARCHIVE<\/td>\n<\/tr>\n<tr>\n<td>\u2013diff or \u2013compare<\/td>\n<td>\nd<\/td>\n<td>Discovers the distinctions between an archive and a file system<\/td>\n<\/tr>\n<tr>\n<td>\u00a0 \u2013append<\/td>\n<td>r<\/td>\n<td>Items are added to the conclusion of a file<\/td>\n<\/tr>\n<tr>\n<td>\u00a0 \u2013concatenate<\/td>\n<td>\u00a0 A<\/td>\n<td>Tar files are appended to an archive<\/td>\n<\/tr>\n<tr>\n<td>\u2013update<\/td>\n<td>u<\/td>\n<td>Appends the files that are newer than the archive&#8217;s copy<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Typically used operation modifiers:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong> Long option<\/strong><\/td>\n<td><strong> Abbreviation<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td>\u2013directory dir<\/td>\n<td>c<\/td>\n<td>Before executing the operations, we make changes to the \u201cdir\u201d directory.<\/td>\n<\/tr>\n<tr>\n<td>\u2013xz<\/td>\n<td>J<\/td>\n<td>Xz is used to process an archive.<\/td>\n<\/tr>\n<tr>\n<td>\u2013bzip2<\/td>\n<td>j<\/td>\n<td>Bzip2 is used to process an archive.<\/td>\n<\/tr>\n<tr>\n<td>\u2013gzip or \u2013gunzip<\/td>\n<td>z<\/td>\n<td>Gzip is used to compress an archive.<\/td>\n<\/tr>\n<tr>\n<td>\u00a0 \u2013exclude=pattern<\/td>\n<td>X<\/td>\n<td>It excludes the pattern-based file.<\/td>\n<\/tr>\n<tr>\n<td>\u00a0 \u2013verify<\/td>\n<td>W<\/td>\n<td>It is verified after writing the archive.<\/td>\n<\/tr>\n<tr>\n<td>\u2013verbose<\/td>\n<td>v<\/td>\n<td>It lists all files that have been read or extracted. When combined with -list, this flag displays the file sizes, ownership, and time stamps.<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u2013same-permissions<\/td>\n<td>p<\/td>\n<td>Original permissions are preserved.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Enter the following code to create a \u201ctar\u201d archive:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">tar<\/span> <span class=\"re5\">-cvf<\/span> archive.tar file1 file2 directory1<\/div><\/div>\n<h3><strong>2. Using Gzip to Compress<\/strong><\/h3>\n<p>Once we built a \u201ctar\u201d archive, we can conserve the disc space by compressing it with the \u201cgzip\u201d command. In Linux, the \u201cgzip\u201d compression method is commonly used.<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">gzip<\/span> archive.tar<\/div><\/div>\n<p>This compresses the \u201carchive.tar\u201d file, producing a compressed file named \u201carchive.tar.gz\u201d. The \u201c.gz\u201d extension denotes a \u201cgzip\u201d compression.<\/p>\n<h2><strong>Setting or Configuring the File Attributes<\/strong><\/h2>\n<p>We can change the rights, ownership, timestamps, and other file properties in Linux. The file properties that are properly configured ensure security, access control, and efficient file management.<\/p>\n<h3><strong>Modifying the File Permissions<\/strong><\/h3>\n<p>File permissions manage the read, write, and executes an access for several user categories including the owner, group, and others. The \u201cchmod\u201d function is used to alter or update the privileges of a file. Here&#8217;s an example:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">chmod<\/span> <span class=\"nu0\">755<\/span> file.txt<\/div><\/div>\n<p>This command grants the read, write, and executes an access to the file owner (7), reads and executes permissions to the group (5), and reads and executes permissions to others (5).<\/p>\n<h3><strong>Finding Files or Folders in Linux<\/strong><\/h3>\n<p>Searching for certain files or folders is a typical activity in Linux. Fortunately, Linux has sophisticated command-line tools to search for files based on a variety of parameters.<\/p>\n<p>Locating the Files Using a Name<\/p>\n<p>The \u201cfind\u201d command allows us to look for files by their names. Here&#8217;s an illustration:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">find<\/span> <span class=\"sy0\">\/<\/span>path<span class=\"sy0\">\/<\/span>to<span class=\"sy0\">\/<\/span>search <span class=\"re5\">-name<\/span> filename.txt<\/div><\/div>\n<p>Replace \u201c\/path\/to\/search\u201d with the location of the search and the \u201cfilename.txt\u201d with the name of the file that we&#8217;re looking for.<\/p>\n<h3><strong>Finding the Files Based on Their Type<\/strong><\/h3>\n<p>We may also find the files by type such as ordinary files, folders, symbolic links, and so on. The \u201clocate\u201d command&#8217;s \u201c-type\u201d argument lets us specify the file type. For example:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"kw2\">find<\/span> <span class=\"sy0\">\/<\/span>path<span class=\"sy0\">\/<\/span>to<span class=\"sy0\">\/<\/span>search <span class=\"re5\">-type<\/span> f<\/div><\/div>\n<p>This command searches for all regular files in the provided directory.<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Learn the basic skills of effective file location, file archiving, compression, and modification to master the art of successful file management in Linux. Improve our efficiency and productivity as a Linux user by organizing, storing, and retrieving the data more effectively. We can use these techniques to fully utilize Linux&#8217;s file management capabilities.<\/p>","protected":false},"excerpt":{"rendered":"<p>Tutorial on the Linux file management tasks to archive\/compress the files and directories in Linux, modify file attributes, and discover the files in Linux.<\/p>","protected":false},"author":111,"featured_media":22486,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049],"tags":[],"class_list":["post-22481","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22481","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/111"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=22481"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/22481\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/22486"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=22481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=22481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=22481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}