File Management – Linux Hint https://linuxhint.com Exploring and Master Linux Ecosystem Mon, 01 Mar 2021 00:17:42 +0000 en-US hourly 1 https://wordpress.org/?v=5.6.2 Ways to Determine the File System Type in Linux https://linuxhint.com/determine-file-system-type-linux/ Mon, 08 Feb 2021 03:10:30 +0000 https://linuxhint.com/?p=89217 In computing, a filesystem is a layout or format used to store files in a storage device. A filesystem is used to logically divide a storage device to keep different files organized nicely in the storage device to be searched, accessed, modified, removed, etc. easily from the storage device.

There are many filesystems available today. Different filesystems have different structures, logics, features, flexibility, security, etc. Some of the most common filesystems are Ext4, Btrfs, XFS, ZFS, NTFS, FAT32, etc.

There are times when a Linux system administrator will need to determine the filesystem type to simply mount the filesystem or to diagnose problems with the filesystem. Different filesystems have different tools for diagnosing problems, checking for errors and fixing them, etc. So, you have to know the filesystem a storage device is using to determine the maintenance tool/tools to use.

In this article, I will show you different ways you can determine the filesystem type in Linux. So, let’s get started.

Way 1: Using the df Command-Line Tool

The df command-line program is preinstalled on almost every Linux distribution you will find. You can use the df command-line program to find the Filesystem type all the mounted storage devices and partitions.

To find the filesystem type of all the mounted storage devices and partitions of your computer, run the df command as follows:

$ df -Th

The df command will show you the following information:
Filesystem: The storage device name or partition name that is currently mounted.

Mounted on: The directory where the storage device/partition (Filesystem) is mounted.

Type: The filesystem type of the mounted storage device/partition.

Size: The size of the mounted storage device/partition.

Used: The disk space that is used from the mounted storage device/partition.

Use%: The percentage of disk space that is used from the mounted storage device/partition.

Avail: The amount of free disk space of the mounted storage device/partition.

On Ubuntu, the df command will show you many loop devices as you can see in the screenshot below.

You can hide the loop devices with the -x option of the df command as follows:

$ df -Th -x squashfs

You can also hide the tmpfs devices from the output of the df command.

To hide the tmpfs devices from the output of the df command as well, run the df command with the -x option as follows:

$ df -Th -x squashfs -x tmpfs

Now, the output looks much cleaner. If you want, you can remove the udev devices from the df command’s output.

To remove the udev devices from the output of the df command as well, run the df command as follows:

$ df -Th -x squashfs -x tmpfs -x devtmpfs

Only the physical storage devices and partitions will be displayed in the output of the df command. The output looks much nicer than before as well.

Way 2: Using the lsblk Command

The lsblk command-line program is preinstalled on almost every Linux distribution you will find. You can use the lsblk command-line program to find the Filesystem type of all (mounted and unmounted) the storage devices and partitions of your computer.

To find the filesystem type of all (mounted and unmounted) the storage devices and partitions of your computer, run the lsblk command as follows:

$ lsblk -f

The lsblk command will show you the following information:
NAME: The storage device name or partition name of a storage device.

MOUNTPOINT: The directory where the storage device/partition (Filesystem) is mounted (if mounted).

FSTYPE: The filesystem type of the storage device/partition.

LABEL: The filesystem label of the storage device/partition.

UUID: The UUID (Universally Unique IDentifier) of the filesystem of the storage device/partition.

FSUSE%: The percentage of disk space that is used from the storage device/partition.

FSAVAIL: The amount of free disk space of the storage device/partition

Just as before, you can hide the loop devices from the output of the lsblk command.

To hide the loop devices from the output of the lsblk command, run the lsblk command with the -e7 option as follows:

$ lsblk -f -e7

As you can see, all the loop devices are removed from the output of the lsblk command. The output looks a lot cleaner than before.

Way 3: Using the blkid Command

The blkid command-line program is preinstalled on almost every Linux distribution you will find. You can use the blkid command-line program to find the Filesystem type of all (mounted and unmounted) the storage devices and partitions of your computer.

To find the filesystem type of all (mounted and unmounted) the storage devices and partitions of your computer, run the blkid command as follows:

$ blkid

The lsblk command will show you the following information:
NAME: The name of the storage device or partition name of the storage device. i.e. /dev/sda1, /dev/sda5.

UUID: The UUID (Universally Unique IDentifier) of the filesystem of the storage device/partition.

TYPE: The filesystem type of the storage device/partition.

PARTUUID: The UUID (Universally Unique IDentifier) of the partition.

You can also hide the loop devices from the output of the blkid command as before.

To hide the loop devices from the output of the blkid command, run the blkid command as follows:

$ blkid | grep -v 'TYPE="squashfs"'

As you can see, the loop devices are not displayed in the output of the blkid command. The output looks much nicer than before.

Way 4: Using the file Command

The file command-line program is preinstalled on almost every Linux distribution you will find. You can use the find command-line program to identify the file type of a file on Linux. As every device is considered a file in Linux, you can use the find command-line program to determine the filesystem type of a storage device or partition in Linux.

For example, to determine the filesystem type of the partition sdb1, you can run the file command as follows:

$ sudo file -sL /dev/sda1

If you read the file command’s output, you can see that the sdb1 partition is using the FAT32 filesystem.

In the same way, you can find the filesystem type of the sda5 partition with the file command as follows:

$ sudo file -sL /dev/sda5

As you can see, the partition sda5 is using the EXT4filesystem.

Way 5: Using the mount Command and /etc/mtab File

The /etc/mtab file contains an entry for all the mounted storage devices and partitions of your computer. You can read this file to find the filesystem type of your storage devices and partitions. The mount command-line program also prints the contents of the /etc/mtab file. So, you can use the mount command-line program as well to find the same data.

You can read the contents of the /etc/mtab file with the following command:

$ sudo /etc/mtab

As you can see, there is a lot of mount information in the /etc/mtab file.

You can find the same information with the mount command as you can see in the screenshot below.

$ mount

As the /etc/mtab file or the mount command’s output has many mount entries, it’s hard to interpret it. You can use the grep command to filter the output and find what you need very easily.

For example, to find the filesystem type of the sda1 partition using either the mount command or /etc/mtab file, run one of the following commands:

$ cat /etc/mtab | grep /dev/sda1

Or,

$ mount | grep /dev/sda1

As you can see, the filesystem type of the sda1 partition is FAT32/vfat

.

In the same way, to find the filesystem type of the sda5 partition using either the mount command or /etc/mtab file, run one of the following commands:

$ cat /etc/mtab | grep /dev/sda5

Or,

$ mount | grep /dev/sda5

As you can see, the filesystem type of the sda5 partition is EXT4.

Way 6: Using the /etc/fstab File

The /etc/fstab file keeps an entry for each of the storage devices or partitions that is to be mounted automatically at boot time. So, you can read this file to find the filesystem type of your desired storage device or partition.

Suppose your computer is not configured to mount a storage device or partition at boot time automatically. In that case, it’s very likely that there won’t be any entry for that storage device or partition in the /etc/fstab file. In that case, you won’t find any information on that storage device or partition in the /etc/fstab file. You will have to use the other methods described in this article to find the storage device’s filesystem type or partition.

You can read the contents of the /etc/fstab file with the following command:

$ cat /etc/fstab

The contents of the /etc/fstab file.

You can see that the storage device or partition with the UUID 3f962401-ba93-46cb-ad87-64ed6cf55a5f uses the EXT4 filesystem.

The storage device or partition that has the UUID dd55-ae26 is using the vfat/FAT32 filesystem.

The lines starting with a # in the /etc/fstab file is a comment. These lines don’t have a real purpose. They are used for documentation purposes only.

If you want, you can hide them using the grep command as follows:

$ grep -v '^#' /etc/fstab

As you can see, the comments are gone, and the output looks a lot cleaner than before.

The /etc/fstab file uses UUID instead of the storage device name or partition name by default. You can use the blkid command to convert the UUID to storage device name or partition name.

For example, to convert the UUID 3f962401-ba93-46cb-ad87-64ed6cf55a5f to the name of the storage device or partition, run the blkid command as follows:

$ blkid -U 3f962401-ba93-46cb-ad87-64ed6cf55a5f

As you can see, the partition sda5 has the UUID 3f962401-ba93-46cb-ad87-64ed6cf55a5f.

In the same way, you can find the storage device or partition name that has the UUID DD55-AE26 as follows:

$ blkid -U DD55-AE26

As you can see, the partition sda1 has the UUID DD55-AE26.

Conclusion:

This article has shown you different ways to determine the filesystem type of a storage device/partition in Linux. I have shown you how to use the df, lsblk, blkid, file, and mount command to determine the filesystem type of the Linux storage devices and partitions. I have also shown you how to determine the filesystem type of the storage devices and partitions of your Linux system by reading the /etc/mtab and /etc/fstab files.

References:

[1] File system – Wikipedia – https://en.wikipedia.org/wiki/File_system ]]> How To Hide Files Inside Images In Linux https://linuxhint.com/hide_files_inside_images_linux/ Sun, 27 Dec 2020 16:49:34 +0000 https://linuxhint.com/?p=83283

Today, we use personal computers as workstations and personal devices. On these devices, we keep personal information and private files not intended for public access.

Given this, even if you do not share your computer with others, it’s essential to treat your security as a high priority and secure your files with cryptography and encryption methods.

This tutorial discusses how to protect and secure your files by hiding them inside other files. For this tutorial, we will look at how to hide files in images; as a bonus, we’ll also discuss how to hide files in audio files.

NOTE: The methods discussed in this tutorial do not guarantee 100% security; a security professional or forensics analyst can crack them. That said, disguising private files you want to secure is better than leaving them exposed.

A Basic Introduction to Steganography

Steganography refers to the process of hiding a file, whether a video, image, audio, or text, inside another file. Although steganography is an old way of hiding files and messages, it can be very useful when working in an unsecured environment.

Steganography is much more advantageous compared to encryption. For example, a malicious user is likely to ignore a secret document hidden inside an image of your cat than a file encrypted with GPG.

Some of the other advantages of steganography include:

  • Steganography does not attract attention compared to other methods of encryption.
  • It is simple to understand and use.
  • Once a file is hidden, it remains in that state until exposed.

Having looked at what steganography is and its pros, let’s get rollin’ in the deep:

How to Use the Cat Command to Hide Files in Images

The first method we can use to hide files inside an image is the cat command in Linux.

To do this, you will need to have a zip file containing all the files you wish to hide and an image.

Start by creating a directory and add all the files you wish to hide. Next, compress the directory into zip format.

Now move the compressed file and the image you wish to use to hide the files into the same directory.

Next, launch the terminal and navigate to the directory location where the zip and the image are.

All you have to do now to hide the files is concatenate the zip and the image to an appropriately named image—you can call the image anything you want.

Here’s an example:

Once you have hidden the files, remove all other raw files to ensure security. To view the files, unzip the image containing the hidden files.

How to Hide Files in Images Using Outguess

We can also use a tool to perform image steganography. The Outguess tool allows you to hide data in redundant bits of existing files. It mainly supports files such as JPEG and NETpbm formats.

Outguess is a widely used tool in BSD systems. You can read the official documentation available here:

https://linkfy.to/goBSDmanualpages

