DEV Community

BC
BC

Posted on

Use `file` to get file types - Linux Tips

You might heard "Everything is a file" in Linux. Using the file shell command, you can get a file's type:

First let's create some files:

# create plain text file
$ echo "" > abc.txt

# create a folder
$ mkdir Music

# create a symbolic link
$ ln -s /media/pi/WDHD ./Cloud

# create a FIFO
$ mkfifo /tmp/myfifo

# list tty devices under /dev
$ ls /dev/tty*
/dev/tty
/dev/tty0
...
/dev/tty13
...
Enter fullscreen mode Exit fullscreen mode

Now we use file command to get those file types:

$ file abc.txt
abc.txt: ASCII text

$ file Music
Music: directory

$ file Cloud
Cloud: symbolic link to /media/pi/WDHD

$ file /tmp/myfifo
/tmp/myfifo: fifo (named pipe)

$ file /dev/tty13
/dev/tty13: character special
Enter fullscreen mode Exit fullscreen mode

Top comments (0)