Posted on Leave a comment

yum update problem “[Errno -1] repomd.xml does not match metalink for updates Trying other mirror.“

MirrorManager is a piece of SW Fedora/RedHat utilizes to provide yum with the lists of mirrors to yum. I.e., “MirrorManager not working correctly”, in this case means yum on a users’s system receives incorrect data.

On the user side, one way to work around the effects of this defect is to remove the metadata files your yum caches.

E.g. by using “yum clean < ...all,metadata>” or by brute force: # rm -f /var/cache/yum/updates/{*xml*,*sql*,*cookie} and to rerun “yum update”.

Posted on Leave a comment

Search and Replace in all files within a folder recursively on Linux/Unix

In order to search recursively through directories, looking in all the files for a particular string, then to replace that string with something else (on linux/Unix), these commands should work (Where string1 is the original string and string2 is the replace-string):

[box type=”shadow”]find ./ -type f -exec sed -i ‘s/string1/string2/’ {} \;[/box]

It would have been better to use xargs instead of -exec. Using xargs, you will fork fewer times. For large numbers of files, that means you will be done faster. In other words:

[box type=”shadow”]find ./ -type f | xargs sed -i 's/string1/string2/'[/box]

Instead of editing all files in a directory, you can use the same concept with grep to edit only files containg a certain string. In other words:

[box type=”shadow”]grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/'[/box]

The trick works fine except for one thing: It only replaces the first instance of string1 it finds in each file. For example if you had 100 instances of string1 in some files, then you would have to run the command 100 times! Also, if you don’t know how many times string1 can be found in the files, then you also don’t know how many times ou have to run the command before everything is replaced.

One Solution:

[box type=”shadow”]grep -rl matchstring somedir/ | xargs sed -i ’s/string1/string2/g’

the g on the edn will replace globally – all instances of string1[/box]

BEWARE:

If any of the files fed through xargs are binary, both sed and perl will change the timestamps of the files that all have the string, binary files or text files, but no changes are made (in at least the one file *I* was looking at at the top of the file directory hierarchy). So filter out binary files.

Another simpler Solution:

use the ‘rpl’ command (apt-get install rpl; yum install rpl):

[box type=”shadow”]rpl -x'.cpp' -x'.h' -pR "old-string" "new-string" *[/box]

or replace directly without prompt

[box type=”shadow”]rpl -x'.cpp' -x'.h' -R "old-string" "new-string" *[/box]

Here, all files with a .cpp or .h suffix wil be searched for an “old-string”. If found the “old-string” is replaced by the “new-string” in all directories recursively.

Another Solution FIY:
The rrep program lets you replace strings in multiple files and also recursively in directories. It also supports regular expressions. The usage is similar to grep.
http://sourceforge.net/projects/rrep/

Posted on Leave a comment

Trash works on NTFS when mounted by Nautilus, but not when automounted via /etc/fstab

I have 2 “data” drives. One is ntfs, the other is ext4.

The Trash works for both drives when I allow Nautilus to handle the mount.

I’ve opted to auto-mount them via entries in /etc/fstab, but when I do this, only the ext4 gives me a functioning Trash directory.

Trash on the ntfs drive simply does not work.
When I press “delete” or use the context menu item “Move to Trash”, I get this error dialogue message.

Cannot move file to trash, do you want to delete immediately?
. . . . The file “test” cannot be moved to the trash . . . .

Here are my /etc/fstab lines.

/dev/sdb1 /media/D_0931_data ntfs defaults 0 0
/dev/sdc1 /media/E_0298_back ext4 defaults 0 0

… and here is how I created the mountpoint directories.

sudo mkdir /media/D_0931_data
sudo mkdir /media/E_0298_back

Everything seems to be working fine, except for the Trash on the ntfs drive…
The Trash on the ext4 drive works normally.

SOLUTION:

I believe Nautilus needs a .Trash-1000 folder in the root of the filesystem (e.g. /media/D_0931_data/.Trash-1000) to exist and be user-writeable.

NOTE: the 1000 in the .Trash-1000 is your user ID. You can get yours by id -u USERNAME. Change it accordingly if needed.

Try running this: sudo mkdir /media/D_0931_data/.Trash-1000; sudo chmod 777 /media/D_0931_data/.Trash-1000.

If that didn’t work, can you try the same but with .Trash instead of Trash-1000, and if that didn’t work, post the output of ls -la /media/D_0931_data?

Try adding this to fstab (on the ntfs line): defaults,uid=1000 instead of just defaults.