How to find file system in linux

Classic SysAdmin: How to Search for Files from the Linux Command Line

This is a classic article written by Jack Wallen from the Linux.com archives. For more great SysAdmin tips and techniques check out our free intro to Linux course.

It goes without saying that every good Linux desktop environment offers the ability to search your file system for files and folders. If your default desktop doesn’t — because this is Linux — you can always install an app to make searching your directory hierarchy a breeze.

But what about the command line? If you happen to frequently work in the command line or you administer GUI-less Linux servers, where do you turn when you need to locate a file? Fortunately, Linux has exactly what you need to locate the files in question, built right into the system.

The command in question is find. To make the understanding of this command even more enticing, once you know it, you can start working it into your Bash scripts. That’s not only convenience, that’s power.

Let’s get up to speed with the find command so you can take control of locating files on your Linux servers and desktops, without the need of a GUI.

How to use the find command

When I first glimpsed Linux, back in 1997, I didn’t quite understand how the find command worked; therefore, it never seemed to function as I expected. It seemed simple; issue the command find FILENAME (where FILENAME is the name of the file) and the command was supposed to locate the file and report back. Little did I know there was more to the command than that. Much more.

If you issue the command man find, you’ll see the syntax of the find command is:

find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point. ] [expression]

Naturally, if you’re unfamiliar with how man works, you might be confused about or overwhelmed by that syntax. For ease of understanding, let’s simplify that. The most basic syntax of a basic find command would look like this:

find /path option filename

Find by name

Let’s break down that basic command to make it as clear as possible. The most simplistic structure of the find command should include a path for the file, an option, and the filename itself. You may be thinking, “If I know the path to the file, I’d already know where to find it!”. Well, the path for the file could be the root of your drive; so / would be a legitimate path. Entering that as your path would take find longer to process — because it has to start from scratch — but if you have no idea where the file is, you can start from there. In the name of efficiency, it is always best to have at least an idea where to start searching.

Читайте также:  При установке linux busybox

The next bit of the command is the option. As with most Linux commands, you have a number of available options. However, we are starting from the beginning, so let’s make it easy. Because we are attempting to find a file by name, we’ll use one of two options:

Remember, Linux is very particular about case, so if you’re looking for a file named Linux.odt, the following command will return no results.

If, however, you were to alter the command by using the -iname option, the find command would locate your file, regardless of case. So the new command looks like:

Find by type

What if you’re not so concerned with locating a file by name but would rather locate all files of a certain type? Some of the more common file descriptors are:

  • f – regular file
  • d – directory
  • l – symbolic link
  • c – character devices
  • b – block devices

Now, suppose you want to locate all block devices (a file that refers to a device) on your system. With the help of the -type option, we can do that like so:

The above command would result in quite a lot of output (much of it indicating permission denied), but would include output similar to:

/dev/hidraw6 /dev/hidraw5 /dev/vboxnetctl /dev/vboxdrvu /dev/vboxdrv /dev/dmmidi2 /dev/midi2 /dev/kvm

We can use the same option to help us look for configuration files. Say, for instance, you want to locate all regular files that end in the .conf extension. This command would look something like:

The above command would traverse the entire directory structure to locate all regular files ending in .conf. If you know most of your configuration files are housed in /etc, you could specify that like so:

find /etc -type f -name “*.conf”

The above command would list all of your .conf files from /etc (Figure 1).

Outputting results to a file

One really handy trick is to output the results of the search into a file. When you know the output might be extensive, or if you want to comb through the results later, this can be incredibly helpful. For this, we’ll use the same example as above and pipe the results into a file called conf_search. This new command would look like: ​

find /etc -type f -name “*.conf” > conf_search

You will now have a file (conf_search) that contains all of the results from the find command issued.

Читайте также:  Linux on google servers

Finding files by size

Now we get to a moment where the find command becomes incredibly helpful. I’ve had instances where desktops or servers have found their drives mysteriously filled. To quickly make space (or help locate the problem), you can use the find command to locate files of a certain size. Say, for instance, you want to go large and locate files that are over 1000MB. The find command can be issued, with the help of the -size option, like so:

You might be surprised at how many files turn up. With the output from the command, you can comb through the directory structure and free up space or troubleshoot to find out what is mysteriously filling up your drive.

You can search with the following size descriptions:

  • c – bytes
  • k – Kilobytes
  • M – Megabytes
  • G – Gigabytes
  • b – 512-byte blocks

Keep learning

