Articles taggués ‘commandes’

20 Linux System Monitoring Tools Every SysAdmin Should Know

17/11/2018 Aucun commentaire

monitoring toolsNeed to monitor Linux server performance? Try these built-in command and a few add-on tools. Most Linux distributions are equipped with tons of monitoring. These tools provide metrics which can be used to get information about system activities. You can use these tools to find the possible causes of a performance problem. The commands discussed below are some of the most basic commands when it comes to system analysis and debugging server issues such as:

  1. Finding out bottlenecks.
  2. Disk (storage) bottlenecks.
  3. CPU and memory bottlenecks.
  4. Network bottlenecks.

#1: top – Process Activity Command

The top program provides a dynamic real-time view of a running system i.e. actual process activity. By default, it displays the most CPU-intensive tasks running on the server and updates the list every five seconds.

top-output-269x300Commonly Used Hot Keys

The top command provides several useful hot keys:

Hot Key Usage
t Displays summary information off and on.
m Displays memory information off and on.
A Sorts the display by top consumers of various system resources. Useful for quick identification of performance-hungry tasks on a system.
f Enters an interactive configuration screen for top. Helpful for setting up top for a specific task.
o Enables you to interactively select the ordering within top.
r Issues renice command.
k Issues kill command.
z Turn on or off color/mono

Lire la suite…

How to Kill Zombie Process?

08/11/2018 Aucun commentaire

Source: Linux Addicted

Use Command Check Process:



#ps aux


#ps -el


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


#ps -elf | grep Z


#ps -ef | grep firefox


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’

08/11/2018 Aucun commentaire


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 :

