Showing posts with label Bash. Show all posts
Showing posts with label Bash. Show all posts

Monday, September 7, 2026

Linux / Unix: Find and Remove Files with One Command

This is really very easy in Linux/Unix. This is the reason why Linux/Unix is so popular in most of the industries.  


COMMAND :-

find - search for files in a directory hierarchy
 

SYNOPSIS 

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

SYNTAX

find <dir-name> <criteria> <action>

dir-name - The directory which you want to search.
criteria - This is searching criteria, what you want to search.
action(if required) - This is command action you want to execute.

There are many options or expressions you can use to find your relevant files and folders.

Example :- The below command for finding all files with extension .xml

dev@jdg-developer-desktop ~ $ find soap_projects/  -name "*.xml"
 

soap_projects/folk-enabler-no-sec--soapui-project.xml
soap_projects/aim-localhost-tomcat-soapui-project.xml
soap_projects/roamenable-service-soapui-project.xml
soap_projects/search-enabler-soapui-project.xml

Find all the files , which file name contains "data" and extensions with .txt

dev@jdg-developer-desktop ~/workspace_test $ find .  -name "*data*.txt"  

./test_data_file.txt


Example for finding and delete all all files with "find" command.


find . -name "*data*.txt" -exec rm -rf {} \;


Example for finding and delete all .xml files.


find / -name "*.xml" -exec rm -f {} \;

Example for finding and delete all .xml files.

find /searchdirectory -name "*.xml" -exec rm -f {} \;



Delete command for all file with find command result :-

-exec rm -rf {} \;



Thursday, May 28, 2015

How to Convert Epoch Time to Human-Readable Format in Unix

How to convert epoch to human readable format in UNIX ?


In this example the epoch time is 1432783870. Use the below command to convert the epoch time to human readable time.Technically epoch time known as UNIX time , also known as POSIX time. 

Example :-

dev@javadevelopersguide-developer-desktop ~/Epoch/ $ date -d @1432783870
Thu May 28 13:31:10 EST 2015
dev@javadevelopersguide-developer-desktop ~/Epoch/ $ date -d @1377360000
Sun Aug 25 02:00:00 EST 2013

Find more here.