Basic Linux commands for your server or servers.
Introduction
Many servers admins or hobbyists will usually at some point have an issue trying to find files on the Linux server.
This quick guide will learn you how to use the find command. This will help you search for files on your VPS or Dedicated Server using many options like filters and file types and even size. Also included is how to use the locate command which is obviously used to locate files/folders on a Linux Machine.
Finding Files/Folders using Name
Quite an easy way to find what you need using the command:
find -name whateverhere
To find any file by name, input:
find -name filenamehere
Finding or Searching by Type
You can specify the type of files you want to find with the -type parameter. It works like this:
- find -type type_descriptor query
Different ways to find file types using find / -type f for example:
f: regular file
d: directory
l: symbolic link
c: character devices
b: block devices
For example, if you want to find character devices, input this command:
find / -type c
You can search all files that end in .conf using tis command:
- find / -type f -name “*.conf”
Find files larger than whatever size you want for example using this command:
find / -size +50M
You can of course change to something like this command:
find / -size +5000M
Try mlocate you can install the command below with Debian/Ubuntu
apt install mlocate
On CentOS, use dnf instead:
dnf install mlocate
mlocate database auto-updates using a daily cron you can update before searching for something with the following command:
updatedb
Use the updateb command before you search using mlocate to ensure you are searching all files including new files.
To find files with locate, simply use this following example command:
locate whateveryouwanthere
Another example:
locate *.gz
If you want to see the history of data information locate has indexed use the following command:
locate -S