Find command find directories that were created after a certain date under Linux/Cygwin
You could use stat instead:
find . -type d -exec bash -c '(( $(stat -c %W "{}") > $(date +%s -d '2013-12-03') )) && du -h "{}"' \;
Find files in created between a date range
You can use the below to find what you need.
Find files older than a specific date/time:
find ~/ -mtime $(echo $(date +%s) - $(date +%s -d"Dec 31, 2009 23:59:59") | bc -l | awk '{print $1 / 86400}' | bc -l)
Or you can find files between two dates. First date more recent, last date, older. You can go down to the second, and you don't have to use mtime. You can use whatever you need.
find . -mtime $(date +%s -d"Aug 10, 2013 23:59:59") -mtime $(date +%s -d"Aug 1, 2013 23:59:59")
Can we store the creation date of a folder (not file) using bash script?
You could do with a -type d
option to include only the directories from the current folder, and as discussed in the comments section if you need the output from the stat
in just yyyy-mm-dd
format, use awk
as below.
find "$DIRECTORY"/ -type d -exec stat \{} --printf="%w\n" \; | sort -n -r | head -n 1 | awk '{print $1}'
To store the value in a bash
variable:-
$ myvar=$(find "$DIRECTORY"/ -type d -exec stat \{} --printf="%w\n" \; | sort -n -r | head -n 1 | awk '{print $1}')
$ echo $myvar
2016-05-20
Recursively find all files newer than a given time
This is a bit circuitous because touch
doesn't take a raw time_t
value, but it should do the job pretty safely in a script. (The -r
option to date
is present in MacOS X; I've not double-checked GNU.) The 'time' variable could be avoided by writing the command substitution directly in the touch
command line.
time=$(date -r 1312603983 '+%Y%m%d%H%M.%S')
marker=/tmp/marker.$$
trap "rm -f $marker; exit 1" 0 1 2 3 13 15
touch -t $time $marker
find . -type f -newer $marker
rm -f $marker
trap 0
How can I recursively find all files in current and subfolders based on wildcard matching?
Use find
:
find . -name "foo*"
find
needs a starting point, so the .
(dot) points to the current directory.
How to find all files containing specific text (string) on Linux?
Do the following:
grep -rnw '/path/to/somewhere/' -e 'pattern'
-r
or-R
is recursive,-n
is line number, and-w
stands for match the whole word.-l
(lower-case L) can be added to just give the file name of matching files.-e
is the pattern used during the search
Along with these, --exclude
, --include
, --exclude-dir
flags could be used for efficient searching:
- This will only search through those files which have .c or .h extensions:
grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"
- This will exclude searching all the files ending with .o extension:
grep --exclude=\*.o -rnw '/path/to/somewhere/' -e "pattern"
- For directories it's possible to exclude one or more directories using the
--exclude-dir
parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:
grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"
This works very well for me, to achieve almost the same purpose like yours.
For more options, see man grep
.
cygwin can't find my files
From cygwin, you can get to the C: disk as
cd /cygdrive/c/
Check here: for permanent solution.
As mentioned there: create a directory for each
of your disks and mount them:
> cd /
> mkdir c
> mount c: /c
> mkdir d
> mount d: /d
> ...etc
Now you can directly go to the c: drive, for example:
> cd /c
Related Topics
A Way to Prevent Bash from Parsing Command Line W/Out Using Escape Symbols
Cmsg_Nxthdr() Returns Null Even Though There Are More Cmsghdr Objects
Delete Files with Backslash in Linux
How to Print the Nth (5Th) Line of Every File Preceded by the Filename Using Any Linux Tool
Delete Last Line Break Using Sed
Read Data from Proc/Sys/Kernel/
How Create a Bash Script with Another Bash Script
How to Know the Current Quarter with Date
How to Mail Script Output in Table Format
Limit Output of All Linux Commands
How to Solve "Bash: Ls: Command Not Found"
Docker Overlay2: Error Walking File System: Oserror [Errno 40] Too Many Levels of Symbolic Links
Converting a Visual Studio Makefile to a Linux Makefile
Will Process Lost Wake-Up Chance in a Preemptive Kernel
How to Use the Parallel Command to Exploit Multi-Core Parallelism on My MACbook