You can also install it using your default package manager. For example, to install it on Debian, simply enter the command:

sudo apt-get install outguess

Once installed, navigate to the directory where you have your secret files and the image you want to use as your file-hiding location. Use the following command to hide your files inside an image (image.jpg) and a passphrase

sudo outguess -k “passphrase” -d secrefile.txt image.jpg output.jpg

The above command will output the image containing hidden files. You can extract them using the command

outguess -k “passphrase” -e -r output.jpg secretfile.txt

How to Use Steghide for Image and Audio Steganography

Another tool we can use for image and audio steganography is Steghide. Steghide is a simple command-line tool capable of hiding data in image and audio files. The tool is powerful mainly because it does not alter the colour-respective sample-frequencies, making it immune to first-order statistical checks. Steghide allows compression and encryption of the embedded data, making it a good choice for steganography.

https://en.wikipedia.org/wiki/Colors_of_noise

Here’s how to use this tool for that purpose:

How to Install Steghide

Unless you are using a penetration distribution, Steghide does not come pre-installed in many Linux distributions. However, it is available in the main repositories, making it easy to install.

To install it on Debian/Ubuntu-based distributions, enter the command:

sudo apt-get install steghide

For Arch-based distributions, use the command

sudo pacman -S steghide

Once you have Steghide installed, you can hide files you want inside an image or an audio file; the examples below illustrate that.

Ensure you move the files you want to hide—and the image or audio file you want to hide them in—into the same folder.

Next, enter the following commands to hide the files

steghide embed -ef secretfile.txt -cf image.jpg

This command will prompt you to provide a passphrase. Enter your passphrase and continue.

To extract the file from the image, use the command:

steghide extract -sf image.jpg

Enter the passphrase you used when embedding the files.

How to Hide Files In Images Using Stegosuite

The final steganographic tool we are going to discuss is Stegosuite. Stegosuite is a simple graphical image steganography tool written in java that uses AES encryption to embed data. The tool currently supports file formats such as BMP, GIF, JPG, and PNG.

To install Stegohide on Debian/Ubuntu-based distributions, use the command:

sudo apt-get install stegosuite

Using Stegosuite is simple; once installed, launch the tool.

In the main menu, select the file –> Open and select the image you wish to use to embed the files. Next, right-click on the box and select add files.

Now select the files you wish to hide inside the image. Finally, provide the passphrase and click Embed.

That will create an embedded image inside the file of the original image location with the name imagename_embed.ext. For example, if the main image is image.jpng, the output file will be image_embed.png.

To extract data, open the file, enter the password, and click Extract.

Conclusion

This tutorial has taught you various methods you can use to hide files in images and audio files. For additional security, consider using hidden directories and encrypted zip files, and then hide them inside an image. That will give your files an extra layer of security from prying eyes.

]]>
How to Find Text in Files in Linux https://linuxhint.com/find_text_in_files_linux/ Tue, 22 Dec 2020 13:20:54 +0000 https://linuxhint.com/?p=82471

For a system administrator, working with text files is a common phenomenon. Maybe need to find a specific section from piles of log files for troubleshooting something? Or, need to find the document that contains essential information quickly?

In the case of Linux, there are numerous methods to find texts in files. It’s possible using both built-in tools and 3rd-party apps. Check out how to find texts in files in Linux.

Finding text in files

Depending on the number of files you have to perform a search on, there are two ways to perform the text search: automated or manual. If you have to work with a couple of text files, the manual search is more suitable. However, if there are hundreds of text files, then the automated search is the most efficient.

For automated search, we’ll be using grep. Grep comes pre-installed on any Linux distro. As for manual search, any modern text editor will do the job.

Find text in files using grep

In Linux, grep is the default tool for searching texts. Its name is derived from the ed command g/re/p that stands for “globally search for a regular expression and print matching lines.” It’s available on any modern Linux distro.

Grep is a command-line tool. Its command structure is as follows.

$ grep <option> <regular_expression> <file_path>

As the name of grep suggests, the pattern to search for is described using a regular expression. The regular expression is a special type of string that describes a pattern to match, locate, and manage. To learn more about grep and regular expression, check out using grep and egrep with regular expression.

For demonstration purposes, grab a sample text file. In this example, download the GNU General Public License v3.0 text file.

Basic search

The fundamental way of using grep is to search for a basic string.

Take a look at the following grep command. It’ll search for the word “GNU” in the text file.

$ grep "GNU" gpl-3.0.txt

To show the line number, use the “-n” flag.

$ grep -n “GNU” gpl-3.0.txt

To perform a case-insensitive search using grep, use the “-i” flag.

$ grep -ni “gnu” gpl-3.0.txt

You may not want to see the search matches but only the file name where the match happened in some situations. To print only the filename, use the “-l” flag. Here, the asterisk denotes to use all the text files in the current directory.

$ grep -l “gnu” *

We can also pipe the output of other commands to grep.

$ cat gpl-3.0.txt | grep -n “GNU”

Regular expression

Regex offers a smart way of fine-tuning the search. It has its own rules. However, different applications and programming languages implement regular expression differently. Here are a couple of examples that you can use with grep.

To define that the string is to be found at starting a line, use the caret (^) symbol.

$ grep -n “^GNU” gpl-3.0.txt

To define that the string is to be found at the end of a line, use the dollar sign ($).

$ grep -n “to$” gpl-3.0.txt

To describe that there can be any character at a certain location of the pattern, use the period character (.). For example, the expression “G.U” is valid if there’s any character between “G” and “U”.

$ grep -n “G.U” gpl-3.0.txt

To describe that there can be a subset of characters at a particular location of the pattern, use the brackets ([]). For example, the expression “t[wo]o” tells that the match is valid for “two” and “too” only.

$ grep -n “t[wo]o” gpl-3.0.txt

Extended regular expression

As the name suggests, an extended regular expression can do more complex things than basic regular expressions. To use extended regular expression with grep, you have to use the “-E” flag.

$ grep -nE <extended_regex> <file>

To search for two different strings, use the OR operators (|).

$ grep -nE “GNU|General|License” gpl-3.0.txt

Finding text in files

Now comes the main part. Instead of manually telling grep the file to perform the search on, grep can do it automatically. In the following command, grep will use all the available text files in the current directory for searching the pattern.

$ grep <regex> *

If you want to grep to perform the search on a different directory, then you have to specify the location.

$ grep <regex> <directory_path>

If there are folders, grep doesn’t explore them by default. To tell grep to search recursively, use the “-R” flag.

$ grep -nR <regex> <directory_path>

Grep GUI

If you prefer to work with GUI but still want to enjoy grep’s features, then check out searchmonkey. It’s a front-end solution for grep. The package is available on almost all the major Linux distros.

Find text in files using nano

GNU Nano is a simple and powerful text editor that comes with any Linux distro. It has built-in features to search for text in a text file.

Note that in this method, you have to open the text file, and search manually. It’s doable if there’s only a handful of text files to work with. If there’s more, then using grep is the most optimal choice.

Open the text file in nano.

$ nano <file_path>

To search for a string match, press “Ctrl + W”. After typing the string to search for, press “Enter”.

Find text in files using Vim

Vim is a well-known and reputed text editor. It’s the command-line equivalent of a modern text editor. Vim comes with numerous advanced features like plugins, macros, auto-completion, filters, etc.

Similar to nano, Vim works with a single file at a time. If you have multiple text files, then using grep is the most optimal way to go.

To search in a text file, first, open it in Vim.

$ vim <file_path>

Enter the following Vim command and hit “Enter”.

$ :/<search_term>

Find text in files using GNOME Text Editor

The GNOME Text Editor is the text editor that comes with the GNOME desktop. It’s a simplistic text editor with all the basic features you’d expect. It’s a nice alternative to the command-line text editors.

Similar to nano and vim, the same caution applies to this method. If the number of text files is large, then you better stick with grep.

Open the text file in Text Editor. Press “Ctrl + F” to bring up the search bar.

Find text in files using VS Code

Visual Studio Code is a powerful text editor with tons of features. It’s optimized for programmers to be used as if it’s a full-fledged IDE. It’s available on almost all the major Linux distros.

Install the Visual Studio Code snap package.

$ sudo snap install code --classic

Open the text file in VS Code. Press “Ctrl + F” to start searching.

Final thoughts

There are numerous ways to search text in files. It’s an easy task to master. It’s strongly recommended to master the grep command because it offers the most value in terms of efficiency and ease-of-use.

If you prefer GUI, then there are numerous text editors to choose from. Any modern text editor will provide the text search option.

Happy computing!

]]>
Best Dual Pane File Managers for Linux https://linuxhint.com/best_dual_pane_file_managers_linux/ Sun, 29 Nov 2020 17:58:09 +0000 https://linuxhint.com/?p=78491

This article will cover a list of free and open source dual-pane and multi-pane file managers available for Linux. These file managers provide a broader look at various files and folders stored on your storage devices. They also improve overall productivity and file handling experience, especially if you regularly navigate through a lot of files using keyboard shortcuts.

Midnight Commander

Midnight Commander is an open source file manager that runs in text mode in terminal emulators. It lists files and directories in a dual-pane layout where users can switch between panes using <TAB> key. It also supports mounting of remote file systems. Most of its text based user interface elements can be navigated through arrows keys and other keyboard shortcuts. However, some elements of the file manager can be accessed using mouse clicks as well. The bottom row shows frequently used file manager commands for easier accessibility.


You can install Midnight Commander in Ubuntu by running the command specified below:

$ sudo apt install mc

Midnight Commander can be installed in other Linux based distributions from the package manager or from its official website.

You can launch Midnight Commander by executing the command below:

$ mc

Double Commander

Double Commander is a dual-pane, graphical file manager that can be installed in both GTK and Qt user interfaces. Its main features include customizable panes, user defined columns, batch rename tool, a built-in text editor, file previewer, support for compressed archives, simple and full text search options,  background operations, customizable toolbar and so on.


You can install GTK or Qt versions of Double Commander in Ubuntu by running the commands specified below:

$ sudo apt install doublecmd-gtk

$ sudo apt install doublecmd-qt

Double Commander can be installed in other Linux based distributions from the package manager or from its official website.

Krusader

Kruaser is an open source, dual-pane file manager written using Qt and KDE libraries. Inspired by other other multi-pane file managers like Midnight Commander and Double Commander, Krusader features local and remote filesystem mounts, remote file transfers, compressed archives, powerful search tools, a built-in text editor, file previewer, batch rename tool, customizable panes and a robust plugin system.


You can install Krusader in Ubuntu by running the command specified below:

$ sudo apt install krusader

Krusader can be installed in other Linux based distributions from the package manager or from its official website.

Sunflower

Sunflower is an open source, dual-pane file manager for Linux. Written in Python3 and GTK3, Sunflower features customizable panes, tabbed browsing, user sessions, embedded terminal, keyboard-only navigation, batch rename tool, bookmarks, detailed file transfer dialogs and so on.


You can install Sunflower in Ubuntu by downloading the “.deb” package from here. Sunflower can be installed in other Linux based distributions from the package manager or from its official website.

Vifm

Vifm is an ncurses based, dual-panel file manager that runs in a terminal emulator. It features user modes and keyboard shortcuts identical to Vi or Vim text editor. Other features of Vifm include color schemes, user sessions, remote commands, mount points, background operations, tree comparisons, markers, bookmarks, batch rename tool, advanced search tool, miller column view, trash bin and so on.


