Rename all files which contain the sub-string ‘foo’, replacing it with ‘bar’

12/02/2024 Categories: Système Tags: , Comments off

Source: commandlinefu.com

Terminal – Rename all files which contain the sub-string ‘foo’, replacing it with ‘bar’

for i in ./*foo*;do mv -- "$i" "${i//foo/bar}";done

Rename all files which contain the sub-string ‘foo’, replacing it with ‘bar’

That is an alternative to command 8368.

Command 8368 is EXTREMELY NOT clever.

  1. Will break also for files with spaces AND new lines in them AND for an empty expansion of the glob ‘*’
  2. For making such a simple task it uses two pipes, thus forking.
  3. xargs(1) is dangerous (broken) when processing filenames that are not NUL-terminated.
  4. ls shows you a representation of files. They are NOT file names (for simple names, they mostly happen to be equivalent). Do NOT try to parse it.

Why? see this :http://mywiki.wooledge.org/ParsingLs

Recursive version:

find . -depth -name "*foo*" -exec bash -c 'for f; do base=${f##*/}; mv -- "$f" "${f%/*}/${base//foo/bar}"; done' _ {} +

Alternatives

ls * | sed -e 'p;s/foo/bar/' | xargs -n2 mv

Renames all files in a directory named foo to bar.

  • foobar1 gets renamed to barbar1
  • barfoo2 gets renamed to barbar2
  • fooobarfoo gets renamed to barobarfoo

NOTE: Will break for files with spaces AND new lines AND for an empty expansion of the glob ‘*’


rename 's/foo/bar/g' ./* $ ls
thisFileIsCalledDAVE
$ rename 's/DAVE/PETE/g' ./*
$ ls
thisFileIsCalledPETE

Would this command line achieve the desired function? My CLI knowledge is not great so this could certainly be wrong. It is merely a suggestion for more experienced uses to critique. Best wishes roly 🙂


for f in *; do mv "$f" "${f/foo/bar}"; done

without sed, but has no problems with files with spaces or other critical characters


ls | sed 'p;s/foo/bar/' | xargs -n2 mv

rename foo bar directory/filename

rename command in my system -Fuduntu running 2.6.38 Linux Kernel- is an ELF 64-bit LSB executable, not a Perl script. man page for rename command shows syntax as « rename from to where » (or something like that), so I am doing just what I have been told…

 

Categories: Système Tags: ,

How to Use RSA Key for SSH Authentication

12/02/2024 Categories: Réseau, Système Tags: , , Comments off

If your daily activity requires loging in a lot of Linux systems through SSH, you will be happy to know (if you don’t already) that there’s a way to allow secure, authenticated remote access, file transfer, and command execution without having to remember passwords for each individual host you connect.

The $HOME/.ssh/authorized_keys file contains the RSA keys allowed for RSA authentication. Each line contains one key, which consists of the following fields: options, bits, exponent, modulus and comment. The first field is optional, bits, exponent and modulus fields give the RSA key and the last field isn’t used at all in the authentication process, but it will be somewhat convenient to the user, for instance to know which key is for which machine.

Before we start, make sure your computer has a ssh client installed and the remote Linux system has ssh installed and sshd running, with RSA authentication enabled (RSAAuthentication yes in /etc/ssh/sshd_config).

Lire la suite…

Categories: Réseau, Système Tags: , ,

Se logguer à distance avec ssh (Linux)

11/02/2024 Categories: Système Tags: , , , , Comments off

Source: Comment ça marche

Les commandes suivantes nécessitent d’avoir un compte sur la machine sur laquelle on veut se connecter et qu’un serveur SSH y soit installé.

Sous Linux, la syntaxe est simple (le client étant intégré dans la plupart des distributions) :

Dans un terminal (n’importe lequel), tapez :

ssh login:motDePasse@MachineSurLaquelleJeveuxmeconnecter
ou
login@(machine sur laquelle je veux me connecter )

Dans ce cas-là, si la machine accepte la connexion, le mot de passe vous sera demandé juste après.
Pour se logguer en mode graphique (utiliser un serveur X), il faut utiliser l’option -X.

Utilisation de SSH à travers un proxy

Installez tout d’abord le paquet proxy-connect :

sudo aptitude install proxy-connect

Modifiez le fichier /etc/ssh/ssh_config pour permettre l’utilisation de SSH en passant par le proxy :

sudo echo 'ProxyCommand /usr/bin/connect-proxy -4 -S monproxy.domaine.com:port %h %p' >> /etc/ssh/ssh_config

Veillez à bien remplacer « monproxy.domaine.com » et « port » par le nom de votre proxy et son numéro de port.

Requête SQL pour trouver les doublons d’une table MySQL

11/02/2024 Categories: Bases de données Tags: , Comments off

Comment trouver les doublons d’une table avec une requête SQL dans une base de données MySQL ?

Pour vérifier la présence ou l’absence de doublon dans une colonne d’une table MySQL, il existe une reqûete SQL permettant d’éviter de lire « manuellement » les données.

Compter les valeurs et trouvers les comptes supérieur à 1

SELECT COUNT( nom) , nom
FROM  `Matable`
GROUP BY nom
HAVING COUNT( nom) >1

L’exécution de cette requête affichera les noms présents plus d’une fois dans le domaine.

Categories: Bases de données Tags: ,

How to reset the administrator password in ISPConfig 3 ?

10/02/2024 Categories: Logiciel Tags: , , , , Comments off

Source: faqforge.com

If you lost your ISPConfig 3 administrator password, you can reset it with the following SQL query.

UPDATE sys_user SET passwort = md5(‘admin’) WHERE username = ‘admin’;

The SQL query sets the password to “admin” for the user “admin”, it has to be executed in the ISPConfig mysql database, e.g. with phpmyadmin. If you dont have phpmyadmin installed, then the query can be executed with the mysql commandline utility as well:

Login to the mysql database.

mysql -u root -p

and enter the password of the mysql root user. To switch to the ISPConfig database, run this command:

use dbispconfig;

Now execute the SQL command:

UPDATE sys_user SET passwort = md5(‘admin’) WHERE username = ‘admin’;

and close the mysql shell:

quit;