Hot answers tagged

34

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. ...


33

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 ...


30

/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 ...


30

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

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 ...


24

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 ...


23


23

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


22

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 ...


20

Use the cruft package.


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. ...


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 ...


18

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.


18

You're almost right. -mtime 365 will be all files that are exactly 365 days old. You want the ones that are 365 days old or more, which means adding a + before the number like this -mtime +365. You may also be interested in the -maxdepth 1 flag, which prevents you from moving items in sub directories. If you want to be sure that you are only moving files, ...


15

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) ...


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


15

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 :-)


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 ...


14

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


14

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


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("..", O_RDONLY|O_NOCTTY|O_NONBLOCK|O_DIRECTORY|...


13

find / -name example.filename


13

If you have only '-newer file' then you can take this workaround: touch -t 201003160120 some_file find . -newer some_file man touch: -t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time Assuming that your touch has this option (mine is touch 5.97).


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

You do not need to use xargs, because find can execute commands itself. When doing this, you do do not have to worry about the shell interpreting characters in the name. find /path/to -name "*.html" -exec grep -l "rumpus" '{}' + from the find man page -exec command {} + This variant of the -exec action runs the specified command on the selected ...



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