You can install Vifm in Ubuntu by running the command specified below:

$ sudo apt install vifm

Vifm can be installed in other Linux based distributions from the package manager or from its official website.

You can launch Vifm by executing the command below:

$ vifm

SpaceFM

SpaceFM is an open source file manager that features tabbed browsing and multi-pane layouts upto four panes. Other main features of SpaceFM include tree view, bookmarks, drag and drop navigation, media thumbnails, real-time search tool, archive management, batch rename tool, advanced sort and filter tools, extensions, a dedicated task manager, mount point management, daemon mode, remote mount points and so on.


You can install SpaceFM in Ubuntu by running the command specified below:

$ sudo apt install spacefm-gtk3

SpaceFM can be installed in other Linux based distributions from the package manager or from its official website.

4Pane

4Pane is an open source file manager that allows you to use two dual-pane layouts at once. These panes work in pairs, the first two panes complement each other and the other two panes also work in tandem. You can hide any set of panes to have only one dual-pane layout. Other features of 4Pane include remote file management, archive management, embedded terminal emulator, batch rename tool, advanced search tools, undo and redo operations, and so on.


You can install 4Pane in Ubuntu by running the command specified below:

$ sudo apt install 4pane

4Pane can be installed in other Linux based distributions from the package manager or from its official website.

Last File Manager

Last File Manager or LFM is an open source, console based file manager inspired by Midnight Commander. It features a built-in text editor, bookmarks, search functionality, virtual file systems, filters, customizable user interface elements, color schemes, embedded CLI shell, custom keyboard shortcuts and so on.


You can install Last File Manager in Ubuntu by running the command specified below:

$ sudo apt install lfm

Last File Manager can be installed in other Linux based distributions from the package manager or from its official website.

You can launch Last File Manager by executing the command below:

$ lfm

Conclusion

These are some of the most popular dual-pane and multi-pane file managers available for Linux. While these file managers may seem cluttered and a little verbose at times, they are really useful if you want to quickly navigate through multiple files at once and run simultaneous file operations.

]]>
Multiple Ways to Transfer Files Between Your Computer and Cloud Linux Server https://linuxhint.com/linux-server-file-transfer/ Sat, 28 Nov 2020 19:54:54 +0000 https://linuxhint.com/?p=78458 There are multiple methods you can use to transfer files between your machine and Linux server, some of which we’ll discuss in this article.

  • using the SCP command in SSH
  • using Netcat
  • using FTP
  • using Python’s Simple HTTP Server

Using SCP (SSH)

SCP is a utility used to move files and directories securely via SSH. With the SCP command, you can transfer files from your computer to your Linux server and vice versa. As this utility uses SSH to move files, you’ll need the SSH credential of your server to transfer files.

SSH comes pre-installed on most Linux servers, but if not, you can install and enable it using the following steps.

Open the Ubuntu terminal and type.

$ sudo apt install -y openssh-server
$ sudo service ssh start

Upload files via SCP

Scp command follows this pattern

$ scp [Options] [Source] [Destination]

To transfer a file from your computer to a linux server, write these commands

$scp /path/of/your/local/file.ext usrename@linux-server-IP:/path/of/ file.ext -i key.pem

In the above command, first, you have to give the path of the file you want to copy from your computer to the Linux server, then the username and IP address of the Linux server, and the path where you want to copy the file on the Linux server fallowing this pattern (username@remote-server-IP: path/of/remote/file.ext).

After running this command, it will require the password of the Linux server user account

$ username@remote-server’s password :

After entering the password, the file will be uploaded.

Download files via SCP

To download files from the Linux server to your computer, you need to provide SCP with the local path of the file or directory and the path on the Linux Server where you’d want your file to be uploaded.

$ scp username@linux-server-ip:/path/of/file.ext  /path/to/destination

After running this command, it will require the authentication password of the linux server. Once you have entered the password, then the file will be copied safely to your computer.

SCP Command-Line Options

You can use different flags(known as command-line options) in the SCP command.

-p flag is used to change the port. By default, ssh uses the 22 port, but with the -p flag, we can change port 22 to something else, like 2222.

$ scp -p 2222 path/of/your/local/file.ext username@linux-server-ip: path/of/file.ext

-r flag is used to copy the folder and all of its content.

$ scp -r /path/of/your/local/folder username@linux-server-ip: /path/of/folder

-i flag is used to authenticating the connection using a cryptographic key pair stored in a file instead of a username and password.

$ scp -i path/of/your/local/file.ext username@linux-server-ip: path/of/file.ext

-c flag is used to compress the data that you want to transfer.

$ scp -c path/of/your/local/file.ext username@linux-server-ip: path/of/file.ext

-q flag is used to suppress the non-error message and progress meter.

$ scp -q /path/of/your/local/file.ext username@linux-server-ip: /path/of/file.ext

Transfer Files Using Netcat

Netcat is a Linux utility used for raw tcp/ip communication, transferring files, port scanning, and network troubleshooting, etc. It comes pre-installed in many Linux-based systems, and it is mainly used by Network Administrators.

If not already installed, you can install Netcat by typing the following command

$ sudo apt-get install netcat

To transfer files using Netcat, you have to type these commands. Turn the Netcat server on listening mode on any port, e.g.(port 4747), and type the path of the file you want to send.

$ nc -l -p 4747 < path/of/file.ext

On the receiving host, run the following command.

$ nc sending-server.url.com 4747 > path/of/file.ext

Note: The server sending file will use less than sign in the command ‘<’ while the receiving computer will have ‘>’ in the netcat command.

You can also transfer directories. Set the receiving host to listen on a port, e.g. (4747).

$ nc -l -p 4747 | tar -zxfv  /path/of/directory

Send it to the receiving host listing on the port.

$ tar czvf - /path/of/directory | nc receiving-hast.url.com 4747

The directory will be transferred. To close the connection, press CTRL+C

Transfer Files Using FTP

FTP (file transfer protocol) is used to transfer files between computers or clients and servers. It is faster than HTTP and other protocols in terms of file transfer because it is specifically designed for this purpose. It allows you to transfer multiple files and directories, and if there is any interruption in the connection during the transfer, the file will not be lost. Instead, it will resume transferring where it got dropped.

You can install an FTP server like vsftpd using apt by running this command.

$ sudo apt install -y vsftpd

After the package has been installed, you have to start the service by typing.

$ sudo systemctl start vsftpd
$ sudo systemctl enable vsftpd

Then you can connect to the FTP server by typing the command FTP and the IP address.

$ ftp [IP_Address]

It will ask you the username and password of the FTP server. After you have entered the username and password, you will be connected to your FTP server.

You can list out all the contents of the server by executing this command.

ftp> ls

Download via FTP

If you want to download any file from the FTP server, then you can get it by typing the command.

ftp> get  path/of/file

The file will be downloaded. You can also use different wildcards to download multiple files in a directory. For example ;

ftp> mget  *.html

It will download all the files with the extension “.html” .

You can also set up a local directory for downloaded files from the FTP server by using the lcd command.

ftp> lcd  /home/user/directory-name

Upload files via FTP

To upload files on the FTP server, type the following command.

ftp> put  path/of/local/file

The file will be uploaded to the FTP server. To upload multiple files, type commands.

ftp> mput  *.html

It will upload all the files with the extension “.html” .

Downloading  files using Python

Python has a module called ‘http.server’, which is used to transfer files, but with it, you can only download files.

If you don’t have the python installed, then type the following command.

$ sudo apt install -y python3

To turn on the python server, use the command.

$ sudo  python3  -m  http.server  4747 #[port e.g.(4747)]

Now the python server is listening on port 4747.

Go to your web browser and type the IP address and port no. on which the python server is listening.

http://IP_Address:4747/

A page will open containing all the files and directory on the python server. You can go into any directory and download the files.

You can go into any directory and download any file.

Conclusion

SCP, Netcat, FTP, and Python are commonly used methods to transfer files. All of the above methods of transferring files and directories are fast, reliable, and used in modern days. There are a lot of other techniques as well; you can adopt any method you prefer.

]]>
How to Manage Log Files with Logrotate? https://linuxhint.com/manage_log_files_with_logrotate/ Tue, 27 Oct 2020 19:48:45 +0000 https://linuxhint.com/?p=74233

One of the most interesting and important things about the Linux system is var/log. All the activities of running services on your system are written into a file inside this directory. These files are called logs, through which you can examine how your system is operating. By using these logs, administrators can troubleshoot the system. If these log files kept on your system forever, they would finally reside the whole space on the filesystem. To prevent these problems, we need a tool for the management of all log files. So, administrators can use a ‘logrotate’ tool that cleans up the logs files on some periodical basis.Logrotate is a Linux based command-line tool used to manage the log files which are made by system processes. It automatically removes the old logs and compresses the logs into the more convenient logs form to conserve your system resources. Using this tool, users have full control over when and how log rotation is processed.In this article, you will see by using the Logrotate tool how you can manage log files on your Linux system. We have executed all steps on the terminal application on Ubuntu 20.04 system here. You should have ‘sudo’ command privileges. Launch the command line ‘Terminal’ application by pressing the ‘Ctrl+Alt+t’ keys and start the implementation.

Install Logrotate on Ubuntu 20.4

On Ubuntu 20.04 the Logrotate utility is preinstalled, but if you don’t have this utility on your system, then update the system apt repository, and using the following command, you can install the Logrotate utility:

 $ sudo apt update

 $ sudo apt install logrotate


By using the following command, you can list all your system log files on the terminal:

 $ ls /var/log

Understanding about the Configuration file (logrotate.conf)

All the configurations of the logrotate utility are placed in the logrotate.conf file that you can find in /etc/logrotate.conf directory. If you open the ‘logrotate.conf’ file in your favorite editor, then you will see the following content of the configuration file:


All the configuration settings for Logrotate files are placed inside the /etc/logrotate.d directory.

 Include /etc/logrotate.d

Logrotate Options

Logrotate utility provides several directives that help us to configure logs, how they will be rotated, and what should be done right afterward. For example, open the syslog file in the editor by using the following command:

 $ vi /etc/logroate.d/syslog


Once you access its content, you will see the following options at the top of this file, which is highlighted in the following snapshot:

  • Rotate represents that this tool should be kept on how many logs files.
  • Daily represents that the tool will rotate logs daily. There are also other possible terms you can see here, such as weekly or monthly.
  • In the above image, missingok represents the logrotate to skip rotate, and if the log file is unfound, it will not give an error.
  • The notifempty represents that if the log file is empty, then skip to rotate. If an empty directive is found, then it will force to rotate all empty log files.
  • Compress and delaycompress means old logs should be compressed with gzip, except for the most recent log file.

Example # 01

Let’s take an example. We would like to run a log named ‘syslog’ with the help of the logrotate utility. It will read the rsyslog configuration file. In the example below, we are handling two logs using the logrotate tool. One is ‘syslog’ that will run for 7 rotations after 1 day, and the other one is ‘mail.info’ that will rotate on a weekly basis for 4 rotations. By using the following command, run the logs and analyze the output on the terminal:

 $ logrotate -d /etc/logrotate.d/syslog


Example # 02

