How to locate Files and Folders with SSH?

There will be a lot of times that you may need to search, find and locate a folder, file or a text line inside your hosting account. Linux offers a couple of very easy ways to search in your file system using SSH. In this article, we will show you the most common and easy ways to find what you are looking for the easy, fast and secure way.

What is SSH?

SSH is a network protocol that allows encrypted data transmission. It is developed to run commands on a remote machine (server) and to transfer files from one machine to another. It also allows easy management of the server you are connected to. SSH provides a high level of authentication and security during communication between servers over an insecure connection. There are multiple SSH commands that are easy to use and can help you search for, find and locate files and folders on Linux hosting servers.

How to search for and locate files in LINUX using SSH commands

Let’s start by the most common SSH search for a file by its name:

find . -name MyCoolPhoto.jpg

Of course, if you are not sure about the file extension, you can locate files using SSH commands by their name only:

find . -name “MyCoolPhoto” 

If you are looking to find a certain directory, you can use the following command:

find / -type d -name MyDirectory   (where “/” is the starting point in our case the whole file system)

If you would like to filter for files that were modified in the four days:

find . mtime -4

Detailed explanation of how the above mentioned SSH commands work

find – this is a build-in Linux library that allows you to find files and folders through SSH
. (the dot or the first argument) – with this you specify your search start point in SSH commands. The dot in the specific example above represents the current directory of the user.
name – this argument specifies that you are making a SSH search for a file by its name
-type d – the argument type can take two values d (for directory) and f (for file)
mtime – with this argument you can easily locate files and folders in Linux that have been modified in the last X days. In the example above 4 is the number of days.

To search in SSH for a word or a sentence in a file you can use the grep command:

grep “username” wp-config.php

this command will output the username keyword in the wp-config.php file, but if you are not sure in which file this is located, you can use:

grep -r – H “username” *
This will look for the username in all files and give out the output in a recursive and human-readable format which the -r and -H options stands for.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Linux tar Command

The Linux tar command is used to compress and extract files to and from an archive. In this...

How to Install WordPress via SSH

Since WordPress is the most widely used CMS it’s installation process has been made as simple and...

SSH Execute Command on a Remote server

Via SSH you can connect to a remote server’s shell. This will allow you to execute commands on...

How to connect to your shared hosting account via SFTP with FileZilla

SFTP is a convenient way to use SSH, while also using the interface of a simple FTP. In order to...

SSH netstat command

If you wish to debug or track statistics of your network in a Linux environment you can use SSH...