Browsing articles tagged with "find - Admins Goodies"
Apr 14, 2013
tom

Recursively delete empty folders with verbose output

This should be fairly simple, but I am not sure what i’m missing. I’d like to recursively delete empty directories, and get an output for what’s being deleted, this command works for sure, but I just can’t print the actions of -excec verbosely. while [ -n "$(find . -depth -type d -empty -exec rm -v -rf {} +)" ]; do :; done by recursively I mean, I want to keep deleting empty folders, until there’s […]

Continue Reading »
Jan 8, 2013
tom

Running a script containing find with a regexp fails in cron but works in a shell

I have the following script in my /etc/cron.d: 19 15 * * * root /opt/scripts/clean-nexus-release-repo.sh The clean-nexus-release-repo.sh script looks like this: #!/bin/bash find /opt/sonatype-work/nexus/storage/releases/se/company* -regextype posix-extended -depth -regex ‘.*/r?[0-9]{5,7}[a-Z0-9_.-]*\.[0-9]{1,3}’ -mtime +60 -type d -print -exec rm -r {} \; find /opt/sonatype-work/nexus/storage/releases/nu/company -regextype posix-extended -depth -regex ‘.*/r?[0-9]{5,7}[a-Z0-9_.-]*\.[0-9]{1,3}’ -mtime +60 -type d -print -exec rm -r {} \; When I run the clean-nexus-release-repo.sh script from my shell everything works fine. When it is run through cron I […]

Continue Reading »
Nov 19, 2012
tom

How to find any file that is an executable or library

Let’s say someone provides you with a tarball, saying it is source code and nothing else. You want to make sure that is true, and that no virus-laden executables or libraries are tucked away in a directory. How to use the find command to do this? Thanks. Asked by Asker You can uncompress the file in a safe place (like a filesystem mounted noexec) and check the resulting directories for binaries. The file command can […]

Continue Reading »
Jul 10, 2012
tom

Calculate disk space occupied by many .png files

I have 357 .png files located in different sub dirs of the current dir: settings# find . -name \*.png |wc -l 357settings# find . -name \*.png | head ./assets/authenticationIcons/audio.png ./assets/authenticationIcons/bbid.png ./assets/authenticationIcons/camera.png ./bin/icons/ca_video_chat.png ./bin/icons/ca_voice_control.png ./bin/icons/ca_vpn.png ./bin/icons/ca_wifi.png Is there a oneliner to calculate the total disk space occupied by them (before I pngcrush them)? I’ve tried (unsuccessfully): settings# find . -name \*.png | xargs du -s 4 ./assets/support/wifi_locked_icon_white.png 1 ./assets/support/wifi_vpn_icon_connected.png 1 ./assets/support/wi_fi.png 1 ./assets/support/wi_fi_conected.png 8 ./bin/blackberry-tablet-icon.png 2 […]

Continue Reading »
May 25, 2012
tom

How to find all filenames with given extension

I need to find all .pem files on my system. Would the following do this? sudo find / -type f -name *.pem If not, how would I write a find command to find every file of the sort? Asked by David542 You’re on the right track — you just need to quote the pattern so that it gets interpreted by find and not by your shell: sudo find / -type f -name ‘*.pem’ Answered by […]

Continue Reading »
Apr 20, 2012
tom

find executables

The following command works on Ubuntu (GNU findutils 4.4.2) but not on Fedora (4.2.27) time find . -maxdepth 1 -type f -executable -print How do I find executable files using older version of find? Asked by shantanuo find . -maxdepth 1 -type f -perm /a+x From the man: -perm /mode Any of the permission bits mode are set for the file. Symbolic modes are accepted in this form. You must specify ’u’, ’g’ or ’o’ […]

Continue Reading »
Apr 20, 2012
tom

find files without any extension

How do I find the files those do not have an extension? For e.g. in the following screen, I will like to return the file sconnect and not .xls -rwxr-xr-x 1 root root 12K Mar 7 19:29 ./Purchase_ORDER.xls -rwxr-xr-x 1 root root 176 Mar 7 19:29 ./sconnect Asked by shantanuo try: # find -type f -not -name ‘*.*’ good luck! Answered by Mario Check more discussion of this question. Bookmark on Delicious Digg this post […]

Continue Reading »
Mar 28, 2012
tom

`find` command not available in web host, how to implement a delete based on modification time using other commands?

I’m creating a simple datebase backup solution for a client using web hosting at DataFlame. The web hosting account provides access to cron but not a shell. I have a database backup script creating regular backups and I want to automatically remove those more than N days old. I attempted to use find -v $backup_dir -mtime +$keep_days -name “*db.tar.gz” -delete however the user executing the script does not have permission to run find. Can you […]

Continue Reading »
Mar 27, 2012
tom

How to tell if a file is older than 30 minutes on AIX?

I’d like to write a shell script in ksh or bash which exits with 1 if a specific file is older than 30 minutes. (Last modification time is older than half hour). It would be easy on a Linux or a modern unix, but I have to do it on AIX 5.2 version. So the constraints: there is no -mmin -mmax options in ‘find’ there is no -d option in touch (touch -d ’30 minutes […]

Continue Reading »
Mar 16, 2012
tom

On Unix on could I get a listing of all mp3 files inside a directory containing other directories with their full path?

Someone said to me use the find command but I’m not exactly sure how to do it. Basically I need this: suppose I have a folder called dir1 and it contains three sub-directories (dir2, dir3 and dir4 respectively) and suppose there might be mp3 files in all of the aforementioned directories. I would like to run a terminal command on dir1 that would search recursively through all the folders and list full paths of where […]

Continue Reading »
Pages:1234567...12»