How display only files inside subdirs using the -haltr format? - linux

How do I add the output looks of ls -haltr into the command below?
find 20180913/ -maxdepth 5 -not -type d -and -not -name '.*'
Basically I am trying to list only files inside my subdirs but need to display the file time stamp sorted by date with latest at the bottom.
Thank you

You can try using the exec option of find:
find 20180913/ -maxdepth 5 -not -type d -and -not -name '.*' -exec ls -haltr {} +
Updated my answer based on PesaThe's correction.

Related

Find non empty directories with condition on their names in linux

There's a directory that has several subdirectories. These subdirectories' names are the date that the subdirectory was created. Now I want to list the subdirectories created in 'June' of 2021 and are not empty, so their names all contain this: 202106*.
How can I do this?
The command I use to list non-empty directories is this:
find . -mindepth 1 -maxdepth 1 -not -empty -type d
But I don't know how to set the name condition.
The name is specified by -name
find . -mindepth 1 -maxdepth 1 -not -empty -type d -name '202106*'
For more information read the find man page
suggesting
find . -type d -path "*202106*" -not -empty

How to exclude multiple subdirectories (same directory name) when using find command to delete files older than 30 days in a batch file?

Given the below linux directory structure, how would I skip each excluded directory, (/assess), to remove files older than 30 days for the rest of the entire directory structure?
Thanks for your assistance...
/mnt/nfsmountpoint/location1/appliance1
/assess
/discover
/bkup
/mnt/nfsmountpoint/location1/appliance2
/assess
/discover
/bkup
etc...
I cobbled together an answer and proofs:: (my asterisks * are not showing sorry)
Run from the /mnt/nfsmountpoint/ directory.
find .// -not -path "/assess/" -type f -mtime +30 -delete
validate::
Does it skip the directory?:
find .// -not -path "/assess/" -type f -mtime +30 -ls|more
Verify no current month (January 2021) files included?:
find .// -not -path "/assess/" -type f -mtime +30 -ls|grep Jan
How much space is made free?:
find .// -not -path "/assess/" -type f -mtime +30 -print0 | du --files0-from=- hc | tail -n1
find /path/to/dir -mtime +30 -type f -not -name "*assess*" -delete
Find files (-type f) in /path/to/dir as well as children directories. Specify only files that have been modified more than 30 days ago (-mtime +30) and do not include files that contain "assess" (-not -name "assess")

How to Find Recent or Today’s Modified Files in Linux

I have a requirement that will have to find out latest modified files list along with date and time.
mainly we have 2 files that boot.properties and ldap related files as part of beadmin password change activity.
find /target_directory -type f -name "*boot.properties" -exec ls -ltr {} \;
is giving only boot.properties but I need to find other files which is in different location.
find supports multiple path arguments, so you could do something like
find /target_dir /other -type f \( -name "*boot.properties" -o -name "other*" \) -exec ls -ltr {} +
try something like this if you have different location and file names.
find /root_directory \
\( \( \
-path "/target_directory1/*" -type f -name "*boot.properties" \) -o \( \
-path "/target_directory2/*" -type f -name "*boot2.properties" \
\) \) -exec ls -ltr {} \;
also, you have other options to find by modified date too.
check this article
https://www.cyberciti.biz/faq/linux-unix-osxfind-files-by-date/

Linux find -type f ignored

I'm creating a cron job, that will find all *.log* files (it will be used to remove them later, when it works).
The find command looks like this:
find /data/dg \( -path /data/dg/kf/data -o -path /data/dg/pg/data \) -prune -o -name "*.log*" -type f
And it should find all files with name ".log" that are not in directories /data/dg/kf/data and /data/dg/pg/data
However the output this command gives contains also the directories.
...
/data/dg/kf/log/controller.log.2019-09-08-22
/data/dg/kf/log/server.log.2019-09-09-07
/data/dg/kf/data
/data/dg/pg/log/postgresql-2019-09-27_000000.log
/data/dg/pg/log/postgresql-2019-09-27_100859.log
/data/dg/pg/log/postgresql-2019-09-27_102411.log
/data/dg/pg/data
/data/dg/sim/log/sim_2019-09-27-11.0.log
/data/dg/sim/log/sim_2019-09-27-12.0.log
...
It seems that -type f doesn't work. What's wrong?
put -type f right after /data/dg
find /data/dg -type f -not -path "/data/dg/kf/data*" -not -path "/data/dg/pg/data*" -name "*.log*"

Linux Shell Script execute without save to temporary variable

If I want to execute a command with variables in it, I always have to store the string first in a variable and then can execute it...
Example:
path_fasta="/home/xxx/yyy/zzz/qqq/"
name_fasta="CTA_Mix_DNA.fna"
path_outp"/some/Path/"
temp='find . -maxdepth 1 -not -name '$name_fasta' -not -name letsgo.sh -delete'
$temp
temp=$path_mothur'mothur #set.dir(output='$path_outp');summary.seqs(fasta='$path_fasta''$name_fasta')'
$temp
How do I do this directly without storing it first in temp? Must be easy, but did not find a solution...
Instead of:
temp='find . -maxdepth 1 -not -name '$name_fasta' -not -name letsgo.sh -delete'
$temp
...just use:
find . -maxdepth 1 -not -name "$name_fasta" -not -name letsgo.sh -delete

Resources