flogiston

Blog

Find something that isn't there in Linux and other nifty snippets

· admin · Linux

As I switch often between Linux and Windows, I tend to forget the most basic stuff. A little brain and a lot of garbage in it doesn't help obviously. One of the things I use quite often (and have to look up repeatedly) is how to find something in Linux.

One of the ways is:

grep -lr -H -i 'between ' .

if you leave out the l, you'll get the line containing what you looked for too
the . indicates the current directory
the -r indicates, obviously, recursive.
the -i indicates: case insensitive

# list all *.swf files recursively in a certain directory

ls -Rlrth path/to/directory | grep "swf\|webapps"

# And one of my favorites: find something that isn't there:
# find in a directory all files that don't contain a certain line.

find /path/to/look/in/ -name *.xml -print | xargs grep -iL 'MODEL'

# find in a file all lines that don't cointain a certain value
cat filename.xml | grep -v 'MODEL'[/shell]

# to delete all CVS folders recursively

find . -name CVS -delete 

# find process with full startup path

ps -auxww | grep tomcat3

# create a symbolic link (symlink)

ln -s target alias

# to resume the download of a file

wget -c "http://www.website.com/download/file.tar"

# to show the meaning of a certain mySQL error

perror 150

# to mount a usb mass storage device:
Changing the permissions of the mount point cannot make the device's contents writable for users, as the permissions are overwritten by the filesystem driver when it mounts the device. Instead, you have to use the appropriate mount(8) option, umask=0 in this case. The command would be

mount /dev/sda1 /mnt/USB -o umask=0

or just mount /mnt/USB when /etc/fstab contains the following line:

/dev/sda1 /mnt/USB auto umask=0,noauto 0 0
mount /dev/sda1 /media/archos -o umask=0
umount /media/archos

# Find and replace

find [path] f -name [filenamepattern] -exec sed -i 's/findvalue/replacevalue/g' {} \; 

eg. find . -type f -name falsetrue*.txt -exec sed -i 's/,False/,0/g' {} \;
# or also:

sed -e 's/False/0/g' false.txt > zero.txt
find pub -type f -name *.xml -exec sed -i 's/findme.localhost/www.productionurl.com/g' {} \;

# find & replace in a single file and output in a new file:

cat findme.localhost.conf  | sed 's/findme/replaceme/g' > replaceme.localhost.conf

# Global search & destroy:
===========================================================================================


#!/bin/sh

cd /

for file in `find  /path/to/file -name update.xml`
 do
  echo "Sedding ${file}"
  cat ${file} | \
  sed
's/<fileName>http:\/\/www.website.com\/XML\/list.xml<\/fileName>/<f
ileName>http:\/\/www.website.com\/XML\/[MODEL].xml<\/fileName>/g' \
  > ${file}.new
  mv ${file}.new ${file}
  chown userx ${file}
 done

for file in `find  /export/home/userx/share/uploads/ -name
update.xml`
 do
  echo "Sedding ${file}"
  cat ${file} | \
  sed
's/<fileName>http:\/\/www.website.com\/XML\/list.xml<\/fileName>/<f
ileName>http:\/\/www.website.com\/XML\/[MODEL].xml<\/fileName>/g' \
  > ${file}.new
  mv ${file}.new ${file}
  chown userx ${file}
 done

===========================================================================================
# import a key

sudo rpm --import http://rpm.livna.org/RPM-LIVNA-GPG-KEY

# prepare rpm package, later to be installed with yum install vlc...

rpm -ivh http://rpm.livna.org/livna-release4.rpm 

# http://rpm.livna.org/configuration.html
# view boot grub config file

vi /boot/grub/grub.conf

1 comment

bart vandendriessche ·

Another nice way to list all *.swf files recursively in a certain directory is as follows:

find /certaindirectory -name '*.swf'