Commandes diverses: Difference between revisions

From hugovil.com
Jump to navigationJump to search
Created page with "=Affichage des fichiers avec majuscule en premier= set LC_COLLATE=C =How to do a search and replace over multiple files?= You could use find and sed, but I find that this little line of perl works nicely: <nowiki>perl -pi -w -e 's/search/replace/g;' *.php</nowiki> -e means execute the following line of code. -i means edit in-place -w write warnings -p loop Example I had the following style sheet in a section: <nowiki><link rel="stylesheet" type="tex..."
 
No edit summary
Line 23: Line 23:
So the final line of code ends up as
So the final line of code ends up as
   <nowiki>perl -pi -w -e 's/\.\.\/includes\/style\.css/admin\.css/g;' *.php</nowiki>
   <nowiki>perl -pi -w -e 's/\.\.\/includes\/style\.css/admin\.css/g;' *.php</nowiki>
=Supprimer un "/" à la fin=
DIR="/usr/local/bin/"
echo ${DIR%/}
=Effacer plusieurs fichiers avec find=
find . -name .svn -exec rm -rf {} \;

Revision as of 19:18, 2 April 2026

Affichage des fichiers avec majuscule en premier

 set LC_COLLATE=C

How to do a search and replace over multiple files?

You could use find and sed, but I find that this little line of perl works nicely:

   perl -pi -w -e 's/search/replace/g;' *.php 
 -e means execute the following line of code.
 -i means edit in-place
 -w write warnings
 -p loop

Example I had the following style sheet in a section:

 <link rel="stylesheet" type="text/css" href="../includes/style.css">

and I wanted the following instead:

 <link rel="stylesheet" type="text/css" href="admin.css">

As each expression is a regular expression you've got to escape the special characters such as forward slash and .

 \.\.\/includes\/style\.css

So the final line of code ends up as

 perl -pi -w -e 's/\.\.\/includes\/style\.css/admin\.css/g;' *.php

Supprimer un "/" à la fin

DIR="/usr/local/bin/"
echo ${DIR%/}

Effacer plusieurs fichiers avec find

find . -name .svn -exec rm -rf {} \;