Susu Linux delete directory older than 1 day [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
Please help
I want to delete the directory and corresponding sub directories from a path and i tried the below command and for some reason it is not deleting .
Any help is appreciated .
/hana/export/PHO> ls -lrt
total 0
-rwxr-x--- 1 phoadm sapsys 678 Sep 4 10:59 export_schema.sh
drwxr-x--- 50 phoadm sapsys 4096 Sep 5 00:23 2018-09-05
drwxr-x--- 50 phoadm sapsys 4096 Sep 6 00:23 2018-09-06
-rwxr-x--- 1 phoadm sapsys 248 Sep 6 00:23 export_schema.out
phoadm#SS4100:/hana/export/PHO> find /hana/export/PHO/* -type d -ctime +1 -exec rm -rf {} \;
phoadm#SS4100:/hana/export/PHO> find /hana/export/PHO/* -type d -mtime +1 -exec rm -rf {} \;
phoadm#SS4100:/hana/export/PHO>
It should delete 2018-09-05 directory but for some reason the above command not working .
Thanks

I think it should be
find /hana/export/PHO -type d -ctime +1 -exec rm -rf {} \;
(without "*"), otherwise you are looking inside the directories not in PHO as you want, because "*" will be expanded by the shell.

or this:
find /hana/export/PHO/ -type d -mtime +1 -delete

Related

How to handle files with leading dashes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I am searching for files and directories using find, the files have leading dashes in the filenames:
ls -al
total 0
-rw-r--r-- 1 razhal staff 0 May 22 23:58 -x
drwxr-xr-x 3 razhal staff 96 May 22 23:58 .
drwxr-xr-x 12 razhal staff 384 May 22 17:06 ..
find * -maxdepth 1 -type file
The above gives the following error message:
find: illegal option -- m
I tried to terminate the options using --, but still having the same problem:
find * -maxdepth 1 -type file --
The strange thing is that if the folder contains a file without a leading dash I am getting no error message:
ls -al
total 0
-rw-r--r-- 1 razhal staff 0 May 22 23:58 -x
drwxr-xr-x 3 razhal staff 96 May 22 23:58 .
drwxr-xr-x 12 razhal staff 384 May 22 17:06 ..
-rw-r--r-- 1 razhal staff 0 May 23 00:03 x
find * -maxdepth 1 -type file
The above returns the x and no error message.
My question is how can I find and list both files/directories with and without leading dashes using find?
Notice that I really want to use find and not some other command such as xargs or similar.
Use . instead of *:
find . -maxdepth 1 -type file
. refers to the current folder you are in. You can also use .. instead of . to search from the parent directory.
Another option would be to put ./ in front of * like this:
find ./* -maxdepth 1 -type file
This way it won't interpret the files whose names start with a dash as options.

find -amin doesn't work if -name is excluded [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am running GNU Linux 6.2 on x86_64 hardware. I'm in a directory with 1237 files. I want to list the files created in the last 36 hours and since I cannot get -atime to work, I use "-amin 2160":
$ find . -amin -2160 -name 'Ar*' -exec ls -l {} \;
-rw-r--r-- 1 oracle dba 2318 Aug 30 04:04 ./Archivelog_backup_08302015040300.log
-rw-r--r-- 1 oracle dba 2317 Aug 30 10:03 ./Archivelog_backup_08302015100321.log
-rw-r--r-- 1 oracle dba 1920 Aug 30 16:21 ./Archivelog_backup_08302015160300.log
-rw-r--r-- 1 oracle dba 2318 Aug 30 22:04 ./Archivelog_backup_08302015220300.log
-rw-r--r-- 1 oracle dba 2318 Aug 31 04:03 ./Archivelog_backup_08312015040300.log
-rw-r--r-- 1 oracle dba 2318 Aug 31 10:04 ./Archivelog_backup_08312015100320.log
But since I don't care what the name is and I want to see ALL files touched in the last 2160 minutes, I type this command,
find . -amin -2160 -exec ls -l {} \;
but it lists all 1237 files in the directory PLUS THE 6 that meet the criterion. Why?
Humbly,
Because one of the matches is the directory entry.
The real lesson here is to not use ls in scripts. find has excellent, unambiguous replacements like the -printf predicate. See also http://mywiki.wooledge.org/ParsingLs
You probably also want to add -type f to avoid listing directories.
find . -type f -amin -2160 -printf '%s %f\n'
What you put in the format string obviously depends on which information exactly you actually want to extract for each matched file.
The first name output by
find .
is
.
which, when sent to ls will list all the files in the current directory. In your first example, . was excluded by -name "Ar*" You could get the same effect by telling find to only emit regular-files (not directories) with
find . -type f …

linux pipe argument list too long [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I use the following bash script to remove files older than $days.
find /home/xxx/conf_* -maxdepth 0 -mindepth 0 -type d -ctime +5 -exec rm -rf {} \;
However if the files are more than 32000+, I get
/usr/bin/find: Argument list too long
how do I trim the list down to like 20000 only?
From comment to answer:
Your problem is the glob expansion but you are already using a tool that can perfectly well handle an arbitrary number of found results, namely find. As such you should use a glob at all. Instead you should let find do all the work.
Something like:
find /home/xxx -maxdepth 1 -name 'conf_*' -type d -ctime +5 -exec rm -rf {} \;
Also if your find has -exec \+ you should probably use this instead:
find /home/xxx -maxdepth 1 -name 'conf_*' -type d -ctime +5 -exec rm -rf {} \+
For such a large number of matching directories I imagine the significantly reduced amount of executions of rm might be significantly more efficient.

Renaming a '.' file in Ubuntu [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I downloaded a file using rsync and accidentaly provided it the destination as '.' (I thought it is the directory to download into). So it downloaded the multi-gig file but named it '.'.
drwxr-sr-x 2 root apache 4096 May 7 00:42 .
drwxr-sr-x 7 me apache 4096 May 7 00:25 ..
-rw-r--r-- 1 1006 1006 2008805206 Apr 5 04:49 .
-rw------- 1 root apache 1675 May 7 00:25 somefile
-rw------- 1 root apache 392 May 7 00:26 anotherfile.txt
How do I rename the 2GB+ '.' file to something meaningful. Nothing I do seems to work (i've tried mv, rename, etc.) but they all say
Device or resource busy
You can use this mv:
mv ./.[[:blank:]]* myfile
Or else try this find:
find . -type f -maxdepth 1 -name '. *' -exec mv '{}' myfile \;
Yes its a superuser question. But I found a solution elsewhere, so thanks everyone for trying. We could do this using:
find . -type f | (let i=0; while read f; do mv "$f" "$f"-$i ; let i=$i+1; done)
Not the most elegant way and probably very insecure too (as there is no undo).
Type this from the directory where it is located.
mv ./. newfile

Setting file permission for Files and Directories [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
I need to apply below permission policies to my files under www folder
664 to all files in www recursively,
755 to all directories under www recursively
I tried
find . -type f -exec chmod 644 {} ;
find . -type d -exec chmod 755 {} ;
But always getting error
find: missing argument to `-exec'
What is the solution?
Backslash before semi-colon (or quotes around it):
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
The shell sees the semi-colon you typed as the end of the command and does not pass it to find, which then complains that it is missing.
Use backslash before ';'
find . -type f -exec chmod 644 {} \;

Resources