search all files and only empty directories using find command
Hi All,
I wanted to search all empty, non empty files and only empty directories. Tried. Code:
find /path/of/dir -type d -empty -type f So how to search using single find command. Please help. |
have you tried this?
Quote:
|
Quote:
The above command is listing only empty files and directories. But I wanted to search all files and also only empty directories using find command at one time. So please help. |
Can you explain in more detail; your request doesn't make sense to me
'only empty dirs' conflicts with searching files. If a file is there, its obviously in a non-empty dir. See also ' search all empty, non empty files' which is a contradiction as written.... |
Tnanks for the reply chrism01.
I am asking that is there a way to search in a single command by putting multiple types instead of searching as below by putting && Code:
touch -t 201306131200 /tmp/timestamp |
Can any body please help for the above?
|
Please have some patience. The people who can help you can come at any time.
It also helps to explain very clearly what you want to do. Give some background information about your goal, so we can better understand it. So you just want to combine multiple tests and actions? Well, find has \(..\) grouping brackets, so perhaps something like this? Code:
find . \( -newer /tmp/timestamp -type d -empty -print \) -o \( -newer /tmp/timestamp -type f -print \) >> /tmp/searchlist Code:
find . \( -newermt 201306131200 -type d -empty -print \) -o \( -newermt 201306131200 -type f -print \) >> /tmp/searchlist http://mywiki.wooledge.org/UsingFind http://www.grymoire.com/Unix/Find.html |
Sorry but I.m not sure I understand what you are after.
but here is a try. you want a list of empty dirs or any file which are newer than T? Code:
find . -newer /tmp/timestamp -type d -empty -o -newer /tmp/timestamp -type f -a and Note, -a is implied when you have two expr e.g. Code:
find . -newer /tmp/timestamp -a -type d -a -empty -o -newer /tmp/timestamp -a -type f I still don't understand why you want empty dirs and all files if it is for this http://www.linuxquestions.org/questi...me-4175465857/ and you want to exclude empty stuff from tar Code:
tar -c `find . -newer /tmp/timestamp -type f ! -empty | sed s/\ /?/g` -f YourTar.tar I think I half understand the empty dir thing, nearly. |
Quote:
Code:
# find /data/cli/ \( -newer /tmp/timestamp -type d -empty -print \) -o \( -newer /tmp/timestamp -type f -print \) I just wanted to backup using only tar whatever it found i.e even for those files/directories even if they have white space in their names. Please see the below. Code:
# ls -l /data/cli/etc/sane.d/dll.d/L\ i\ n\ u\ x Code:
# tar -cpjvf $(find /data/cli/ \( -newer /tmp/timestamp -type d -empty -print \) -o \( -newer /tmp/timestamp -type f -print \)) Once again thanks a lot and waiting for your kind reply. |
David's find piped through sed
Code:
tar -c $(find /data/cli/ \( -newer /tmp/timestamp -type d -empty -print \) -o \( -newer /tmp/timestamp -type f -print \)|sed s/\ /?/g) -f YourTar.tar This will be better , escape hell :D Code:
tar -c $(find /data/cli/ \( -newer /tmp/timestamp -type d -empty -print \) -o \( -newer /tmp/timestamp -type f -print \)|sed s/\ /\\\\\ /g) -f YourTar.tar Scratch that, not working |
Quote:
Thanks a lot Firerat. Code:
# find /data/cli/ -newer /tmp/timestamp -type d -empty -o -newer /tmp/timestamp -type f As you can see in above output, the colored file & directory respectively which are having white spaces in their names also should be backed up. Code:
# tar -c `find /data/cli -newer /tmp/timestamp -type f ! -empty | sed s/\ /?/g` -f /tmp/mytar.tar Code:
# tar -tvf /tmp/mytar.tar And also I wanted it to be in tar.bz2 format only. So could you please provide a command for tar.bz2? If you don't mind could please explain "sed s/\ /?/g". Since I am newbie in sed I did not understand that for what it is. |
Quote:
Code:
# tar -tvf YourTar.tar |
Quote:
the sed is quite simple sed s/\ /?/g sed is substituting ' ' with '?' , all of them ( group ) sed s/\ /?/ would result in just the first ' ' being substituted, the g at the end processes all the matches man sed or more info https://startpage.com/do/search?cmd=...arch&query=sed sed ( stream editor ) is a big subject |
Quote:
the sed is quite simple sed s/\ /?/g sed is substituting ' ' with '?' , all of them ( group ) sed s/\ /?/ would result in just the first ' ' being substituted, the g at the end processes all the matches ? is a bit like *, but ? is treated as any single character, which is why it is not perfect Code:
touch "this is an example" man sed or more info https://startpage.com/do/search?cmd=...arch&query=sed sed ( stream editor ) is a big subject |
Quote:
Code:
# ls -l this?is?an?example |
All times are GMT -5. The time now is 05:38 PM. |