
Terminal - Commands tagged find - 369 results
This is sample output - yours may be different.
[[email protected] ~]# ls -l /etc/**/*killall
-rwxr-xr-x. 1 root root 652 Apr 19 15:47 /etc/init.d/killall
lrwxrwxrwx. 1 root root 17 May 31 06:00 /etc/rc0.d/S00killall -> ../init.d/killall
lrwxrwxrwx. 1 root root 17 May 31 06:00 /etc/rc6.d/S00killall -> ../init.d/killall
This command will give you the same list of files as "find /etc/ -name '*killall' | xargs ls -l".
In a simpler format just do 'ls /etc/**/file'.
It uses shell globbing, so it will also work with other commands, like "cp /etc/**/sshd sshd_backup".
find . -iname '*.conf' | xargs grep "searh string" -sl
This is sample output - yours may be different.
-sl : show just file names
find /var/spool/mqueue -type f -mtime +7 | perl -lne unlink
This is sample output - yours may be different.
Find all files in /var/spool/mqueue older than 7 days, pass to perl to efficiently delete them (faster than xargs or -exec when you've got millions or hundreds of thousands to delete). Naturally the type, directory, and file age vars can be adjusted to meet your specific needs.
allVideos() { find ./ -type f -print0 | xargs -0 file -iNf - | grep ": video/" | cut -d: -f1; }
This is sample output - yours may be different.
$ find ./ -type f -print0 | xargs -0 file -iNf - | grep ": video/" | cut -d: -f1
./.v.a-desk/atomic_city.wmv
./.mozilla/firefox/yhszbu0k.default/Cache/1/1A/9DD36d01
./.mozilla/firefox/yhszbu0k.default/Cache/7/A6/8BFE0d01
./.mozilla/firefox/yhszbu0k.default/Cache/6/63/FAE2Cd01
./.mozilla/firefox/yhszbu0k.default/Cache/9/D5/E16E0d01
$
Videos are found using their MIME type. Thus no need to for an extension for the video file.
This is a efficent version of "jnash" cmd (4086). Thanks for jnash. This cmd will only show video files while his cmd show files having "video" anywhere in path.
find . -type f | sed -n 's/..*\.//p' | sort -f | uniq -ic
This is sample output - yours may be different.
1 bin
15 css
8 gif
1 html
1 ico
6 jpg
21 js
Change "sort -f" to "sort" and "uniq -ic" to "uniq -c" to make it case sensitive.
lsr() { find "${@:-.}" -print0 |sort -z |xargs -0 ls $LS_OPTIONS -dla; }
This is sample output - yours may be different.
=[9 [email protected] ~ ]= $ lsr ~/.cron
drwx------ 10 h3xx users 304 Aug 13 01:45 /home/h3xx/.cron/
drwx------ 2 h3xx users 264 Aug 14 03:09 /home/h3xx/.cron/cron.01d/
-rwxr-xr-x 1 h3xx users 466 Jun 10 13:10 /home/h3xx/.cron/cron.01d/clean-chrome-tmp.sh*
-rwxr-xr-x 1 h3xx users 4973 Aug 13 22:59 /home/h3xx/.cron/cron.01d/clean-maildirs.sh*
-rwxr-xr-x 1 h3xx users 117 Aug 9 18:32 /home/h3xx/.cron/cron.01d/clean-thumbscache.sh*
-rwxr-xr-x 1 h3xx users 50 Aug 10 2010 /home/h3xx/.cron/cron.01d/linuxcounter.sh*
-rw-r--r-- 1 h3xx users 1264 Oct 12 2007 /home/h3xx/.cron/cron.01d/mkbackups.sh
-rw------- 1 h3xx users 375 Oct 7 2005 /home/h3xx/.cron/cron.01d/rcsync.sh
drwx------ 2 h3xx users 224 Aug 13 09:14 /home/h3xx/.cron/cron.01h/
-rw-r--r-- 1 h3xx users 937 Dec 31 2010 /home/h3xx/.cron/cron.01h/.bash-history.sh-notworking
-rwxr-xr-x 1 h3xx users 433 Aug 13 09:14 /home/h3xx/.cron/cron.01h/getmail-3.sh*
-rwxr-xr-x 1 h3xx users 4427 Jul 6 2010 /home/h3xx/.cron/cron.01h/randsig.pl*
-rw-r--r-- 1 h3xx users 1358 Aug 17 2010 /home/h3xx/.cron/cron.01h/stupid-curl
-rwxr-xr-x 1 h3xx users 172 Aug 13 00:09 /home/h3xx/.cron/cron.01h/waffles-log.sh*
drwxr-xr-x 2 h3xx users 80 Dec 31 2010 /home/h3xx/.cron/cron.01m/
-rw------- 1 h3xx users 218 Mar 27 2006 /home/h3xx/.cron/cron.01m/vidcap.sh
drwx--x--x 2 h3xx users 48 Mar 21 2008 /home/h3xx/.cron/cron.05m/
drwx------ 2 h3xx users 160 Aug 2 03:31 /home/h3xx/.cron/cron.07d/
-rwxr-xr-x 1 h3xx users 140 Apr 20 2009 /home/h3xx/.cron/cron.07d/clean-vim-views.sh*
-rwxr-xr-x 1 h3xx users 165 Apr 17 2008 /home/h3xx/.cron/cron.07d/insert_bash_history.sh*
-rwx--x--x 1 h3xx users 92 Sep 28 2010 /home/h3xx/.cron/cron.07d/logrotate.sh*
drwxr-xr-x 2 h3xx users 80 Aug 14 03:09 /home/h3xx/.cron/cron.15m/
-rwxr-xr-x 1 h3xx users 433 Aug 13 09:14 /home/h3xx/.cron/cron.15m/getmail-1.sh*
drwxr-xr-x 2 h3xx users 96 Aug 14 03:09 /home/h3xx/.cron/cron.30d/
-rwxr-xr-x 1 h3xx users 752 Aug 13 23:50 /home/h3xx/.cron/cron.30d/bogofilter-db-maintenance.sh*
drwx------ 2 h3xx users 144 Aug 13 09:14 /home/h3xx/.cron/cron.30m/
-rwxr-xr-x 1 h3xx users 367 Jan 23 2010 /home/h3xx/.cron/cron.30m/dyndns-update*
-rw-r--r-- 1 h3xx users 433 Aug 13 09:14 /home/h3xx/.cron/cron.30m/getmail-2.sh
lrwxrwxrwx 1 h3xx users 26 Aug 18 2008 /home/h3xx/.cron/cron.30m/process-spam.sh -> ../../libs/process-spam.sh
-rwx--x--x 1 h3xx users 4125 Aug 13 01:41 /home/h3xx/.cron/install-crontab*
-rwx--x--x 1 h3xx users 4122 Aug 13 01:34 /home/h3xx/.cron/install-crontab~*
=[9 [email protected] ~ ]= $
Tells you everything you could ever want to know about all files and subdirectories. Great for package creators. Totally secure too.
On my Slackware box, this gets set upon login:
LS_OPTIONS='-F -b -T 0 --color=auto'
and
alias ls='/bin/ls $LS_OPTIONS'
which works great.
find . -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort
This is sample output - yours may be different.
find . -type d -name 'CVS' -exec rm -r {} \;
This is sample output - yours may be different.
find . -type d -name 'CVS' | xargs rm -r
This is sample output - yours may be different.
find * -type d -maxdepth 0
This is sample output - yours may be different.
Alternatively,
ls -F | grep /\$
but will break on directories containing newlines. Or the safe, POSIX sh way (but will miss dotfiles):
for i in *; do test -d "./$i" && printf "%s\n" "$i"; done
find . -iname "*.flac" | cpio -pdm /Volumes/Music/FLAC
This is sample output - yours may be different.
#Any folders containing .flac files will be copied to the destination.
/Volumes/Music/FLAC/Music $ ls
Albert King The Best of Albert King(flac)/
Cloud Kicker/
St Germain/
Astor Piazzolla(flac)/
.flac is the filetype.
/Volumes/Music/FLAC is the destination.
find . -type f -exec chmod -x {} \;
This is sample output - yours may be different.
find . -type f -name "*.py" -exec wc -l {} \; | awk '{ SUM += $1} END {print SUM }'
This is sample output - yours may be different.
find /myfs -size +209715200c -exec du -m {} \; |sort -nr |head -10
This is sample output - yours may be different.
675.07 /myfs/sop/infranc/med/20110201/det_med_MOS.txt
393.57 /myfs/sop/inffin/part/20110407/fact_par_201103.accdb
338.03 /myfs/20110501/det_med_MOS.txt
338.02 /myfs/AC/SGE/20110501/EVID.txt
338.00 /myfs/infranc/med/20110601/det_med_EOV.txt
337.96 /myfs/AC/SGE/20110601/EVID.txt
Specify the size in bytes using the 'c' option for the -size flag. The + sign reads as "bigger than". Then execute du on the list; sort in reverse mode and show the first 10 occurrences.
find -type f -printf "%S\t%p\n" 2>/dev/null | gawk '{if ($1 < 1.0) print $1 $2}'
This is sample output - yours may be different.
Prints the path/filename and sparseness of any sparse files (files that use less actual space than their total size because the filesystem treats large blocks of 00 bytes efficiently).
find . -name '*.java' -o -name '*.xml' | grep -v '\.svn' | xargs wc -l
This is sample output - yours may be different.
123 ./src/java/com/company/app/service/Foo.java
42 ./test/java/com/company/app/service/FooTests.java
165 total
There's nothing particularly novel about this combination of find, grep, and wc, I'm just putting it here in case I want it again.
ack "search pharse" *.[ch]
This is sample output - yours may be different.
ack search recursively by default
find . -type f -printf %s\\n | numsum
This is sample output - yours may be different.
pipe into
| sed "s/$/\/(1024\*1024\*1024)/" | bc
to get size in GB
find . -type f -newermt "2010-01-01" ! -newermt "2010-06-01"
This is sample output - yours may be different.
Find files in a specific date range - in this case, the first half of last year.
-newermt = modification time of the file is more recent than this date
GNU find allows any date specfication that GNU date would accept, e.g.
find . -type f -newermt "3 years ago" ! -newermt "2 years ago"
or
find . -type f -newermt "last monday"
touch -t 201001010000 begin; touch -t 201012312359.59 end; find . -newer begin -a ! -newer end
This is sample output - yours may be different.
Example above will recursively find files in current directory created/modified in 2010.
find . -name "*.[ch]" -print | xargs grep -i -H "search phrase"
This is sample output - yours may be different.
Original submitter's command spawns a "grep" process for every file found. Mine spawns one grep with a long list of all matching files to search in. Learn xargs, everyone! It's a very powerful and always available tool.
perl -MFile::Find -e"finddepth(sub{rmdir},'.')"
This is sample output - yours may be different.
find -L / -samefile /path/to/file -exec ls -ld {} +
This is sample output - yours may be different.
This command finds and prints all the symbolic and hard links to a file. Note that the file argument itself be a link and it will find the original file as well.
You can also do this with the inode number for a file or directory by first using stat or ls or some other tool to get the number like so:
stat -Lc %i file
or
ls -Hid file
And then using:
find -L / -inum INODE_NUMBER -exec ls -ld {} +
find . -maxdepth 1 -type f -not -iname '*.jpg' -ls |awk '{TOTAL+=$7} END {print int(TOTAL/(1024^2))"MB"}'
This is sample output - yours may be different.
With this sentence we can estimate the storage size of all files not named *.jpg on the current directory.
The syntax is based on Linux, for Unix compliance use:
find ./* -prune ! -name '*.jpg' -ls |awk '{TOTAL+=$7} END {print int(TOTAL/(1024^2))"MB"}'
We can change the jpg extension for whatever extension what we need
find . -maxdepth 1 -type f -mtime +60 -ls
This is sample output - yours may be different.