Another example for logs rotation analysis is given below:

 $ logrotate -d /etc/logrotate.d/samba


In the screenshot below, you can read the configuration file of ‘samba’. You can analyze the output of the logrotate tool handling 3 different logs here. It rotates on a weekly basis for 7 rotations.

Conclusion

This is a comprehensive article about the logrotate tool. We have seen in detail how to use this utility on Ubuntu 20.04 system. Moreover, we have elaborated on how to read configuration files with the help of logrotate. From the above-mentioned details, I hope you get a clearer idea about the logrotate tool options. However, if you have any problem, then let us know via comments.

]]>
How to Create Hard Links Linux? https://linuxhint.com/how_to_create_hard_links_linux/ Tue, 27 Oct 2020 16:38:26 +0000 https://linuxhint.com/?p=74207

Linking is an interesting feature in Linux. In UNIX-like operating systems, everything is a file. A file is fundamentally a link to an inode, a special type of data structure that stores everything about a certain file except its original name and actual contents.This is the feature that links leverages. To create a link is to create another file that points to the same underlying inode as another file. In many situations, it’s an incredibly useful method.

Check out how to create hard links in Linux.

Hard links in Linux

Before diving deeper, let’s talk a bit about hard and soft links. There are some fundamental differences between them. In the case of a hard link, it can only exist in the same filesystem, while the symbolic link will persist cross-filesystems. Moreover, it can only be performed on regular files. You also can’t create directory hard links, so it doesn’t create a directory loop.

If one file of the hard link is deleted, it removes the link from the underlying inode.

The ls command can print the inode of a target file/directory.

 $ ls -li <file_or_dir>

Creating hard links

Generating a hard link is quite simple. To create links, ln is the dedicated tool available in almost all Linux distros.

Use the following command structure to create a hard link. Note that the destination should be within the same filesystem. The “-v” flag is for verbose mode.

 $ ln -v <source> <link>


Verify the result.

 $ ls -li <target>


As for directory hard linking, it’s not allowed. Hypothetically, it’s still possible to create, but most Linux distros disable that feature, even if you run the action with root privilege. For directory linking, use soft links.

Soft links

Soft linking is commonly referred to as symbolic links. Soft linking can be cross-filesystem. By definition, it’s not a standard file, but rather, a file that points to an existing file. Here, the soft link file will have a different inode value, but it points to the original file.

Just like creating hard links, we’ll be using the ln tool. To declare to create a soft link, add the “-s” flag.

 $ ln -vs <source> <destination>


Verify the result.

 $ ls -li <target>

If there’s already a link existing, then you may update it using the “-f” flag that forces ln to update the link without any confirmation. Alternatively, you could use the “-i” flag for interactive link creation.

 $ ln -sf <source> <destination>


Don’t forget to verify the result.

 $ ls -li <target>

Finding links

Assuming there are multiple links to the same file, keeping track of them can become difficult. In such a situation, use this method to find out all the links.

For this, we need the inode value of the original file. Use the following command to find out the inode number.

 $ ls -li <target_file>


Now, use the inode number to find out all the links to that file. Here, the current active directory should be the directory where the original file is located.

 $ find . -inum <inode_value>

Deleting links

If you want to disable a hard link, the way to do so is by deleting the linked file.

 $ rm <link>

Final thoughts

Linking is a powerful tool you can use in many situations. While it comes with its own limitations, it can offer excellent benefits to lots of scenarios.

Interested in more in-depth about the ln command? Check out how to use the ln command.

Happy computing!

]]>
How to Create Hard Link and Soft Link in Linux? https://linuxhint.com/create_linux_hard_and_soft_link/ Sun, 25 Oct 2020 06:03:15 +0000 https://linuxhint.com/?p=73293 In the Linux operating system, all the information about a file is stored in its respective inode. These inodes allow you to know all the metadata of a file. There is a concept of creating links to a file in Linux, just like we create pointers to the files in most of the popular programming languages. These links are basically of two types: the hard and the soft links. A hard link to a file is essentially an exact copy of the file, which means that a hard link to a file and the actual file will share the same inode. The biggest advantage of creating a hard link is that even if you accidentally delete the actual file, you will still be able to access its contents via its hard link.

On the other hand, a soft link or a symbolic link works exactly like a pointer or a shortcut to a file. It is not an accurate copy of the file but only points to the original file. A soft link to a file and the actual file will have different inode values. Moreover, if you delete the actual file at any time, you will not be able to access its contents via its soft link. Today, we will share with you the methods of creating a hard link and soft link to a file in Linux.

Note: We have used Linux Mint 20 for walking you through the methods shown below.

Method of Creating a Hard Link in Linux Mint 20:

For creating a hard link to a file in Linux Mint 20, we will perform the steps mentioned below:

First, we need to launch the terminal so that we can pass commands via the terminal in Linux Mint 20 for creating a hard link. We have also attached the image of the Linux Mint 20 terminal below:

Now you need to list down all the files present in your current working directory. You can also do this for any other directory of your choice by explicitly specifying its path. However, we preferred working with the Home directory so that we do not have to mention its path in our command below:

$ ls –l

This command will list all the contents of the working directory you are currently working on.

The contents of our Home directory are also shown in the following image:

Now select any file of your choice whose hard link you want to create. We have highlighted our selected file in the image shown above. Now we will attempt to create a hard link for the file named “awk.txt” by running the command shown below:

$ ln awk.txt abc.txt

Here, the first file will be the one whose hard link you want to create, whereas the second file specifies the name of the hard link to be created. You can use any name other than “abc.txt”.

After running this command, you need to list down the contents of your current working directory once again with the “ls” command to verify if a hard link to the file “awk.txt” has been created or not. Once you run this command, you will be able to see the exact clone of “awk.txt” with the name “abc.txt” in your current working directory as highlighted in the following image:

Another way to verify it is to visit your Home directory by clicking on your File Manager icon. There, you will be able to see “awk.txt” along with “abc.txt” which is, in fact, the exact copy of the same text file. You can also open both of these files to verify if their contents are the same or not.

Method of Creating a Soft Link in Linux Mint 20:

For creating a soft link to a file in Linux Mint 20, we will perform the steps mentioned below:

We need to run the “ls” command once again to check the contents of the current working directory, as we did in the method shown above. This time, we have selected another file named “Bash.sh” for creating its soft link as highlighted in the following image:

After selecting a file for creating its soft link, we need to execute the below-mentioned command in our Linux Mint 20 terminal:

$ ln –s Bash.sh NewBash.sh

Here, the “-s” flag indicates that we are going to create a soft link to a file; the first file refers to the file whose soft link is to be created, whereas the second file refers to the name of your soft link or the pointer to your first file. You can have any name of your choice for the soft link of this file.

After running this command, you need to list down the contents of your current working directory once again with the “ls” command to verify if a soft link to the file “Bash.sh” has been created or not. Once you run this command, you will be able to see the soft link named “NewBash.sh” which will be pointing to the file named “Bash.sh” in your current working directory, as highlighted in the following image. Moreover, you will also be able to see the “l” flag in the highlighted entry, which further indicates that the link you have just created is merely a pointer to the file and not the exact copy of the file.

Another way to verify it is to visit your Home directory by clicking on your File Manager icon. There, you will be able to see “Bash.sh” and “NewBash.sh” which is, in fact, the soft link to the former file. You can also see an arrow located on the “NewBash.sh” file, which shows that it is kind of a shortcut or a link to the file “Bash.sh” and not its exact copy as highlighted in the image shown below:

Conclusion:

By explaining to you the methods of creating the hard links and soft links to a file in this article, we have enabled you to create either of these links to any file of your choice according to your requirements. We have tried to demonstrate these methods in the easiest way possible.

]]>
How to Copy a Folder in Linux? https://linuxhint.com/copy_a_folder_in_linux/ Sun, 25 Oct 2020 05:46:49 +0000 https://linuxhint.com/?p=73277 The files and folders are commonly used in any operating system. At times, your folder contains some crucial data, and you prefer to keep several backup copies. The first solution that comes to our mind is to copy that folder somewhere else. Therefore, in this article, our target is to figure out all the methods of copying a folder in Linux, i.e., both the CLI-based methods and the GUI-based methods.

Note: For explaining the different methods of copying a folder in Linux, we have made use of Linux Mint 20.

Methods of Copying a Folder in Linux:

Following are the four most common methods of copying a folder in Linux:

Method # 1: Using the Linux GUI:

This is the easiest method of copying a folder in Linux, which is also very commonly used in other operating systems. You need to perform the following steps to copy a folder in Linux using this method:

First, we have to create a folder for demonstration in our Home directory named “CopyFolder”.

The folder that we have created is shown in the image below:

For launching a pop-up menu, you should right click on this folder. Once the menu is launched, we will choose the “Copy” option from this menu, as shown in the following image:

In this example, we intend to copy our “CopyFolder” to the “Documents” folder. Therefore, we will double click on the “Documents” folder to open it. Then while on the “Documents” folder, we will right click on its empty space to launch a pop-up menu again. Now we will select the “Paste” option from the menu, which has just launched as highlighted in the image shown below:

After doing this, you will notice that your “CopyFolder” or any other selected folder has been copied to the “Documents” folder or any other folder that you have chosen, as shown in the following image:

Method # 2: Using the “cp” Command:

This method and the two other methods shown below are Linux Mint 20 terminal based. We will follow the steps mentioned below for making use of this method copying a folder in Linux:

Since this method is terminal-based, therefore, we will launch the Linux Mint 20 terminal as shown in the following image:

You should enter the following command in your terminal once it has been launched:

$ cp –r NameOfFolderToBeCopied DestinationPath

Here, you have to provide the actual name of the folder to be copied instead of NameOfFolderToBeCopied, and the actual path to where you want to copy that folder instead of DestinationPath. In the scenario which we are discussing, we intend to copy the “CopyFolder” to our “Documents” folder. Hence, we have written “CopyFolder” instead of NameOfFolderToBeCopied. Also, the path to the “Documents” directory instead of DestinationPath, as shown in the image below:

Once you have pressed the “Enter” key to execute the above-mentioned command, your desired folder would have been copied to the specified destination. You can also confirm if the desired operation has taken place or not by running the following command in your terminal:

$ ls –l DestinationPath

Here, you should provide the path to the place where you have copied your folder instead of the DestinationPath.

Running this command will list down all the contents of the “Documents” directory, which will also contain the folder that you have just copied, i.e., the “CopyFolder”, as shown in the image below:

Method # 3: Using the “rsync” Command:

In using the “rsync” command to copy a folder in Linux Mint 20, we will have to perform all the steps listed below:

First, we need to install the “rsync” command, if it has not already been installed, by executing the following command in our terminal:

$ sudo apt-get install rsync

Once this command has been installed on your system, your terminal will reflect the output shown in the image below:

Now, when the “rsync” command has been successfully installed on your system, you have to execute the following command in the terminal:

$ rsync –avz NameOfFolderToBeCopied DestinationPath

Here, you have to provide the actual name of the folder to be copied instead of NameOfFolderToBeCopied and the actual path to where you want to copy that folder instead of DestinationPath. In the scenario which we are discussing, we intend to copy the “CopyFolder” to our “Documents” folder. Hence, we have written “CopyFolder” instead of NameOfFolderToBeCopied. As well as the path to the “Documents” directory instead of DestinationPath as shown in the following image:

