Jump to content

Search the Community

Showing results for tags 'file management'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • General Discussion
    • Artificial Intelligence
    • DevOpsForum News
  • DevOps & SRE
    • DevOps & SRE General Discussion
    • Databases, Data Engineering & Data Science
    • Development & Programming
    • CI/CD, GitOps, Orchestration & Scheduling
    • Docker, Containers, Microservices, Serverless & Virtualization
    • Infrastructure-as-Code
    • Kubernetes & Container Orchestration
    • Linux
    • Logging, Monitoring & Observability
    • Security, Governance, Risk & Compliance
  • Cloud Providers
    • Amazon Web Services
    • Google Cloud Platform
    • Microsoft Azure

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


LinkedIn Profile URL


About Me


Cloud Platforms


Cloud Experience


Development Experience


Current Role


Skills


Certifications


Favourite Tools


Interests

Found 10 results

  1. The post fswatch – Track File and Directory Changes in Linux first appeared on Tecmint: Linux Howtos, Tutorials & Guides .fswatch is a cross-platform, file change monitor that gets notification alerts when the contents of the specified files or directories are altered or modified. It The post fswatch – Track File and Directory Changes in Linux first appeared on Tecmint: Linux Howtos, Tutorials & Guides.View the full article
  2. Linux works well as a multiuser operating system. Many users can access a single OS simultaneously without interpreting each other. However, if others can access your directories or files, the risk may increase. Hence, from a security perspective, securing the data from others is essential. Linux has features to control access from permissions and ownership. The ownership of files, folders, or directories is categorized into three parts, which are: User (u): This is the default owner, also called the file’s creator. Group (g): It is the collection of multiple users with the same permissions to access folders or files. Other (o): Those users not in the above two categories belong to it. That’s why Linux offers simple ways to change file permissions without hassles. So in this quick blog, we have included all the possible methods to change file permissions in Linux. How to Change File Permissions in Linux In Linux, mainly Linux file permissions are divided into three parts, and these are: Read (r): In this category, users can only open and read the file and can’t make any changes to it. Write (w): Users can edit, delete, and modify the file content with written permission. Execute (x): When the user has this permission, they can execute the executable script and access the file details. Owner Representation Modify permission using the operator Permission symbols for symbolic mode Permission symbols for absolute mode User → u To add use ‘+’ Read → r To add or subtract read use ± 4 Group → g To subtract use ‘-‘ Write → w To add or subtract read use ± 2 Other → o To set use ‘=’ Execute → x To add or subtract read use ± 1 As you can see from the above table, there are two types of symbol representation of permission. You can use both of these modes (symbolic and absolute) to change file permissions using the chmod command. The chmod refers to the change mode that allows users to modify the access permission of files or folders. Using chmod Symbolic Mode In this method, we use the symbol (for owner- u, g, o; for permission- r, w, x) to add, subtract, or set the permissions using the following syntax: chmod <owner_symbol> mode <permission_symbol> <filename> Before changing the file permission, first, we need to find the current one. For this, we use the ‘ls’ command. ls -l Here the permission symbols belong to the following owner: ‘-‘ : shows the file type. ‘rw-‘ : shows the permission of the user (read and write) ‘rw-‘ : shows the permission of the group(read and write) ‘r- -‘ : shows the permission of others (read) In the above image, we highlighted one file in which the user has read and write permission, the group has read and write permission, and the other has only read permission. So here, we are going to add executable permission to others. For this, use the following command: chmod o+x os.txt As you can see, the execute permission has been added to the other category. Simultaneously, you can also change the multiple permissions of different owners. Following the above example, again, we change the permissions in it. So, here, we add executable permission from the user, remove write permission from the group, and add write permission to others. For this, we can run the below command: chmod -v u+x ,g-w,o+w os.txt Note: Use commas while separating owners, but do not leave space between them. Using chmod Absolute Mode Similarly, you can change the permission through absolute mode. In this method, mathematical operators (+, -, =) and numbers represent the permissions, as shown in the above table. For example, let’s take an example and the updated permission of the file data is as follows: Mathematical representation of the permission: User Read + Write Permission is represented as 665 4+2=6 Group Read + Write 4+2=6 Other Read + Execute 4+1=5 Now, we are going to remove read permission from the user and others, and the final calculation is: User Read + Write -Read (-4) Updated permission is represented as 261 4+2=6 6-4=2 Group Read + Write – 4+2=6 6 Other Read + Execute -Read (-4) 4+1=5 5-4=1 To update the permission, use the following chmod command: chmod -v 261 os.txt Change User Ownership of the File Apart from changing the file permission, you may also have a situation where you have to change the file ownership. For this, the chown is used which represents the change owner. The file details represent the following details: <filetype> <file_permission> <user_name> <group_name> <file_name> So, in the above example, the owner’s or user name is ‘prateek’, and you can change the user name that only exists on your system. Before changing the username, first list all the users using the following command: cat /etc/passwd Or awk -F ':' '{print $1}' /etc/passwd Now, you can change the username of your current or new file between these names. The general syntax to change the file owner is as follows: sudo chown <new_username> <filename> Note: Sudo permission is required in some cases. Based on the above result, we want to change the username from ‘prateek’ to ‘proxy.’ To do this, we run the below command in the terminal: sudo chown proxy os.txt Change Group Ownership of the File First, list all the groups that are present in your system using the following command: cat /etc/group | cut -d: f1 The ‘chgrp’ command (change group) changes the filegroup. Here, we change the group name from ‘prateek’ to ‘disk’ using the following command: sudo chgrp disk os.txt Conclusion Managing file permissions is essential for access control and data security. In this guide, we focused on changing the file permissions in Linux. It has a feature through which you can control ownership (user, group, others) and permissions (read, write, execute). Users can add, subtract, or set the permissions according to their needs. Users can easily modify the file permissions through the chmod command using the symbolic and absolute methods. View the full article
  3. All UNIX-based operating systems, including Linux, follow the structure that “everything is a file.” These systems treat all the regular files, directories, processes, symbolic links, and devices like external hardware as files. You can create, modify, and delete files using the commands or from the File Manager. Deleting files is essential when you accidentally create multiple files that become unnecessary for the system. So, in this quick blog, we will explain quick ways to delete a file in Linux with no trouble. There are a few methods of deleting the files, so let’s look at them individually with the correct examples. The rm Command You can use the rm command to delete the file from the terminal. For example, you want to delete the “filename.txt” located in the Downloads directory, so first run the below command to open the directory in the terminal: cd ~/Downloads Then, use the following command: rm filename.txt The rm command doesn’t display any output, but you can use the -v option to get the output: rm -v filename.txt If you want to delete multiple files from the current directory, you can mention all those files in a single rm command. For example, to delete three files– file1.txt, file2.txt, file3.txt, please run the below command: rm file1.txt file2.txt file3.txt In case you want to delete all the files with the same extension, then you can run the following command: rm *.txt As the above image shows, we have deleted all the .txt files from the Downloads directory. Moreover, you can use multiple extensions in a single command to delete different types of files simultaneously. For example, let’s delete all the files having the .txt and the .sh extensions: rm -v *.sh *.txt Similarly, you can empty a directory by only adding the * in the rm command: rm * Remember, the above command deletes all files except the directories. Hence, if there is a subdirectory, then the terminal will show the following output: However, you can use the -r option with the rm command to delete the subdirectories. The -r option recursively deletes the directory along with its contents: rm -r * In case you want to get the confirmation before deleting the file, please use the -i option. rm -i * Once you run the command, the system will show a confirmation prompt, so all you have to do is press Y to delete or N to decline it. From the File Manager We recommend deleting the file from the File Manager if you are a Linux beginner. So first open the File Manager and locate the directory: Now select the file and right-click it to get the context menu. Finally, click on the Move to Trash option or press Delete button. A Quick Wrap-up Linux has various commands and methods to delete a file quickly. However, users must know how to delete files to maintain an organized system and minimal storage consumption. This quick tutorial explained two ways of doing so. Initially, we discussed how the rm command works, then explained briefly the step-by-step process of deleting files using the GUI. View the full article
  4. Linux is a famous OS due to its features, like its robust file management system. It lets you perform various operations such as creating, editing, moving, and renaming those files. However, these features pose no advantage if you cannot locate your desired files. This is quite a common issue, and many users often forget a file’s location. So, this quick tutorial has all the easy methods to find a file in Linux with no hassles. In this section, we have included multiple commands such as find and locate. So let’s take a look at them one by one: The Find Command The find powerful command to search files based on various criteria. For example, let’s search for the Password.txt file located in the Documents directory: cd ~/Documents find Password.txt In case you don’t know the directory of the file, then you can run the below command: find -name Password.txt The above command produces accurate results only if you enter the file name in proper cases. Otherwise, you can run a case-insensitive search by using the -i option: find -iname password.txt Moreover, you can guide the system to search only for files or only for directories by using the -f or -d options, respectively. For files: find -type f -iname password.txt For directories: find -type d -iname password.txt The locate Command The locate is more efficient than find as it scans your system periodically and indexes it in advance. So, whenever you use the locate command, it quickly refers to the index and returns the file location. Locate is not a pre-installed command, so please run the below command to install it: sudo apt install mlocate -y Now, let’s find the Password.txt using the locate command: locate Password.txt Similarly, you can use the -i option to make the command case insensitive: locate -i password.txt The File Manager If you are a Linux beginner, we recommend you to use the File Manager to find a file. For example let’s find the Password.txt file so please open the File Manager. Here, either you can press CTRL + F or click on the search icon to open the search bar: Now, you can search for the Password.txt in the search bar: A Quick Wrap-up It sometimes becomes difficult for Linux users to find a specific file due to the complex file storage. Hence, we have explained three simple methods for finding a file with no hassles. First, one explains the find and locate commands and their functionality. Lastly, we have included the easiest method for Linux beginners to find files right from the File Manager. View the full article
  5. Archive(zip) files reduce space consumption to make the data transferable. That’s why most files you download from the web are in zip formats like tar, zip, and rar. However, you first need to unzip these files to access the data. Although a few tools are available to unzip files, Linux contains simple commands that can be used to unzip files quickly. Therefore, in this quick tutorial, we will explain different ways to unzip files in Linux. In this section, we have included commands and graphical tools to unzip files without getting errors. From File Manager If you are new to Linux, we recommend that you use the File Manager to unzip the files. First, open the File Manager and go to the directory where you saved the zip file. Now, right-click on the file; you will get two “extract here” and “extract to” options. So please choose “extract here” to unzip the file in the same directory or “extract to” to unzip the file in any other directory. In case the zip file is password protected, the system will give you a pop-up window to enter the password: The unzip Command If you’re specifically dealing with a zip format file, use the unzip command. Otherwise, you can jump right into the next section. To unzip a file using the unzip command, first navigate to the directory where the zip file is located. For example, let’s open the Downloads directory: cd Downloads Now use the unzip command in the following manner: unzip Music.zip If you want to list the content of a zip file, then please use the -l option: unzip -l Script.zip You can also extract the zip file data in any other directory by using the -d option: unzip Script.zip -d ~/Documents In case the zip file is password protected, you need to use the -P option, including the password in the command: unzip -P 12345 Scripts.zip The tar Command The tar is the second most commonly used archive format after ‘zip’, which makes it equally essential to be aware of. For unzipping ‘tar’ files, Linux provides the tar command that can handle formats like ‘.tar,’ ‘.tgz,’ ‘.taz,’ ‘.tar.xz’, and more. Let’s take an example of a zip file, ‘Scripts.tar,’ and unzip it using the tar command: tar -xvf Scripts.tar Furthermore, if the tar archive is compressed using gzip and bzip2, use the ‘-z’ or ‘-j’ options, respectively. For instance, had the file in the above example been ‘Scripts.tar.gz’ or ‘Scripts.tar.bz2’, we would have used: tar -xvfz Scripts.tar.gz OR tar -xvfj Scripts.tar.bz2 A Quick Wrap-up Unzipping a file is a fundamental task, and as a Linux user, you must know the various methods to unzip a file. This short guide explains the two common commands that let you unzip files of different archive formats. For the zip format, the straightforward approach is via the unzip command, whereas for other formats, you must use the tar command. View the full article
  6. Directories are containers that hold various data, including text, media, and zip files. As a system administrator, you can create, move, or delete these directories. Although deleting a directory in Linux is simple, many beginners need to learn the correct ways to do it. That’s why Linux users sometimes delete important directories, which can lead to major issues. In this quick blog, we have included all the possible ways to delete a directory in Linux. Here, we have included commands and a simple GUI method to delete a directory without hassles. So let’s look at them all with the appropriate examples: The rm Command The rm command deletes files and directories, where ‘rm’ stands for ‘remove.’ You can use the following rm command to delete a directory: rm -r directory_name We use the ‘-r’ option to delete the target directory, its content, and subdirectories. For instance, let’s delete the music directory using the rm command: rm -r Music Note: Be cautious using the rm command because it permanently deletes files and directories without confirmation. The rmdir Command Unlike rm, the rmdir command is designed to remove empty directories. For example, to delete an empty directory named Script located in the home directory, please use the following command: rmdir ~/Script Note: When using the rmdir command, please specify the target directory and its path. Without the correct path, this command will result in an error. Similarly, you can also use the rmdir to delete a subdirectory. For example, let’s delete the Images subdirectory available in the Documents directory: rmdir ~/Documents/Images The find Command Despite the original function of the find command, it also lets you delete files and directories with its ‘-exec’ option. However, this feature is only applicable to empty directories. For example, to remove a directory this way, use: find directory_name -type d -exec rm -r {} + Here, the ‘-type d’ option specifies that the searched term is the name of a directory. The ‘-exec rm -r {} +’ option guides the find utility to execute the ‘rm -r’ command for every directory found with the input name. Moreover, replace the directory_name with the name of the directory you intend to remove: find Scripts -type d -exec rm -r {} + A Quick Summary Deleting files and directories is a fundamental task for an everyday Linux user. This article demonstrated different methods for deleting a directory using appropriate examples: the rm, rmdir, and find commands. You can choose the rm to delete directories and files, whereas the rmdir only works to delete empty directories. Lastly, the find command allows you to delete directories with the help of the ‘-exec’ option. View the full article
  7. In operating systems, files are the building blocks that contain data, configurations, and programs. They aid in system customization, data organization, scripting and programming, user collaboration, and more. There are various types of files, including text, binary executable, media, system, and many more. Despite this variety, text files contribute roughly 50 to 80% of the data. Hence, it is a crucial aspect that users must be aware of. Many beginners do not yet know the approaches to making new text files. So, in this guide, we briefly describe how you can create a file in Linux without any hassles. There are three simple methods for creating a file in Linux: a text editor, the touch command, and the redirection operator. Let’s divide this section to discuss each in detail using suitable examples. The Text Editors Linux’s text editors are powerful yet simple tools to create text files and edit them. There are various text editors like Nano and Vim in Linux systems. For instance, to create a file, say sample.txt using nano, your command would be: nano sample.txt On entering this command, it will create the sample.txt file and open it in the text editor window. Similarly, you can use the following command to create the text files through the vi text editor: vi sample.txt<span style="font-weight: 400"> </span> The touch Command The touch is used to create the empty files and update a file’s timestamps quickly. To use it for creating a text file, use the following command: touch filename.txt Redirect Operator Suppose you execute a command or script whose output you want to save in a text file. This is where the redirect operator “>” comes into play. For example, to save the output of an echo command in a new text file, “sample_file.txt,” you should use: echo "Hello, this is a sample file." > sample_file.txt A Quick Wrap-up Knowing how to create a file is a must-have skill for every Linux user. This guide lists three approaches that you can use to make a text file. These methods involve using a text editor, the redirect operator, and the touch command. While the way through the text editor is simplest, the other two methods have their use. View the full article
  8. As a Linux user, you are likely to perform file compression and decompression frequently. One of the most widely used compression formats is ZIP; it allows you to bundle multiple files into a single archive for easy storage and sharing. Linux offers a lot of flexibility on how and where to unzip your compressed files. In this blog, you will learn various methods for unzipping files to a specific directory. Understanding File Compression and DecompressionBefore diving into unzipping files in Linux, it's essential to understand the fundamentals of file compression and decompression. File compression involves decreasing file sizes by more efficiently encoding data, making them easier to store and transfer when working with large amounts of information. Decompression refers to extracting original files from compressed archives. Check out this blog to learn 4 Commands to Check File Size in Linux Linux gives users more control in the decompression process by allowing them to unzip files to a specific directory. This helps organize files and directories neatly. Unzip Verification/InstallationUnzipping zip archive files requires installing the unzip package on your system; most modern Linux distributions come equipped with unzip support. To verify if the unzip tool is installed on Ubuntu and check its version, use the following commands: Verify if unzip is installedYou can check if unzip is installed by attempting to run it or using the “which” command to locate its executable file. which unzipThe command will return the path to the unzip executable if unzip is installed. If it's not installed, the command gives an empty output. Installing unzipIf unzip is not installed or you want to ensure the latest version is installed, you can install it using the package manager (apt) on Ubuntu. Run the following commands sequentially to install it: sudo apt update sudo apt install unzip The first command (apt update) updates the local package index to ensure that the package information is up to date. The second command (apt install unzip) installs the unzip package. After installation, you can verify that unzip is installed and check its version using the commands mentioned earlier. Methods to Unzip Files to a Specific Directory in LinuxBelow are the different methods of unzipping files: Method 1: Using the unzip CommandThe most common way to unzip files in Linux is using the unzip command-line utility. To unzip a file to a specific directory, provide the -d option followed by the desired destination directory. Below is the syntax for this method: unzip <zipfile> -d <destination_directory>For example, to unzip a file named demo.zip to a directory named destination, use the command: unzip demo.zip -d destinationThis command will extract all files from the ZIP archive demo.zip into the destination directory. Learn how to manage files and directories in Linux from this post: Linux - Create, Delete, Copy, and Move Files and Directories Below are the most commonly used options for the unzip command in Linux, along with detailed explanations and examples: -d <directory>: This option specifies the directory where the extracted files will be placed. By default, files are extracted to the current working directory. Using `-d` allows you to extract files to a specific location. unzip demo.zip -d /path/to/destination-l: Lists the contents of the ZIP file without extracting them. This option is useful for previewing the contents of an archive before extraction. unzip -l demo.zip -d /path/to/destination-v: Displays verbose output, providing more detailed information during extraction. This includes the name and size of each file as it is extracted. unzip -v demo.zip -d /path/to/destination-t: Tests the integrity of the ZIP file, checking for any errors or corruption. This option can ensure that the archive is not damaged before extraction. unzip -t demo.zip -d /path/to/destination-o: Overwrites existing files without prompting for confirmation. If a file with the same name already exists in the destination directory, it will be replaced by the extracted file. unzip -o demo.zip -d /path/to/destination-q: Suppresses normal output and only displays error messages. This option is helpful for scripting or automation tasks where you want to avoid cluttering the terminal with unnecessary information. unzip -q demo.zip -d /path/to/destination-x <patterns>: Excludes files from extraction based on specified patterns. This allows you to extract only the files you need while ignoring others. unzip demo.zip -x "*.txt" -d /path/to/destinationThis command will exclude all files with a .txt extension from extraction. -P <password>: Specifies a password to decrypt encrypted ZIP files. If the ZIP file is protected with a password, you must provide the correct password to extract its contents. unzip -P secret demo.zip -d /path/to/destinationThis command will extract the contents of demo.zip, encrypted with the password "secret". -j: Junk paths. This option tells unzip to ignore directory structures and extract all files directly into the destination directory. It is useful when you want to avoid creating nested directories. unzip -j demo.zip -d /path/to/destination-n: Never overwrite existing files. This option instructs unzip to skip extracting files if they already exist in the destination directory. It prevents accidental overwriting of files. unzip -n demo.zip -d /path/to/destination-U: Use Unicode character encoding for filenames. This ensures proper handling of non-ASCII characters in filenames during extraction. unzip -U demo.zip -d /path/to/destinationMethod 2: Use the tar OptionIn Linux, the tar command is commonly used for creating and manipulating tar archives, often used for file compression and archiving purposes. When you want to extract files from a tar archive, you typically use the tar command with the -x option (short for extract). Below is the syntax to use the tar command to extract files from a tar archive: tar -xvf demo.tar -C /path/to/destination-x: This option tells tar to extract files from the archive. -v (verbose): This option displays detailed information about the extraction process, including the names of files as they are extracted. -f (file): This option specifies the name of the tar archive file. It should be followed by the name of the tar archive you want to extract. -C: This option gives the destination path where files will be extracted. If the tar archive is compressed (e.g., with gzip or bzip2), you may need to add additional options to handle compression. For example, if the archive is compressed with gzip, you would use the -z option: tar -xzvf demo.tar.gz -C /path/to/destinationMethod 3: Using the -d Option with Archive ManagerIf you prefer a graphical interface for file management, many Linux distributions come with Archive Manager or similar utilities pre-installed. These applications provide a user-friendly way to work with compressed files. To unzip a file to a specific directory using Archive Manager, follow these steps: Right-click on the ZIP file you want to extract.Select "Extract Here" to unzip the files to the current directory, or choose "Extract to" to specify a destination directory.Navigate to the desired destination directory and click "Extract."Archive Manager will then extract the files from the ZIP archive to the chosen directory.Method 4: Using the -d Option with GUI File ManagersSuppose you're using a desktop environment with a graphical file manager such as Nautilus (GNOME), Dolphin (KDE), or Thunar (XFCE). In that case, you can also unzip files directly from the file manager to a specific directory. Here's how to do it in Nautilus: Navigate to the directory containing the ZIP file.Right-click on the ZIP file and select "Extract Here" to unzip the files to the current directory, or choose "Extract to" to specify a destination directory.If you chose "Extract to," navigate to the desired destination directory and click "Extract"Similar options are available in other file managers, allowing you to extract files to a specific directory with just a few clicks. Method 5: Using the unzip Command with WildcardsSometimes, you may need to extract multiple ZIP files to the same destination directory. Using wildcards with the unzip command can simplify this task. Wildcards are special characters that represent one or more other characters. For example, to unzip all ZIP files in the current directory to a directory named destination, you can use the following command: unzip '*.zip' -d destinationThis command will extract all ZIP files in the current directory to the destination directory. Common Problems when Unzipping Files on LinuxBelow are some common problems you may encounter when unzipping files on Linux and the possible solutions: Insufficient Permissions: If you don't have the necessary permissions to write to the directory where you are trying to extract the files, unzip may fail. Use the chmod command to adjust permissions as needed.Lack of Disk Space: If your disk is full or needs more space to extract the files, unzip may fail. Check your disk space usage and free up space if necessary.File Size Limitations: If the zip file is huge, you may need help with memory or file size limitations. Consider using alternative methods for extracting large files, such as zcat or tar.Filesystem Issues: Filesystem inconsistencies or disk errors can also lead to problems when unzipping files. Run filesystem checks (fsck) to identify and fix any issues with your filesystem.By addressing these common issues, you should be able to successfully unzip files on Linux without encountering major problems. ConclusionFrom command line tools to graphical interfaces, Linux offers flexible extraction solutions tailored to meet your file extraction needs. By mastering the techniques we’ve discussed, you can efficiently manage compressed files while maintaining an organized directory structure. Check out our Linux Basics Course. The most important thing while learning Linux, especially the Linux command line, is practice. The hundreds of questions in our labs throughout this course will give you enough hands-on practice to be confident in Linux. View the full article
  9. In this guide, we will learn about copying files and directories in Linux. Prerequisites: To perform the steps that are demonstrated in this guide, you need the following components: A properly configured Linux system. For learning and testing, an Ubuntu VM will suffice. Read access to the files/directories to be copied. Learn more about file permissions in Linux. Copying Files and Directories Copying is one of the most fundamental operations that you have to perform when operating a computer. In Linux, there are multiple tools that are available for copying files and directories: cp: The default tool for copying files and directories. It’s available on all Linux distros. rsync: A powerful tool that is primarily used for file synchronization. However, we can also use it for copying files and directories. For demonstration purposes, we configured two directories: /tmp/source and /tmp/destination. $ tree /tmp/source $ tree /tmp/destination Copying Files and Directories Using Cp The command structure of cp is as follows: $ cp <options> <source> <destination> For all the available options, check out the man page: $ man cp Copying a File The following command copies the “1.txt” from /tmp/source to /tmp/destination: $ cp -v /tmp/source/1.txt /tmp/destination $ tree /tmp/destination If you specify a different file name as the destination, cp renames it accordingly: $ cp -v /tmp/source/1.txt /tmp/destination/test.txt $ tree /tmp/destination Copying Multiple Files The following command copies all the text files under /tmp/source to /tmp/destination: $ cp -v /tmp/source/1.txt /tmp/source/2.txt /tmp/source/3.txt /tmp/source/4.txt /tmp/source/5.txt /tmp/destination $ tree /tmp/destination If the source files are named in a pattern, cp can work with that: $ cp -v /tmp/source/*.txt /tmp/destination $ tree /tmp/destination Copying a Directory In the next example, we will copy the “subdir1” to /tmp/destination: $ cp -v -r /tmp/source/subdir1 /tmp/destination $ tree /tmp/destination Here, the “-r” flag tells the cp command to copy the directory and all its content recursively to the destination. If a different directory name is specified in the destination, cp renames it accordingly: $ cp -v -r /tmp/source/subdir1 /tmp/destination/yellow $ tree /tmp/destination If the destination directory already exists, cp copies the source directory and everything it contains. However, we can specify to only copy the files and sub-directories, not the target directory: $ cp -v -rT /tmp/source/subdir1 /tmp/destination/yellow $ tree /tmp/destination Copying Files and Directories Using Rsync The primary usage of rsync is synchronizing the files between the local/remote servers. It comes with numerous additional features. However, we can also use it for “syncing” files from one directory to another (copying in other words). The rsync command structure is as follows: $ rsync <option> <source> <destination> Check out the man page for all the available options: $ man rsync Copying Files The following command copies the “1.txt” from /tmp/source to /tmp/destination: $ rsync -a /tmp/source/1.txt /tmp/destination && tree /tmp/destination Here, the “-a” parameter tells rsync to operate in archive mode. We can also copy the file with a different name in the destination: $ rsync -a -v /tmp/source/1.txt /tmp/destination/different.txt && tree /tmp/destination To copy multiple files, specify the files one by one or describe the pattern to match: $ rsync -a -v /tmp/source/1.txt /tmp/source/2.txt /tmp/destination && tree /tmp/destination $ rsync -a -v /tmp/source/*.txt /tmp/destination && tree /tmp/destination Copying Directories Unlike cp, to copy the directories with its files and sub-directories, there’s no change of syntax with rsync. When working in archive mode, rsync automatically copies all the contents recursively. One key difference here is the trailing slash (/). If a slash is present in the source directory, rsync copies the contents of the source directory to the destination. If a slash isn’t present in the source directory, rsync copies the source directory inside the destination directory. The following commands demonstrate the difference perfectly: $ rsync -a -v /tmp/source /tmp/destination $ tree /tmp/destination $ rsync -a -v /tmp/source/ /tmp/destination $ tree /tmp/destination Copying Files to Remote Machine Using Scp The scp command is a specialized tool that copies the files and directories over SSH. It requires having the OpenSSH server installed on the remote host. The fundamentals of the scp command are the same as the cp command. Learn more about the scp command. Copying Files In the following command, we copy the Ubuntu 22.04 ISO to the /tmp directory on a remote host: $ scp ubuntu-22.04-desktop-amd64.iso root@192.168.99.15:/tmp To copy a file from a remote host, use the following command: $ scp root@192.168.99.15:/tmp/ubuntu-22.04-desktop-amd64.iso. Copying Directories To copy a directory to a remote host, we use the following scp command: $ scp -r test_dir root@192.168.99.15:/tmp Here, the “–r” parameter is to operate in recursive mode (needed to copy the directory). Conclusion We showcased the various ways of copying the files in Linux. We demonstrated how to use the cp and the rsync commands to copy the files and directories locally. We also showcased how to use the scp command to copy the files and directories to a remote host. For more advanced copying and backup configurations, rsync is a better option. It can make a system backup, sync with multiple remote hosts, update new files, and more. View the full article
  10. “ls” is one of the most frequently used commands in Linux. It is used to list down the files and sub-directories within your current directory. This command is equally useful for normal users as well as for system administrators. Therefore, today we will share the five most practical use cases of the “ls” command in Linux Mint 20. 5 Most Practical Examples of Using “ls” command in Linux: The five most practical uses of the “ls” command in Linux are as follows: Example # 1: Listing all the Files and Directories without any Additional Details: The simplest usage of the “ls” command is to use it without any additional flags or parameters. You can do this in the manner shown below: $ ls All the files within the current directory of our Linux system are shown in the following image: Example # 2: Listing all the Files in the Last-Modified File First Order: If you want to list down all the files in the last modified file first order, i.e., you want to list down the files according to their modification time or date; then you can execute the “ls” command as follows: $ ls –t All the files within the current directory of our Linux system in the last modified file first order are shown in the image below: Example # 3: Listing all the Hidden Files: The hidden files in Linux are not displayed by using the simple “ls” command in the terminal. But they can be listed by using the “-a” flag with the “ls” command in the following manner: $ ls –a All the hidden files within the current directory of our Linux system are shown in the image below: Example # 4: Listing all the Details along with Files: If you want to display all the details along with the file names such as file size, date modified, file permissions, etc., then you can use the “ls” command in the following manner: $ ls –l All the files within the current directory of our Linux system, along with their details, are shown in the image below: Example # 5: Listing all the Files in the Descending Order of their Size: If you want to display all the files in the descending order of their size, i.e., the largest file first order, then you will have to execute the “ls” command in the following manner: $ ls –lS All the files within the current directory of our Linux system in the descending order of their size are shown in the image below: Conclusion: This article was intended to share the five most practical examples of using the “ls” command in Linux. However, if you want to know more about this command’s usage, you can execute the “ls –help” command in Linux for accessing the help manual of this command. In this way, you will know about all the flags and parameters that can be combined with this command to serve different purposes. View the full article
  • Forum Statistics

    43.5k
    Total Topics
    43k
    Total Posts
×
×
  • Create New...