find -type d and ls return different results on same directory - find

I'm trying to think of a reason find would return partial results on Ubuntu 16.04. I have a google drive mount (using plexdrive) located at
/home/user/media
When using
find $HOME/media -type d
16 results are returned. When using
ls -d $HOME/media/*/
186 results are returned. The folders are all browsable via sftp and samba shares, all permissions on relevant directories are 775. The content in the media directory is formatted as
a/a.ext
b/b.ext
c/c.ext
Has anyone seen this type of behavior before or have any clues on how to get find to return the full results?

This happens when find is looking at a directory with symbolic links. Use the -L flag to see the proper folder structure. find -L $HOME/media -type d

Related

Command line find if path matches and remove all contents

I'm trying to locate all folders that match a certain path.
The path is public_html/core/cache
I can find all instances of cache with the command below, however this does return results from elsewhere which are undesired!
find . -name cache -print
I've tried the below, but it presents an error.
find . -name public_html/core/cache -print
I'd like to run the script once to ensure the results are accurate, then afterwards run it again, removing all contents of the returned folder.
Many thanks in advance
A kind friend gave me the solution:
find / -type d -path "*core/cache" -print

ClearCase - How to Find All Checkins By One User for an Entire PVOB?

I have been asked to find every checkin by one specific user across an entire ClearCase Project VOB since a particular date. How might I obtain this information?
I assume it's some usage of the cleartool find command, but I've not yet figured out the syntax to get the information that I'm looking for.
I guess I'm looking for a "change set" across every activity of that user across every stream of a given PVOB since a particular date.
Looking at cleartool find (which work for versions created with or without UCM), it should be something like:
cleartool find . -user <auser> -version "{created_since(date1)}" -print
This is done within a vob, not a pvob, as it search for version (data), not UCM activities (metadata recorded on PVob level)
You need first to go to a view, preferably a dynamic view:
cd m:\aView\aVob
# unix
cd /view/aview/vobs/avob
As noted by the OP's answer, what works is:
using create_by instead of -user,
adding -all -nvis.
With the repeated help of (and huge thanks to) #VonC, here is what I wound up using, at a command prompt (not in a ClearTool session), with my working directory set to the directory just beneath the root of my snapshot view:
cleartool find . -all -name "*" -version "{created_by(<userid>) && created_since(dd-Mmm-yyyy)}" -print > <absolute path to output file>
Update: The command below, which was originally my answer, returns only invisible files:
cleartool find . -all -nvisible -name "*" -version "{created_by(<userid>) && created_since(dd-Mmm-yyyy)}" -print > <absolute path to output file>

Find command with prune option is not working in particular directory in KSH

I want to list down .success files in dly folder and not within dly folder recursively as below.
find /CD/dly/ * prune -name "*.success"
Above command is listing file list properly. However when I switch to /AB/dly/ and run the same command
cd CD AB
find /AB/dly/ * prune -name "*.success"
It is showing below error.
find: bad option -ltr
Is it problem with AB directory? or something else?

Recursively replace colons with underscores in Linux

First of all, this is my first post here and I must specify that I'm a total Linux newb.
We have recently bought a QNAP NAS box for the office, on this box we have a large amount of data which was copied off an old Mac XServe machine. A lot of files and folders originally had forward slashes in the name (HFS+ should never have allowed this in the first place), which when copied to the NAS were all replaced with a colon.
I now want to rename all colons to underscores, and have found the following commands in another thread here: pitfalls in renaming files in bash
However, the flavour of Linux that is on this box does not understand the rename command, so I'm having to use mv instead. I have tried using the code below, but this will only work for the files in the current folder, is there a way I can change this to include all subfolders?
for f in *.*; do mv -- "$f" "${f//:/_}"; done
I have found that I can find al the files and folders in question using the find command as follows
Files:
find . -type f -name "*:*"
Folders:
find . -type d -name "*:*"
I have been able to export a list of the results above by using
find . -type f -name "*:*" > files.txt
I tried using the command below but I'm getting an error message from find saying it doesn't understand the exec switch, so is there a way to pipe this all into one command, or could I somehow use the files I exported previously?
find . -depth -name "*:*" -exec bash -c 'dir=${1%/*} base=${1##*/}; mv "$1" "$dir/${base//:/_}"' _ {} \;
Thank you!
Vincent
So your for loop code works, but only in the current dir. Also, you are able to use find to build a file with all the files with : in the filename.
So, as you've already done all this, I would just loop over each line of your file, and perform the same mv command.
Something like this:
for f in `cat files.txt`; do mv $f "${f//:/_}"; done
EDIT:
As pointed out by tripleee, using a while loop is a better solution
EG
while read -r f; do mv "$f" "${f//:/_}"; done <files.txt
Hope this helps.
Will

using grep and find commands - basic questions to help me sort it out in my simple mind

I am back with a second no-brainer question, but I would like to get this straight in my head.
I have an assignment in which I am charged with providing a command to find a file named test in my home directory (one command using find, and one using grep). I understand that using find is just 'find ~/test', but using grep, wouldn't I have to search out a pattern within the file 'test'? Or is there a way to search for the file (using grep), even if the file is empty?
ls ~ | grep test
I understand that using find is just 'find ~/test'
No. find ~/test will also have a match for every file or directory under the directory $HOME/test/. Rather use find ~ -type f -name test.
The assignment sounds unclear. But yes, if you give any filenames to grep, it will look at the contents of the files and ignore the names of the files. Perhaps you can grep the output of another command? Maybe ls as #Reese suggested, or maybe a different find command.
ls -R ~ | grep test
Explanation: ls -R ~ will recursively list all files and directories in your home folder. grep test will narrow down that list to files (and directories) that have "test" in their name.