Once you have executed this command, your terminal will show you a confirmation message depicting that the specified operation has been successfully performed, as shown in the image below:

You can also confirm it by executing the “ls” command, as described in the method above.

Method # 4: Using the “scp” Command:

This is yet another terminal-based method of copying a folder in Linux, which can be followed in the manner shown below.

The “scp” command can be used to copy a folder in Linux in the following way:

$ scp –r NameOfFolderToBeCopied DestinationPath

Here, you have to provide the actual name of the folder to be copied instead of NameOfFolderToBeCopied and the actual path to where you want to copy that folder instead of DestinationPath. In the scenario which we are discussing, we intend to copy the “CopyFolder” to our “Documents” folder. Hence, we have written “CopyFolder” instead of NameOfFolderToBeCopied. Also, the path to the “Documents” directory instead of DestinationPath as shown in the following image:

Once you have executed this command, you can confirm if your folder has been copied to the specified destination or not by running the “ls” command once again.

Conclusion:

All the methods demonstrated in this article are extremely easy to follow. These methods are capable of copying a folder to any specified destination within a few seconds. By following any of these methods, you can copy as many folders as you want and at any place of your choice while using the Linux operating system.

]]>
How to install and Configure Nemo File Manager in Linux https://linuxhint.com/installing_nemo_file_manager_linux/ Fri, 31 Jul 2020 11:14:44 +0000 https://linuxhint.com/?p=64448 Nemo is a relatively new file manager that ships by default in Linux Mint. It is part of the Cinnamon desktop environment stack on Linux Mint and is a fork of Nautilus file manager (also known as GNOME Files) that ships with Ubuntu and other distributions that use GNOME shell. Ubuntu Budgie has also adopted Nemo as its default manager since its 20.04 release. This article will cover the installation and configuration of Nemo file manager.

Rationale Behind the Development of Nemo File Manager

GNOME shell and many GTK-3 apps embraced a minimalistic approach by simplifying the user interface. In this process, some features were removed, some were relocated, and some were stripped down. The result was that GNOME-3 applications turned out to be a whole lot different than GNOME-2 applications. Many Linux distributions and desktop environments use the GNOME application stack as a base, and the development of GNOME-2 applications stopped with the advent of GNOME-3. Developers had to choose whether to stick to a fully-featured, but older application stack or embrace the new, minimalistic GNOME-3 suite.

Linux Mint developers decided to go with the old, tried and tested, feature-packed desktop environment layout that is friendly for both casual and power users. Since many GNOME-2 apps were almost defunct, Linux Mint developers created new apps, forked some of the old and new apps, and developed a new desktop environment called “Cinnamon”. These forked apps received new features and patches. Nemo file manager is one such app forked from the Nautilus file manager.

Main Features of the Nemo File Manager

New and improved features that make Nemo File manager different than Nautilus file manager are:

  • Supports nested tree view for directories (called “list view” in Nemo)
  • Shows free hard disk space in the sidebar and bottom information bar
  • Includes a button for toggling location address bar (shows the address in readable string form)
  • Includes full menu bar by default (File, Edit, View and so on)
  • Includes a “directory up” button (goes to parent folder on click)
  • Supports plugins that add custom actions to the right-click menu (Send by Email etc.)
  • Supports side-by-side two-pane view
  • Includes support for opening files and folders by a single click
  • Includes an option to open any location as a root user
  • Supports automatic mounting of external media
  • Supports bulk renaming of files and folders
  • Unlike Nautilus file manager, Nemo allows toolbar customization
  • Supports many right-click actions by default, much more than Nautilus

Installing Nemo File Manager in Linux

To install Nemo file manager in Ubuntu, run the following command:

$ sudo apt install nemo

Maintainers of Nemo file manager don’t provide any installable packages. Major Linux distributions like Debian, Fedora and Ubuntu already have Nemo packages in their official repositories. You can search for the “Nemo” keyword in the package manager of your Linux distributions to install the app. In case it is not available in your Linux distribution, you may have to compile it from source code available here.

Once installed, search for “Nemo” in the application launcher to launch it. Note that both Nautilus and Nemo file managers may be named “Files” in the application launcher, but their icons are different. It may take a couple of tries to correctly identify the Nemo file manager in the application launcher.

Making Nemo Default File Manager

To check the current default file manager on your system, run the command below:

$ xdg-mime query default inode/directory

You will get some output like this (make a note of the line, it will be used in the next command):

org.gnome.Nautilus.desktop

To check what all mimetypes Nautilus is being used for, run the command below:

$ cat /usr/share/applications/defaults.list | grep org.gnome.Nautilus.desktop

You will get some output like this:

inode/directory=org.gnome.Nautilus.desktop

Note that in some distributions, “defaults.list” is called “mimeapps.list” and the exact location in the root folder may be slightly different.

Now to set Nemo as the default file manager, run the command below (the goal is to assign Nemo same mimetypes that are used for Nautilus file manager):

$ xdg-mime default nemo.desktop inode/directory

Since the output above shows only one mimetype for Nautilus, the command for setting Nemo as the default file manager changes only one mimetype. If you get multiple mimetypes when querying “defaults.list” file, use a command in the following format:

$ xdg-mime default nemo.desktop <mime/type1> <mime/type2>

To confirm the change, run the query command again:

$ xdg-mime query default inode/directory

You will now get some output like this:

nemo.desktop

Logout and re-login for the changes to take effect. Finally, to confirm that Nemo has been indeed set as the default file manager, run the command below:

$ xdg-open $HOME

If you have followed the instructions correctly so far, the home folder on your system will now open in the Nemo file manager instead of Nautilus.

To revert back to Nautilus, run the command below:

$ xdg-mime default org.gnome.Nautilus.desktop inode/directory

Note that desktop wallpaper and desktop icons are handled by the default file manager in GNOME-based Linux distributions. I will advise you to not to change the default file manager for desktop background rendering to avoid system issues.

Conclusion

Nemo is an extremely powerful and customizable graphical file manager for Linux. If you prefer a much more feature-packed and one-stop file manager for handling a lot of file actions, Nemo gets the job done. If you prefer a minimalistic, clutter-free user interface, Nautilus is always there.

]]>
Downloading Files on Linux using the Command Line https://linuxhint.com/download_files_linux_command_line/ Sun, 12 Apr 2020 18:44:21 +0000 https://linuxhint.com/?p=57913 In recent years, technology has evolved and grown significantly, highlighting the changes taking place in the digital world. These technological advancements have led to the creation of so many extraordinary tools and softwares that have significantly aided in making our lives easier.

Linux, a Unix based open-source operating system, is one example of such a software that only a few years back, didn’t have the specs to be used in desktops and as a result, was mainly considered for server development. However, with time, it has rapidly evolved, becoming a reliable and powerful operating system, which in turn has led to it gaining the attention of a large number of users.

The Command Line tool provided by Linux is one of its most powerful features that it offers to users and is also what makes it so fascinating and amazing to use. A command line is simply a text-based interface that takes in commands and forwards them to the OS which runs them. It is due to this flexible nature of it that it has gained an edge over the Graphical User Interface (GUI) and as a result, many users have switched to the Command Line for doing various tasks, one of which is the downloading of files.

Hence today we’ll be looking at two different ways on how to download files on Linux using the Command Line tool.

Downloading Files using Wget

One of the most popular command line tools for downloading files from the internet is Wget. Wget is a pretty versatile tool that supports multiple protocols such as HTTP, HTTPS and FTP and allows one to download multiple files and directories. It also provides users with a variety of features ranging from recursive downloading to playing and pausing the downloads as well as limiting its bandwidth.

Moreover, it is cross-platform which gives it quite the edge over many other command line downloaders as well as graphical downloaders.

How to Install Wget?

Wget usually comes pre-installed with most of the Linux Distributions. However, if a user is in possession of a system without Wget being installed, then the user needs to open the command line through either Ubuntu Dash or Ctrl+Alt+T shortcut and enter the following command:

$ sudo apt-get install wget

It is to be noted that the command given above is for only Debian based Linux systems such as Ubuntu. If a user has a Red Hat Linux system such as Fedora, then the user needs to enter the following command into the command line:

$ yum install wget

Features of Wget

As mentioned before, Wget has multiple features incorporated inside of it. The most basic operation that Wget offers to users is downloading files by simply using its URL. This can be done by inputting the following command into the terminal:

$ wget URL

Let us show an example to further clarify this. We will be downloading a simple image in the png format from the internet. See the image below for better understanding:

Wget also allows users to download multiple files from different URLs. This can easily be done by the following command:

$ wget URL1 URL2 URL3

Once again, we can show this using an example. We will be downloading two HTML files from two different websites. For better understanding, please look at the image below:

We can also change the name of the file from its original using the following command:

$ wget -O filename URL


Here filename refers to the name that you want to address the file as. Using this, we can also change the type of the file. This is shown in the image below:

Wget also allows users to recursively download their files which is basically downloading all the files from the website under a single directory. This can easily be done by the following command:

$ wget -r URL

For more information regarding Wget, users can input the following command into the terminal to get access to all the Wget commands that appear to be available:

$ wget --help

Downloading Files using Curl

Curl is another command line tool that can be used to download files from the internet. Unlike Wget, which is command line only, features of Curl are powered by libcurl which is a cross-platform URL transfer library. Curl not only allows downloading of files but can also be used for uploading and exchanging of requests with servers. Curl also has a much larger support range for protocols including the important ones such as HTTP, HTTPS, FTP, SFTP etc. However, Curl does not support recursive downloads which Wget offers.

How to Install Curl?

Similarly, like Wget, Curl comes pre-installed with most of the Linux Distributions. This can simply be checked by running the following command:

$ curl --version

However, if a user is in possession of a system without Curl being installed, then the user needs to open the command line through either Ubuntu Dash or Ctrl+Alt+T shortcut and enter the following command:

$ sudo apt-get install curl

It is to be noted that the command given above is for only Debian based Linux systems such as Ubuntu. If a user has a Red Hat Linux system such as Fedora, then the user needs to enter the following command into the command line:

$ yum install curl

Features of Curl

Just like Wget, Curl has multiple features incorporated inside of it. The most basic is its ability to allow users to download files from a single URL from the internet. This can be done by inputting the following command into the terminal:

$ curl -O URL

For better understanding, we will be downloading a simple image in the png format from the internet just like in the case of Wget.

Curl also allows users to change the filename and the type of the file. This can be done by the following command:

$ curl URL > filename

In the image above, we took a png file originally named pancake1.png and converted it to a zip file with the new name p.zip.

Just like in the case of Wget, Curl allows users to download multiple files using a number of URLs from the internet. This can easily be done by the following command:

$ curl -O URL1 -O URL2 -O URL3

For our example, we will use curl to download a jpg file and a png file from the internet. Results are shown in the image below:


A pretty amazing feature that Curl provides to its users is its ability to monitor the progress of the download of the file. This can be done by the following command:

$ curl -# URL > filename

For more information regarding Curl, users can input the following command into the terminal to get access to all the Curl commands that appear to be available:

$ curl --help

Best Command Line Method to Download Files

