Tag Info

Hot answers tagged

30

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


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


22


22

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


21

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.


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

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


17

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

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.


16

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


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


14

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

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


14

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


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

Use the cruft package.


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


12

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


12

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


12

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


12

find / -name example.filename


12

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


11

GNU find by default uses emacs regular expressions, you can change that type with -regextype option (see man find). If you use -regextype posix-egrep your expression seems to work. You could then also probably reduce the pattern to ^.+(jpg|gif|exe)$ With emacs: find . -regex '.+\(jpg\|gif\|exe\)$' . See this section of emacs manual for those specific ...


11

From man find: -exec command {} + This variant of the -exec option runs the specified command on the selected files, but the command line is built by appending each selected file name at the end; the total number of invoca- tions of the command will be much less than the number of matched files. The command line is built in ...


11

man find -mmin File's data was last modified n minutes ago.


11

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


11

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



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