Recursive version:

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


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
$ rename 's/DAVE/PETE/g' ./*
$ ls

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 Bulk Rename Files in Linux (Terminal or GUI)

01/11/2018 Comments off

Source: Webmaster tips

There are several ways to bulk rename files in Linux. If you want to bulk rename files with a GUI tool, try Thunar file manager, or Krename.

Tip: To install Thunar on Ubuntu/Debian, type sudo apt-get install thunar in a terminal. To install Krename, type sudo apt-get install krename.
How to bulk rename files from the terminal

If you have a directory of files that you would like to bulk rename, you can use the rename command from the terminal.
UPDATE: I believe the Perl-based rename command is only available on Debian-based Linux distros, but there are instructions on adding it to other distros below.

The syntax for the rename command is:

rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]

-v means « verbose » and it will output the names of the files when it renames them. It is a good idea to use this feature so you can keep track of what is being renamed. It is also a good idea to do a test run with -n which will do a test run where it won’t rename any files, but will show you a list of files that would be renamed.

The « perlexpr » part of the command is a Perl expression. Don’t panic yet…
The « rename » command in action

Here is an example of the rename command:

rename -n ’s/\.htm$/\.html/’ *.htm

The -n means that it’s a test run and will not actually change any files. It will show you a list of files that would be renamed if you removed the -n. In the case above, it will convert all files in the current directory from a file extension of .htm to .html.

If the output of the above test run looked ok then you could run the final version:

rename -v ’s/\.htm$/\.html/’ *.htm

The -v is optional, but it’s a good idea to include it because it is the only record you will have of changes that were made by the rename command as shown in the sample output below:

$ rename -v 's/\.htm$/\.html/' *.htm
 3.htm renamed as 3.html
 4.htm renamed as 4.html
 5.htm renamed as 5.html

The tricky part in the middle is a Perl substitution with regular expressions, highlighted below:

rename -v ’s/\.htm$/\.html/’ *.htm

Tip: There is an intro to Perl regular expressions here.

Basically the « s » means substitute. The syntax is s/old/new/ — substitute the old with the new.

A . (period) has a special meaning in a regular expression — it means « match any character ». We don’t want to match any character in the example above. It should match only a period. The backslash is a way to « escape » the regular expression meaning of « any character » and just read it as a normal period.

The $ means the end of the string. \.htm$ means that it will match .htm but not .html.

It’s fairly basic — substitute .htm with .html:


The last part of the command, highlighted below, means to apply the rename command to every file that ends with .htm (the * is a wildcard).

rename -v ’s/\.htm$/\.html/’ *.htm

Other Examples

Maybe you have a digital camera that takes photos with filenames something like 00001234.JPG, 00001235.JPG, 00001236.JPG. You could make the .JPG extension lowercase with the following command executed from the same directory as the images:

rename -v 's/\.JPG$/\.jpg/' *.JPG

Here is the output of the above command:

$ rename -v 's/\.JPG$/\.jpg/' *.JPG
 00001111.JPG renamed as 00001111.jpg
 00001112.JPG renamed as 00001112.jpg
 00001113.JPG renamed as 00001113.jpg

That is simple enough, as it is similar to the .html example earlier. You could also bulk rename them with something descriptive at the beginning like this:

Tip: Before trying more complicated renaming like in the example below, do a test run with the -n option as described at the beginning of this tutorial.

rename -v 's/(\d{8})\.JPG$/BeachPics_$1\.jpg/' *.JPG

That will change filenames that have the pattern ########.JPG (8 numbers and capital .JPG) to something like BeachPics_########.jpg (the same 8 numbers and changing the extension to lowercase .jpg). Here is a test run with the -n option:

$ rename -n 's/(\d{8})\.JPG$/BeachPics_$1\.jpg/' *.JPG
 00001111.JPG renamed as BeachPics_00001111.jpg
 00001112.JPG renamed as BeachPics_00001112.jpg
 00001113.JPG renamed as BeachPics_00001113.jpg

Here’s a quick breakdown of the Perl substitution with the regular expression above.

The highlighted section below means to count 8 digits. The parentheses mean to save those 8 digits for later because they are going to be used again in the second half of the substitution:


In the highlighted section below, it adds the string BeachPics, and underscore, and then the text in parentheses from the first half of the substitution. $1 will insert the string from the first set of parentheses that it finds — in this case the 8 digits. If you have more than one set of parentheses you can access the second set with the Perl variable $2 and so on.


Final Refinement

The following variation would make even cleaner-looking filenames. See if you can figure out how it works:

$ rename -n 's/\d{5}(\d{3})\.JPG$/BeachPics_$1\.jpg/' *.JPG
 00000123.JPG renamed as BeachPics_123.jpg
 00000124.JPG renamed as BeachPics_124.jpg
 00000125.JPG renamed as BeachPics_125.jpg

Learning Perl Regular Expressions

You can learn more about Perl regex here and in the Perl regular expression documentation, and the quickstart. Also check out this regex cheatsheet. You can learn more about the rename command by typing man rename in the terminal.
Adding the Rename Command to Non-Debian Distros

The following information was provided by Dan Fego on how to add the Perl-based rename command to non-Debian Linux distros:
I did the following [on Gentoo], though I’m aware there’s both more concise and generic ways to do it. This was just my path of discovery.

[the following commands are from Ubuntu]
# which rename
 # ls -l /usr/bin/rename
 lrwxrwxrwx 1 root root 24 Dec 2 02:13 /usr/bin/rename ->
 # ls -l /etc/alternatives/rename
 lrwxrwxrwx 1 root root 16 Dec 6 00:29 /etc/alternatives/rename ->
 # ls -l /usr/bin/prename
 -rwxr-xr-x 1 root root 2987 Dec 4 04:18 /usr/bin/prename

Once I had the final link in the chain [on Ubuntu], I knew which file to copy [to Gentoo], though really I didn’t need to follow it all that way. The reason I did to begin with was because I tried to copy it with the filesystem mounted, and it referred to absolute paths which didn’t exist outside of the Ubuntu environment. The prename script is fully self-contained, assuming you’ve got Perl on your system (which just about any self-respecting Linux distro does).

The code from Ubuntu’s rename/prename is here (Gutsy Gibbon).

Categories: Système Tags: ,

Best way to backup all settings, list of installed packages, tweaks, etc?

28/10/2018 Comments off



A quick way of backing up a list of programs is to run this:

dpkg --get-selections > ~/Package.list
sudo cp /etc/apt/sources.list ~/sources.list
sudo apt-key exportall > ~/Repo.keys


It will back them up in a format that dpkg can read for after your reinstall, like this:

sudo apt-key add ~/Repo.keys
sudo cp ~/sources.list /etc/apt/sources.list 
sudo apt-get update
sudo apt-get install dselect
sudo dpkg --set-selections < ~/Package.list
sudo apt-get dselect-upgrade -y


Settings and Personal Data


Before you reinstall, you should probably back up the settings from some of your programs, this can easily be done by grabbing folders from /etc and all the content from your user directory (not just the stuff you can see in nautilus!):

rsync --progress /home/`whoami` /path/to/user/profile/backup/here


After you reinstall, you can restore it with:

rsync --progress /path/to/user/profile/backup/here /home/`whoami`


So all together as a pseudo-bash script.


This assumes there is only one user on the machine (remove /'whoami' otherwise) and that you used the same username on both installs (modify dest. of rsync otherwise).

dpkg --get-selections > ~/Package.list
sudo cp /etc/apt/sources.list ~/sources.list
sudo apt-key exportall > ~/Repo.keys
rsync --progress /home/`whoami` /path/to/user/profile/backup/here

##  Reinstall now

rsync --progress /path/to/user/profile/backup/here /home/`whoami`
sudo apt-key add ~/Repo.keys
sudo cp ~/sources.list /etc/apt/sources.list 
sudo apt-get update
sudo apt-get install dselect
sudo dpkg --set-selections < ~/Package.list
sudo dselect