Wget and Curl are among the wide range of command line tools that Linux offers for the downloading of files. Both offer a huge set of features that cater to different needs of the users. If users simply want to download files recursively, then Wget would be a good choice. If users are looking to interact with the server or download a file built under a protocol that Wget doesn’t support, then Curl would be a better alternative.

]]>
What is /dev/null and How to Use It https://linuxhint.com/what_is_dev_null/ Fri, 20 Mar 2020 12:08:51 +0000 https://linuxhint.com/?p=56876 Linux is an interesting operating system that hosts some virtual devices for numerous purposes. As far as programs running in the system are concerned, these virtual devices act as if they are real files. Tools can request and feed data from these sources. The data is generated by the OS instead of reading them from a disk.

One such example is /dev/null. It’s a special file that’s present in every single Linux system. However, unlike most other virtual files, instead of reading, it’s used to write. Whatever you write to /dev/null will be discarded, forgotten into the void. It’s known as the null device in a UNIX system.

Why would you want to discard something into the void? Let’s check out what /dev/null is and its usage.

Prerequisites

Before diving deep into the usage of /dev/null, we have to have a clear grasp of the stdout and stderr data stream. Check out this in-depth guide on stdin, stderr, and stdout.

Let’s have a quick refresh. Whenever any command-line utility is run, it generates two outputs. The output goes to stdout and the error (if generated) goes to stderr. By default, both these data streams are associated with the terminal.

For example, the following command will print out the string within the double quotation mark. Here, the output is stored in stdout.

$ echo “Hello World”

The next command will show us the exit status of the previously-run command.

$ echo $?

As the previous command ran successfully, the exit status is 0. Otherwise, the exit status will be different. What happens when you try to run an invalid command?

$ adfadsf
$ echo $?

Now, we need to know about the file descriptor. In the UNIX ecosystem, these are integer values assigned to a file. Both stdout (file descriptor = 1) and stderr (file descriptor = 2) have a specific file descriptor. Using the file descriptor (1 and 2 in this situation), we can redirect the stdout and stderr to other files.

For starter, the following example will redirect the stdout of the echo command to a text file. Here, we didn’t specify the file descriptor. If not specified, bash will use stdout by default.

$ echo “Hello World” > log.txt

The following command will redirect the stderr to a text file.

$ asdfadsa 2> error.txt

Using /dev/null

Redirecting output to /dev/null

Now, we’re ready to learn how to use /dev/null. First, let’s check out how to filter normal output and error. In the following command, grep will try to search for a string (hello, in this case) in the “/sys” directory.

$ grep -r hello /sys/

However, it will generate a lot of error as without root privilege, grep can’t access a number of files. In such a case, it’ll result in “Permission denied” errors. Now, using the redirection, we can get a clearer output.

$ grep -r hello /sys/ 2> /dev/null

The output looks much better, right? Nothing! In this case, grep doesn’t have access to a lot of files and those that are accessible doesn’t have the string “hello”.

In the following example, we’ll be pinging Google.

$ ping google.com

However, we don’t want to see all those successful ping results. Instead, we only want to focus on the errors when ping couldn’t reach Google. How do we do that?

$ ping google.com 1> /dev/null

Here, the contents of stdout are dumped to /dev/null, leaving only the errors.

Redirect all output to /dev/null

In certain situations, the output may not be useful at all. Using redirection, we can dump all the output into the void.

$ grep -r hello /sys/ > /dev/null 2>&1

Let’s break this command a little bit. First, we’re dumping all the stdout to /dev/null. Then, in the second part, we’re telling bash to send stderr to stdout. In this example, there’s nothing to output. However, if you’re confused, you can always check if the command ran successfully.

$ echo $?

The value is 2 because the command generated a lot of errors.

If you tend to forget the file descriptor of stdout and stderr, the following command will do just fine. It’s a more generalized format of the previous command. Both stdout and stderr will be redirected to /dev/null.

$ grep -r hello /sys/ &> /dev/null

Other examples

This is an interesting one. Remember the dd tool? It’s a powerful tool for converting and copying files. Learn more about dd. Using dd, we can test the sequential read speed of your disk. Of course, it’s not an accurate measurement. However, for a quick test, it’s pretty useful.

$ dd if=<big_file> of=/dev/null status=progress bs=1M iflag=direct

Here, I’ve used the Ubuntu 18.04.4 ISO as the big file.

Similarly, you can also test out the download speed of your internet connection.

$ wget -O /dev/null <big_file_link>

Final thoughts

Hopefully, you have a clear understanding of what this /dev/null file is. It’s a special device that, if written to it, discards and if read from, reads null. The true potential of this interesting feature is in interesting bash scripts.

Are you interested in bash scripting? Check out the beginner’s guide to bash scripting.

Enjoy!

]]>
Extracting Metadata of a File using ExifTool https://linuxhint.com/get_filea_metadata_exif_tool/ Sun, 02 Feb 2020 16:21:01 +0000 https://linuxhint.com/?p=54405 ExifTool is a free and open source software program which is used to read, write and update metadata of various types of files such as PDF, Audio, Video and images. It is platform independent, available as a perl library as well as a command line application. Metadata can be described as information about the data such as file size, date created, file type, etc. ExifTool is very easy to use and gives a lot of information about the data. In this blog we will discuss different ways in which ExifTool can be used.

Installing ExifTool

It is quite easy to install ExifTool on Linux Machine. It can be installed by typing the following command in the terminal

ubuntu@ubuntu:~$ sudo apt-get install libimage-exiftool-perl

Now ExifTool is installed in your machine and is ready to use.

Extracting Entire Metadata of File

We can get entire metadata of a file by using the following command in the terminal

ubuntu@ubuntu:~$ exiftool <file_name>

When we type above command, we get all the information about file as shown below

It gives us a bunch of information about the file. In the above image all the details are not shown. You can see further details by scrolling down the terminal window.

We can use ExifTool with some options to extract specific data of the file. To see all the available options, type following command in the terminal.

ubuntu@ubuntu:~$ man exiftool

It will open the manual page for ExifTool, as shown below and we can see all the available options in this manual page. Some of these options have been  discussed here.

Extracting Common Metadata

We can extract the most common metadata of a file by using <common> option along with Exiftool command. Type the following command in the terminal to display common metadata of file.

ubuntu@ubuntu:~$ exiftool -common <file_name>

It will give us general information of the file as shown in the following image.

Extracting Location of the Image

Modern smartphones and digital cameras save GPS coordinates of the location, where image is captured, in each photo. We can extract GPS coordinates of the image by executing the following command in the terminal

ubuntu@ubuntu:~$ exiftool <file_name> | grep GPS

It will give us GPS coordinates of the location where the image was captured.

Extracting Specific Metadata

We can also extract specific metadata of file by using different options. You can see all the options in the manual page. Type the following command to see specific metadata

ubunut@ubuntu:~$ exiftool -<option> <file_name>

It will give us specific information specified by <option> field. We can also use more than one option as shown in the following image.

Creating Thumbnail Image

Thumbnail images can be described as a preview of original image which is less in size as compared to the original image. It describes how the original image looks like and can be opened quickly.

We can create thumbnail images by typing following command in the terminal

ubuntu@ubuntu:~$ exiftool -ThumbnailImage <file_name> > thumb.jpg

This will save the thumbnail of original image as “thumb.jpg” and this thumbnail will be lesser in size as compared to original image

We can see that thumbnail has been created and the size of thumbnail is just 86 bytes while the original image is 3.8 MB in size.

Extracting Metadata using Keywords

We can also extract our required metadata using keywords. For example, if we want to display image width using ExifTool, we will use width keyword to search for it. Following is the syntax to use keywords along with ExifTool.

ubuntu@ubuntu:~$ exiftool -”*width*<file_name>

When we type above command, it will give us all the tags related to width as shown in the following image.

We can see that all the tags related to “width” keyword have been displayed. In this way we can use any keyword to search for its related tags.

Verbose Mode of ExifTool

Verbose mode of ExifTool gives us more details of the file as compared to normal mode. We can go to verbose mode by using <-v> option along with ExifTool. The syntax of verbose mode is as follows

ubuntu@ubuntu:~$ exiftool -v <file_name>

In verbose mode, ExifTool will give us more information about the file as shown in the following image

Updating Metadata of a File

ExifTool provides us with the power to update the metadata of a file but this power is limited as we can not update all the tags of metadata. We can update some tags. Following is the syntax to update metadata of file

ubuntu@ubuntu:~$ exiftool -<tag_name>=”New_tag” <file_name>

This will change the <tag_name> to “New_tag” as shown in the image below

In the above image, can see that “F Number” tag has been updated from 4.0 to 6.0 and a new image has been created with the suffix of “_original”. The “F Number” tag in “image.jpg_original” will remain 4.0.

Some <tag_name> can not be updated like “Light Value”. When we try to update this <tag_name>, it will not change and gives a warning message as shown in the following image

In the above image neither the <tag_name> has been updated nor a new image with “_original” suffix has been created.

Removing Metadata of File

So far we have updated metadata and extracted metadata of a file. We can also remove metadata of a file using ExifTool. Metadata of a file can be removed by typing following command in the Terminal

ubuntu@ubuntu:~$ exiftool -all= <file_name>

When we type above command in terminal, not all but some metadata is removed. Following image explains it effectively

When we type above command, the original image is restored and a new image with changed metadata is created. We can see that metadata of the image is reduced.

Extracting Metadata of PDF Files

ExifTool is used not only with images, it can also be used to extract metadata of PDF and Video files too. The syntax to get metadata of PDF and Video files is same as that of images. Following image shows the metadata of PDF file

Conclusion

ExifTool is a powerful tool used to extract metadata of a file. It is used not only on images but some other formats of files like PDF and mp4 etc. It enables us to update and remove metadata of files and gives a lot of information about files.

]]>
How to Use KRename https://linuxhint.com/krename/ Mon, 27 May 2019 17:26:41 +0000 https://linuxhint.com/?p=41101 KRename is a batch file renaming utility for the KDE Desktop Environment. You can use it to easily rename multiple files at the same time using different patterns and conditions. You can use KRename plugins to read tags from JPEG/TIFF image files, read MD3 tags from music files such as MP3/OGG, read tags from PDF files, use JavaScript and many more to rename your files exactly as you want.

In this article, I am going to show you how to use KRename to rename multiple files on the KDE 5 Plasma Desktop Environment. I will be using Kubuntu 18.04 LTS for the demonstration in this article. But any modern Linux distribution that supports KDE Desktop Environment (such as Ubuntu/Debian, LinuxMint, Arch) should work just fine. So, let’s get started.

Installing KRename on Ubuntu/Debian from the Command Line:

On Ubuntu/Debian you can install KRename from the official package repository very easily.

First, update the APT package repository cache with the following command:

$ sudo apt update

Now, install KRename with the following command:

$ sudo apt install krename

Now, press y and then press <Enter> to confirm the installation.

KRename should be installed.

Installing KRename from Software Center:

You can also install KRename from the Software Center of KDE 5 Plasma Desktop.

First, open Software Center from KDE Application Launcher > Applications > System > Discover as marked in the screenshot below.

Now, search for KRename. Once you find it, click on Install as marked in the screenshot below.

KRename should be installed.

Starting KRename:

Once KRename is installed, you can start KRename from KDE Application Launcher > Applications > Utilities > KRename as marked in the screenshot below.

