Hot answers tagged

33

You can use nmap to run a ping scan. nmap -sP 192.168.254.* Starting Nmap 5.00 ( http://nmap.org ) at 2011-03-09 11:32 GMT Host xyzzy.lan (192.168.254.189) is up (0.00022s latency). MAC Address: 00:0C:29:5B:A5:E0 (VMware) Host plugh.lan (192.168.254.196) is up (0.00014s latency). MAC Address: 00:0C:29:2E:78:F1 (VMware) Host foo.lan (192.168.254.200) is up. ...


28

You could concoct something with -printf, but the easiest is just to tack on -print on the end. This will show what was successfully deleted.


27

xargs with the -P option (number of processes). Say I wanted to compress all the logfiles in a directory on a 4-cpu machine: find . -name '*.log' -mtime +3 -print0 | xargs -0 -P 4 bzip2 You can also say -n <number> for the maximum number of work-units per process. So say I had 2500 files and I said: find . -name '*.log' -mtime +3 -print0 | xargs -0 ...


26

/var/cache$ sudo find ./ -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq -c | sort -n 1 .6 1 .cache 1 .noconf 1 .php 1 .sl 2 .bin 2 .el 2 .tdb 4 .baseA 4 .baseB 4 .dat 4 .DB 27 .db 221 .deb find ./ -type f find only file, not ...


26

If you've got GNU find then you probably want find <directory name> -name '*.pyc' -delete If you need something portable then you're better off with find <directory name> -name '*.pyc' -exec rm {} \; If speed is a big deal and you've got GNU find and GNU xargs then find <directory name> -name '*.pyc' -print0|xargs -0 -p <some ...


23


22

No, you can use a date/time string. From man find: -newerXY reference Compares the timestamp of the current file with reference. The reference argument is normally the name of a file (and one of its timestamps is used for the comparison) but it may also be a string describing an ...


19

Well, as far as the -exec syntax goes, you could do like a lot of people, give up and use xargs: find . -type f | xargs chown username (or the files-with-spaces-and-other-nonsense-in-them-safe version) find . -type f -print0 | xargs -0 chown username Or, to try to remember the right thing to do with the semicolon, what you need to drill into your head ...


19

I generally find that using the -exec option for find to be easier and less confusing. Try this: find . -name vmware-*.log -exec rm -i {} \; Everything after -exec is taken to be a command to run for each result, up to the ;, which is escaped here so that it will be passed to find. The {} is replaced with the filename that find would normally print. ...


19

with this trick you can see the current folder - but no progress bar - sorry. watch readlink -f /proc/$(pidof find)/cwd


18

If you have GNU find you can use the -delete option: find . -name "vmware-*.log" -delete To use xargs and avoid the problem with spaces in filenames: find . -name vmware-*.log -print0 | xargs -0 rm However, your log files shouldn't have spaces in their names. Word processing documents and MP3 files are likely to have them, but you should be able to ...


17

Use the cruft package.


17

Use find ... -print0 | xargs -0 ... e.g. find /path/to -name "*.html" -print0 | xargs -0 grep -l "rumpus" from the find man page -print0 True; print the full file name on the standard output, followed by a null character (instead of the newline character that ‘-print’ uses). This allows file names that ...


17

You can you -maxdepth and -mindepth with your modified/accessed/changed attribute search of choice, i.e. find -maxdepth 1 -mtime 4 for 4 days. Don't forget to exclude the . and .. results that find returns. Useful link to many find examples.


15

Use nmap. Important to run it as root so you get the MAC addresses. Example: sudo nmap -sP 192.168.1.0/24 Will scan 192.168.1.1 - 192.168.1.255. Look up CIDR notation on wiki if you're not familiar with this subnet notation. You should be able to get nmap from the repos of any recentish Linux distro, e.g. sudo apt-get install nmap or sudo yum ...


15

locate filename Much faster than find, if you're running the locate service, and it only finds files that existed at the time updatedb last ran (usualy the night befor under the control of a cron job). You can run updatedb by hand, but that is even slower than the find cletus suggests, and requires root. I sometimes update the database by hand after ...


15

Option 1 will avoid spawning external processes, which is useful under stressed conditions. Option 2 will spawn a single xargs process, which will spawn only as many rm processes as necessary. This option is typically used with -print0 and -0 in order to handle filenames with spaces and/or newlines. Option 3 will spawn a rm process for each file. GNU ...


15

The ! operator returns true when a condition is false. So while -perm 0644 matches files that have rw-r--r-- permissions set, ! -perm 0644 matches those that don't have those permissions. The command you need is: find /path/to/dir/ -type f ! -perm 0644 -print0 | xargs -0 chmod 644


14

... find . -type f -name '*.php'


14

Use find to select the directories and wc to count them. find <directory> -mindepth 1 -type d | wc -l


14

Here is a one-liner that I believe does what you want: find /tmp -name something | egrep '.*' The return status will be 0 when something is found, and non-zero otherwise. If you also need to capture the output of find for further processing, then SvenW's answer has covered that.


14

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'


14

Looking at strace -eopen find . -type f with GNU find (4.4.2 from Debian Squeeze) the answer appears to be "no, find does not open files", but it does open directories: open("details", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 5 open("..", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|O_NOFOLLOW) = 5 open("..", ...


13

Also: find -name "*.avi" -exec ./myscript '{}' \; Womble's answer definitely works in the majority of cases, but Xargs isn't perfect with spaces across all implementations. I've never found find's 'exec' mode to break. Solaris was particularly cranky in that respect. Obviously, the '-print' would be better for simply generating output for a list of files ...


13

It looks like your /dev/null may have been deleted at some point so when you started writing to it you are writing to a plain file rather then the character special null device. You an confirm this by looking at the output of ls $ ls -l /dev/null crw-rw-rw-. 1 root root 1, 3 Sep 28 08:11 /dev/null If I'm right then you won't see a character special ...


13

GNU find's manpage says that all POSIX finds are supposed to detect filesystem loops and emit error messages in these cases, and I have tested find . -follow -printf "" on GNU find, which was able to find loops of the form ./a -> ./b and ./b -> ./a printing the error find: `./a': Too many levels of symbolic links find: `./b': Too many levels of ...


13

Use the 'find' command if you have findutils version 4.3.0 or greater installed: For all files under the current directory that are writable by the current user: find . -writable For all files under the current directory that are not writable by the current user: find . ! -writable According to the man page: This test makes use of the access(2) ...


13

GNU parallel can help too. find /dump -type f -name '*.xml' | parallel -j8 java -jar ProcessFile.jar {} Note that without the -j8 argument, parallel defaults to the number of cores on your machine :-)


12

It's possible that the timzeone issue is a red herring. find . -mtime 7 should find files that are exactly seven days old ("seven" meaning between 7.000 and 7.999 days, give or take, and "old" meaning "since last modification"). If you want files that are more than seven days old, which judging by the date on your first file (June 2010) you do, try ...


12

find / -name example.filename



Only top voted, non community-wiki answers of a minimum length are eligible