Archive

Articles taggués ‘shell’

How to chmod 755 all directories but no file (recursively)?

15/02/2024 Comments off

zqtPL

To recursively give directories read&execute privileges:

find /path/to/base/dir -type d -exec chmod 755 {} +

To recursively give files read privileges:

find /path/to/base/dir -type f -exec chmod 644 {} +

Or, if there are many objects to process:

chmod 755 $(find /path/to/base/dir -type d)
chmod 644 $(find /path/to/base/dir -type f)

Or, to reduce chmod spawning:

find /path/to/base/dir -type d -print0 | xargs -0 chmod 755 
find /path/to/base/dir -type f -print0 | xargs -0 chmod 644

 

Categories: Système Tags: ,

How to Kill Zombie Process?

13/02/2024 Comments off

Source: Linux Addicted

Use Command Check Process:

#top

or

#ps aux

or

#ps -el

or

#ps aux | awk '{ print $8 " " $2 }' | grep -w Z

or

#ps -elf | grep Z

or

#ps -ef | grep firefox

Output:

Z 6502
Z 8320
Z 6985

Use Command kill zombie Process:

# kill -9 6985
Categories: Système Tags: ,

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

12/02/2024 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 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 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.