KRename should start. In the next section of this article, I will show you how to use KRename to bulk rename your files.

Using KRename:

The first thing you have to do is to add some files to KRename. You can click on the Add… button to add the files that you want to rename.

Now, select the files that you want to rename and click on Open.

All the files that you want to rename should be opened.

Now, go to the Destination tab. Normally you don’t have to do anything from here. The default option Rename input files is what you want. But, if you want to move or copy the files to another folder after the rename operation, or create symbolic links to the files in another folder, you can do it from here with one of the options as marked in the screenshot below.

To rename your files, you have to go to the Filename tab. On the bottom you have a handy preview window as you can see in the screenshot below. Here, on the left, you have the original file names and on the right, you have the renamed file names.

Here, you have a Prefix section. You can use it to add a prefix on your existing filename.

Here, you have a Prefix section. You can use it to add a prefix on your existing filename.

As you can see, the Number is inserted before the file.

If you want to add something after the number, you can put it in the empty text box right next to the prefix checkbox.

If you want more complex option, click on the icon as marked in the screenshot below.

As you can see, there are many categories and each category has a lot of options to choose from. Select what you want to put in your filename and click on Insert.

As you can see, I’ve added [filesize] option and the file names are updated in the preview section.

The same way, you can choose a Suffix (to add after the filename, before the extension). The options are the same as the Prefix. So, I am not showing you this again here.

You can also change the filename to Uppercase, lowercase or Capitalize it from the Filename section. You will more likely want to set a custom name depending on your need. To do that, click on Custom name.

Now, you can either set a custom name, or select from many predefined options as you saw earlier.

I added the current date after the filename using one of the predefined template. Here, $ is replaced by the original filename.

The same way, you can convert the extension to lower case, upper case or capitalize it from the Extension section. You can also set custom extension the same way as before.

If you want, you can also search for strings and replace them. You can also use regular expression to match and replace strings in your filename. To do that, click on the Find and Replace… button as marked in the screenshot below.

Now, click on Add… to add a new find and replace pattern.

Now, type in what you want to find in the Find section, then what you want to replace with in the Replace With section. If you want to match regular expressions, then put the regular expression in the Find section and check Find is a Regular Expression. Once you’re done, click on OK.

Now, click on OK for it to take effect. If the find and replace pattern is something that you use very frequently, then you can also save it and load it latter. To save the pattern, click on Save Settings… and save it somewhere safe. If you need it later, you can click on Load Settings… and load the pattern.

As you can see, timezone is replaced with TZ.

Once you’re done, click on Finish for the rename operation to take place.

Once the rename process is finished. Click on Close.

As you can see, the files are renamed.

So, that’s how you install and use KRename on KDE Plasma Desktop Environment. Thanks for reading this article.

]]>
How to Delete Directory in Linux https://linuxhint.com/delete_directory_linux/ Mon, 13 May 2019 07:18:23 +0000 https://linuxhint.com/?p=39938 You can delete directories from the command line in Linux very easily. If you have any graphical desktop environment installed on your computer, you can also delete directories using the graphical user interface.  In this article, I am going to show you both ways of deleting directories in Linux. So, let’s get started.

Deleting Directories from the Command Line:

If a directory you’re trying to remove is empty (does not have any files or directories inside), then you can use the rmdir command to remove the directory from the command line.

For example, let’s say, you have an empty directory test/ which you want to remove.

To remove the empty directory test/, run the following command:

$ rmdir test

As you can see, the directory test/ is removed.

If the directory you’re trying to remove has contents, you can’t remove it with the rmdir command. You have to use the rm command instead.

Let’s say, you want to remove a directory configs/ which has files and other directories inside.

$ tree configs/

Now, to remove the directory configs/ run the rm command as follows:

$ rm -rv configs/
Or
$ rm -rfv configs/

The directory and all the contents (files and directory) of the directory should be removed as you can see in the screenshot below.

If you want, you can remove multiple directories (and its contents) with the rm command as follows:

$ rm -rv directory1 directory2 /path/to/directory3
Or
$ rm -rfv directory1 directory2 /path/to/directory3

NOTE: The -f option removes the directory and contents without any safety check. So, be sure that you don’t have anything important in the directory that you’re trying to remove. For more information on that, read the next section of this article.

Safety Check Before Removing Directories from the Command Line:

A directory contains a lot of files and other directories. You may not know whether you have any important files in there all the time before you actually removed it (oh no!). So, it’s always a good idea to use programs such as tree to verify that you don’t have anything important in the directory that you want to remove.

The tree program is very simple to use. The format of the tree command is:

$ tree path_to_the_directory

The tree command is not available in most of the Linux distribution by default. But you can easily install it from the official package repository of your desired Linux distribution.

CentOS 7 and RHEL 7:

You can install tree package from the official package repository of CentOS 7 or RHEL 7 using the YUM package manager as follows:

$ sudo yum install -y tree

Ubuntu/Debian:

On Ubuntu, Debian or any derivatives of Debian, you can install tree package from the official package repository using the APT package manager as follows:

$ sudo apt install -y tree

The rm command also has a safety check option. You can use the -i option to tell rm to prompt for confirmation before it removes any file or directory.

To safely remove a directory images/ using rm, run the following command:

$ rm -ri images/

Before rm descend (go into) any directory, it will prompt for confirmation. To confirm, press y and then press <Enter>.

rm will also prompt for configuration before it removes any file. To confirm, press y and then press <Enter>.

It will only remove the directory if you confirm removal of everything. Otherwise, it will leave all the files that you don’t want to remove along with the directories. Now, you have a way to move the important files and remove the directory afterward. It’s better than regretting later.

The -i option will be enabled by default in some Linux distribution. To override it and force rm to remove everything without prompting first, use the -f option.

Removing Directories using Graphical User Interface:

If you’re using graphical desktop environment, then you can use the File Manager (i.e Nautilus, Dolphin etc) included in the desktop environment to remove directories.

To remove a directory or directories, select the directory or directories that you want to remove and then press <Shift> + <Delete>. Your file manager should prompt you to confirm the delete operation. To confirm, click on Delete as marked in the screenshot bleow. The directory or directories that you’ve selected should be removed.

So, that’s how you delete a directory or directories in Linux. Thanks for reading this article.

]]>
Rename Files and Directories in Linux https://linuxhint.com/rename_file_directory_linux/ Wed, 08 May 2019 18:02:07 +0000 https://linuxhint.com/?p=39834 In Linux, you can rename files and directories from the command line.  You can also rename files and directories using the graphical user interface or keyboard shortcuts if you’re using a graphical desktop environment.

In this article, I will show you some of the ways to rename files and directories in Linux. So, let’s get started.

Renaming Files from the Command Line:

You can rename files from the command line in Linux using the mv command. mv stands for move. In Linux, renaming is also known as moving a file.

The format of the mv command is:

$ mv file_to_rename new_filename

For example, let’s say, I have a file test.txt which I want to rename to test2.txt.

To rename the test.txt file to test2.txt, run the mv command as follows:

$ mv test.txt test2.txt

As you can see, the file test.txt is renamed to test2.txt.

Renaming Directories from the Command Line:

The same way, you can rename a directory as well.

For example, let’s say, you have a directory programming/ and now you want to rename it to codes/.

To rename the directory programming/ to codes/, run the mv command as follows:

$ mv -v programming codes

NOTE: Here, the -v option is used to show the status of the command.

As you can see, the command ran successfully and the directory programming is renamed.

We can further verify that the directory programming/ is renamed to codes/ using the ls command as you can see in the screenshot below.

$ ls

Renaming Files and Directories using Nautilus File Manager:

You can also rename files and directories graphically using the Nautilus file manager if you’re using GNOME 3 desktop environment.

To rename a file or directory, just right click (mouse click) on the file or directory and click on Rename… as marked in the screenshot below.

Now, type in a new name and click on Rename or press <Enter>.

The selected file or directory should be renamed as you can see in the screenshot below.

You can also click on a file or directory to select it and press F2 on your keyboard to rename the file or directory.

Select a file or directory and press F2.

The same way, type in a new name and click on Rename or press <Enter>.

Your desired file or directory should be renamed.

Renaming Multiples Files and Directories with Nautilus File Manager:

You can also rename multiple files together with nautilus file manager.

To do that, select the directories and files that you want to rename.

Then, press F2 on your keyboard. You should see the following window. On the left side, the original file and directory names of the selected files and directories are displayed. On the right side, the file and directory names that will be after the rename operation is displayed. Right now, both of these are the same.

Now, if you want to add something before the original file or directory name, then add it before the [Original file name] as marked in the screenshot below. As you can see, file and directory name after the rename operation is previewed on the right side of the window.

You can also add something to the end of the file or directory name. To do that, type in what you want to add after the [Original file name] as marked in the screenshot below. The same way, a preview of what the file and directory names will be is displayed on the right side of the window.

If you want, you can also add numbers to the [Original file name]. To do that, click before or after the [Original file name] depending on where you want to add numbers and click on + Add. Now, select the number format that you want to add from the list.

As you can see, the file and directory names are updated on the preview (right side of the window).

If you want, you can also find and replace portion of the names of files and directories. To do that, click on Find and replace text radio button.

Now, type in what you want to find within the existing name in the Existing Text section and what you want to replace it with in the Replace With section.

As you can see, the matched section is highlighted and the replaced name is displayed in the preview section.

Once you’re happy with the results, click on Rename.

The files and directories should be renamed as you wanted.

Renaming Files and Directories with Dolphin File Manager:

You can do simple rename operations with Dolphin file manager.

To rename a file or directory, right click (mouse) on it and click on Rename… as marked in the screenshot below. You can also select the file or directory and press F2 on your keyboard to do the same thing.

Now, type in a new file or directory name and press <Enter>.

The file or directory should be renamed.

So, that’s basically how you rename files and directories in Linux. Thanks for reading this article.

]]>
Linux File System Hierarchy https://linuxhint.com/linux-file-system-hierarchy/ Wed, 04 Oct 2017 10:14:15 +0000 https://linuxhint-com.zk153f8d-liquidwebsites.com/?p=19605

Maybe you have just installed Linux, and now you want to know about the hierarchy and structure of the Linux File system. You may also wonder why different types of software are installed in its different directories.

To know the Linux Filesystem’s structure, let’s begin with the entry or starting point of the directories, which is known as the root directory. In this post, we will use the tree command to view the hierarchical structure of directories in the form of the tree in the terminal.

Let’s install a tool named “tree” to view the structure of directories and better understand the hierarchy.

To install the “tree” on Ubuntu or Debian based systems, use the command below:

$ sudo apt install tree

To install the “tree” on Fedora or RedHat, use the appended command:

$ sudo dnf install tree

Once “tree” is installed, first, change the directory to the root directory(/), using the “cd” command:

$ cd /

Then run the tree command here:

$ tree

It has shown all the directories and subdirectories, which was actually not needed since we only wanted to see the directories of the current folder.

So, let’s modify the tree command a little bit according to our needs, and try this command instead:

$ tree -L 1

In this command, the “-L” is representing the level we want to see, and the “1” is representing the level number.

Now, we have a better view of the directories of our interest in the root directory.

Next, let’s learn about each directory.

Directories:

Let’s begin the root directory “/”:

/