We’ve only scratched the surface of the find command, but you now have a fundamental understanding of how to locate files on your Linux systems. Make sure to issue the command man find to get a deeper, more complete, knowledge of how to make this powerful tool work for you.

Источник

7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)

A file system is the way in which files are named, stored, retrieved as well as updated on a storage disk or partition; the way files are organized on the disk.

A file system is divided in two segments called: User Data and Metadata (file name, time it was created, modified time, it’s size and location in the directory hierarchy etc).

In this guide, we will explain seven ways to identify your Linux file system type such as Ext2, Ext3, Ext4, BtrFS, GlusterFS plus many more.

1. Using df Command

df command reports file system disk space usage, to include the file system type on a particular disk partition, use the -T flag as below:

$ df -Th OR $ df -Th | grep "^/dev"

df Command - Find Filesystem Type

For a comprehensive guide for df command usage go through our articles:

2. Using fsck Command

fsck is used to check and optionally repair Linux file systems, it can also print the file system type on specified disk partitions.

The flag -N disables checking of file system for errors, it just shows what would be done (but all we need is the file system type):

$ fsck -N /dev/sda3 $ fsck -N /dev/sdb1

fsck - Print Linux Filesystem Type

3. Using lsblk Command

lsblk displays block devices, when used with the -f option, it prints file system type on partitions as well:

Читайте также:  Linux mint on imac

lsblk - Shows Linux Filesystem Type

4. Using mount Command

mount command is used to mount a file system in Linux, it can also be used to mount an ISO image, mount remote Linux filesystem and so much more.

When run without any arguments, it prints info about disk partitions including the file system type as below:

Mount - Show Filesystem Type in Linux

5. Using blkid Command

blkid command is used to find or print block device properties, simply specify the disk partition as an argument like so:

blkid - Find Filesystem Type

6. Using file Command

file command identifies file type, the -s flag enables reading of block or character files and -L enables following of symlinks:

file - Identifies Filesystem Type

7. Using fstab File

The /etc/fstab is a static file system info (such as mount point, file system type, mount options etc) file:

Fstab - Shows Linux Filesystem Type

That’s it! In this guide, we explained seven ways to identify your Linux file system type. Do you know of any method not mentioned here? Share it with us in the comments.

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Parted Command in Linux

TLDR Man Pages for Linux Commands

apt-get Command Examples

Ubuntu apt-cache Commands

apt Command Examples

Funny Linux Commands

15 thoughts on “7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)”

will create a ext2 filesystem on image1, if its not big enough (warning “Filesystem too small for a journal” means a filesystem without a journal, a.k.a. ext2, is created) If you don’t realize this and nevertheless mount it as ext4. The df and mount methods above will mirror back ext4:

$ df -Th /tmp/mnt* Filesystem Type Size Used Avail Use% Mounted on /dev/loop4 ext4 1003K 24K 908K 3% /tmp/mnt1 /dev/loop5 ext4 987K 33K 812K 4% /tmp/mnt2 $ mount | grep mnt . /home/mallikab/image1 on /tmp/mnt1 type ext4 (rw,relatime,seclabel) /home/mallikab/image2 on /tmp/mnt2 type ext4 (rw,relatime,seclabel,data=ordered)
$ fsck -N /tmp/mnt1 fsck from util-linux 2.23.2 [/sbin/fsck.ext2 (1) -- /tmp/mnt1] fsck.ext2 /tmp/mnt1 $ fsck -N /tmp/mnt2 fsck from util-linux 2.23.2 [/sbin/fsck.ext4 (1) -- /tmp/mnt2] fsck.ext4 /home/mallikab/image2 $ file -sL /home/mallikab/image2 /home/mallikab/image2: Linux rev 1.0 ext4 filesystem data, UUID=b4e8e086-54ca-4d9d-9f38-32bbed211e6b (needs journal recovery) (extents) (64bit) (huge files) $ file -sL /home/mallikab/image1 /home/mallikab/image1: Linux rev 1.0 ext2 filesystem data (mounted or unclean), UUID=09b3a8c9-0b6d-43c5-b195-c45f6c091765 (extents) (64bit) (huge files) hm, although fsck doesn't indicate ext2 unless the images are mounted, i.e. $ fsck -N ~/image1 fsck from util-linux 2.23.2 [/sbin/fsck.ext4 (1) -- /home/mallikab/image1] fsck.ext4 /home/mallikab/image1

The only working method for me was ‘ lsblk -f ‘; the other replied “fuseblk“, “HPFS/NTFS/exFAT” or nothing. Reply

Источник

Оцените статью
Adblock
detector