DEV Community ๐Ÿ‘ฉโ€๐Ÿ’ป๐Ÿ‘จโ€๐Ÿ’ป

Bo
Bo

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)

Create an Account!
Now it's your turn!
ย 
๐Ÿ—’ Share a tutorial
๐Ÿค” Reflect on your coding journey
โ“ Ask a question

Create an account to join hundreds of thousands of DEV members on their journey.