This is the entry point of all directories and is described as a forward slash, which is actually the home of the Operating System. Everything is in it. Not every user has read and write privileges to this directory; only the administrators or allowed users of the operating systems can have access to such privileges.

/bin

This is the directory that has all the binary files of some important programs on the operating system. This directory holds the data about the most used commands related to making(mkdir), moving(mv), copying(cp), listing(ls), and removing(rm) a directory or file. According to the Linux Filesystem Standards, this directory cannot have subdirectories.

/boot

This is the directory that handles the ignition of the Linux Operating System. First of all, you don’t need to modify anything in this directory, otherwise, you can’t alter anything in it unless you have administrator’s rights. You should stay away from doing anything in this directory, or else it will be a huge mess to set it up again.

/dev

This directory holds the files of the devices like a USB Device or a Hard Drive. Most of the files are either created on the boot time or when a device is attached.

/etc

This may seem a little bit funny to you, but this directory is for those types of configuration files and folders in which the system does not know where to put them. So, it is an “et Cetra” directory for the Linux Operating system.

This directory mostly contains the static program local files that affect all users. Since this directory mostly contains files related to the configuration, it is better to call it “Everything to Configure”.

/home

This is the directory where most of the user’s personal data is placed. A user spends most of his time here because Downloads, Documents, Desktop, and all other basic required and much-known directories are in this “/home” directory. All the dot configuration files of a user are also in here.

/lib

These are the folders where libraries are stored. Libraries are some files that are needed by any application to perform several tasks or functions. For example, these libraries may be needed by the binary files in the /bin directory.

/media

This is the directory where all the external connected storage devices are mounted automatically. We do not need to do anything in this directory because it is managed by the Operating System itself, but if we want to mount storage devices manually, we have the /mnt directory for that purpose.

/mnt

This is the directory where you can find the other mounted drives. For example, a USB drive, an External Hard Drive, or a Floppy Disk Drive. This is not used nowadays because the devices are automatically mounted to the /media directory, but this is where we can mount our storage devices manually.

/opt

This is the optional folder. It is the directory where manually installed software by vendors is placed.

/proc

This is the directory with the pseudo files. The pseudo files contain information about the processes.

/root

Just like /home directory, /root is the house of the Administrator a.k.a. superuser. Since this is the superuser’s directory, it is better not to touch it unless you have complete knowledge of what you are doing.

/run

This directory is used to store temporary data of processes running on the Operating System.

/sbin

This directory is just like the /bin directory, but this is used by the superuser, and that’s why “s” is used before bin.

/snap

The is the directory with the snap packages stored in it.

/srv

This directory stores the data of the services running on the system. For example, it holds the data if a server is running on the Operating System.

/sys

This directory is always created during boot time, so it is a virtual directory like /dev, and it is the directory when you want to communicate to the Kernal. It also holds information related to the connected devices.

/tmp

This is a temporary directory and holds the temporary files of the applications running on the system.

/usr

This directory contains the applications installed and used by the user. It is also known as the “UNIX System Resources”. It also has its own /bin, /sbin, and /lib directory, which is different from the superuser’s /bin, /sbin, and /lib directories.

/var

This is a variable directory that contains the files and folders whose size is expected to increase with the passage of time and the system’s usage.

Summary:

If you have been confused about the Linux directories and their purposes, then this post must have been a great help to you. It contains a profound and on point explanation of the topic, including the purpose of every single directory that exists in any kind of Linux based Operating System.

]]>
Find Files on Linux https://linuxhint.com/find-files-on-linux/ Sat, 23 Sep 2017 01:59:35 +0000 https://linuxhint-com.zk153f8d-liquidwebsites.com/?p=19552 Introduction

Linux is an operating system family which makes use of the Linux kernel. The operating systems under the Linux banner are generally known as distributions, and are often for free of charge. Here in this article it explains how to find files with ease, and how to expand its capability to get more precise details. As the operating system it uses Ubuntu 17.04, but this is the same in pretty much any other Linux operating system depending on its version.

Basic Search

The basic search involves typing the name of the file in “File” manager which by default searches files in the Home directory only, but by navigating to “Other Locations”, it can be commanded to search files in both “Network” and “On this Computer” locations. “On this computer” lists out locally available hard drives to the operating system, whereas “Networks” lists out discovered network locations.

  1. Click on “File” manager.
  2. Navigate to “Other Locations”
  3. Click on either “Computer” or any network location listed in the file manager.
  4. Use the search bar on the “File” manager to start searching the files as in following screenshot.

“Find” Command (Terminal Command)

Find command is a part of findutils directory searching utility, and which searches files by traversing in a folder hierarchy. The process is relatively faster then “File” manager search, and is capable of finding files in real time. Find command uses many parameters to change the behavior of the search, and therefore it’s a powerful tool to get into action.

Basic Syntax

The basic search of “Find” goes as following. It consists of the name parameter which specifies name of the file to be searched, and the location which specifies to where the file to be searched.  “~” symbol indicates the search is made in the “home” directory. Since it’s a basic search the quotation marks are not used, but generally it’s recommended to used them to avoid unexpected results.

             find ‘path’ -name ‘file name’

             find ~ -name readme.txt

             find ~ -name ‘readme.txt’

Search in Current Directory

This is same as the aforesaid one. The only difference here is having “.” Which indicates the current search to be made in “current directory” (denoted by “.”).

             find . -name readme.txt

             find . -name ‘readme.txt’

Search as Administrator

Sometimes when searching in certain protected directories or from root  (“/”) directory the terminal might complain it doesn’t have enough permission to access denoted by “Permission denied” message. In such cases using sudo along with the password of the current user helps to solve the problem. As seen in the following screenshot cd /<directoryname> helps to specify the current directory to use with find.

             cd /etc (to change the current directory)

             sudo find . –name ‘file name’

             sudo find . -name ‘README’

             sudo find . -name README

Search case insensitive words

In an operating system it’s normal for having both uppercase and lowercase file names, but find is unable to detect them by default, and therefore this new parameter –iname which ignores the case of the file’s name has to be used instead of the default –name parameter.

             find /etc –iname ‘readme’

Search by extensions

Extension specifies the type of the file as in whether it’s a text file or system file or any other file. Here the “*” symbol is used to denote one or more characters are considered when making the search. In the following example it uses “*.txt”, and thus any text file is included in the result.

             find /etc -iname ‘*.txt”

Search by size

A file always has a size which indicates how much contents it bears within. Find supports search by file size with –size parameter which supports megabyte denoted by M, kilobytes denoted by k, gigabyte denoted by G sizes. Since size also needs either greater than or lesser than option, it also has to be stated with either + or – respectively.

             find / -iname ‘file name’ –size <Number>k/M/G

Greater than

When greater than is used, files larger than the stated size are filtered. In the following examples files larger than 1 kilobyte are filtered.

             find /etc -iname ‘readme’ –size +1k

Less than

When less than is used, files lesser than the stated size are filtered. In the following examples files lesser than 1 kilobyte are filtered.

             find / -iname ‘readme’ –size -1k

Search File by Date

Search file by date as the name itself implies for searching files based on the time and date. Find supports three parameters access time, change time, and modified time.

Access time

Access time changes when a file is read or processed by any process directly or through a script. In the following example it returns any file with name linux which was not accessed for 1 days.

             find / -name ‘linux* –atime +1

Change time

When the file had its contents updated or when its permission was changed the change time is changed accordingly, and thus using the ctime which denotes change time returns any file which was changed within the given time period. In the following example it returns any file with name ‘readme’ changed for 22 days or more.

             find / -name ‘readme’ –ctime +22

Modify time

Modify time and change time both are almost same, except modify time doesn’t include changes in the file permission. The following example as earlier returns any file with the name readme which was changed for 22 days or more.

             find / -name ‘readme’ –mtime +22

And or OR

And, OR operators join two or more parameters together; hence they are useful for searching multiple files at the same time. In the following example it searches for both ‘linux’ OR ‘readme’ files.

             find / -iname ‘linux’ –or –iname ‘readme’

In the following example it searches for files with the name readme with the size greater than 5 kilobytes

             find / -iname ‘readme’ –and –size +5k

Not indicates the opposite of what had been mentioned. In the following example it indicates not to filter files with names ‘linux’ and ‘log*’ but return any other files with type txt which denotes text files.

             find / -name ‘*.txt’ –not –iname ‘log*’ –not –iname ‘linux’

Prefix

Prefix is useful when a part of a file name is known and it starts with the given keyword, for instance, if there are a large amount of files which start with ‘linux’ in their file names, that particular files can be filtered by using the ‘*linux’

             find / -name ‘*linux’

Suffix

Suffix is useful when a part of a file name is known and it ends with the given keyword, for instance if there are a large amount of files which end with ‘linux’ in their file names, that particular files can be filtered by using the ‘linux*’

As you can see the find command is what you really want to use when you get sophisticated, but you can get started with the Graphical User Interface if you are a Linux newbie.

 

]]>
Install FreeFileSync 11.5 on Ubuntu 20.04– A Free File Sync Software https://linuxhint.com/install-free-file-sync-software-ubuntu/ Fri, 21 Jul 2017 21:34:38 +0000 http://sysads.co.uk/?p=15968

FreeFileSync is a useful multi-platform application that helps us to synchronize our files and folder across various devices. It creates the backup of our data on the local system or any external device.

The FreeFileSync is not available from the Ubuntu 20.04 standard repository. However, its source tarball is available from the official webpage. As of preparing this guide, the latest FreeFileSync version is 11.5.

Installing FreeFileSync on Ubuntu 20.04

Complete the below-given steps to install FreeFileSync on Ubuntu 20.04:

Step 1: Download FreeFileSync tarball

Visit the FreeFileSync official website (https://freefilesync.org/).

Click on ‘Download’ and select FreeFileSync for Linux.

The FreeFileSync tarball will be downloaded in the ‘Downloads’ directory.

Step 2: Extract tarball

After successfully downloading the FreeFileSync tarball, navigate to the ‘Downloads’ directory, and extract the tarball with tar the command:

$ cd Downloads
$ sudo tar -zxvf FreeFileSync_11.5_Linux.tar.gz

Step 3: Move FreeFileSync to /opt

Next, move the FreeFileSync directory to /opt. The /opt directory is used to store external and third-party applications.

$ sudo mv FreeFileSync /opt

Step 4: Create FreeFileSync application shortcut

The FreeFileSync tarball does not include any executable file. Therefore, we need to create an executable application shortcut.

Execute the below-given command to create the FreeFileSync desktop entry:

$ gedit ~/.local/share/applications/FreeFileSync.desktop

After executing the above-given command, a text file will be opened.

Write the below-given lines to create a FreeFileSync Desktop entry.

Next, save and close the file.

Launch and use the FreeFileSync application

Once the application shortcut is created, open the Application Menu and search for FreeFileSync.

Click on the FreeFileSync application icon to open the application.

Click on the ‘+’ button to add files in FreeFileSync.

Now click on ‘Browse’ to add the files and folders.

The files are folder will be added successfully.

Click on ‘Synchronization’ to start syncing your files and folders.

Conclusion

FreeFileSync is a free and open-source file syncing application. It works on multiple platforms, including Linux, and creates files and folder backups. This guide explains FreeFileSync installation on Ubuntu 20.04.

]]>