Crea sito

Archivio per la categoria script

How to count the files inside a directory and the subdirectories

Count the files Here there is the problem: given a directory, we need to get the number of the files (not directory) inside this directory (and the subdirectory). Plus, we need to count the numbers of the files for each subdirectory, in the same way. For example, if we have a directory like this: directory1: […]

How to nat a PC with an other PC

Here is the situation: you have 2 (or more) PCs with Linux system. One PC has at least 2 network interface and with one on them it is connected on Internet. The second PC instead has no access to the internet. If you want that also the second PC gets a connection, you can use […]

How to limit the CPU usage of a process: cpulimit

How to limit the CPU usage of a certain process of a Unix System: cpulimit. cpulimit is a program that attempts to limit the cpu usage of a process. This limit is a percentage of real cpu usage and not a cpu time. cpulimit is also able to adapt itself to the overall system load, dynamically and quickly. How […]


How to extract audio (mp3) from a video (flv or mp4)

If you have a mp4 or flv video (for example a video that you downloaded from youtube) and you want to get only the audio (mp3), here there is a simple solution. Before you start, you have to install on your Linux system ffmpeg and lame Here there is the command list: ffmpeg -i video.mp4 […]

How to delete or substitute a newline using sed

How can you delete or substitute a newline using sed? Unix shell command to delete all newlines from a file using sed:  sed ‘:a;N;$!ba;s/\n//g’   input_file   Unix shell command to substitute all newlines from a file with an other string using sed:  sed ‘:a;N;$!ba;s/\n/new_string/g’   input_file   Example: substitute all newlines with the string […]

How to display only a section of a file

To display a file the most common unix command is probably cat. But with cat you can display all the file, not only a part of it. To get section of a file you can use the commands tail and head. tail -n +start_line input_file | head -number_of_line where start_line is the number of the […]

How to use a string as input of awk

How can you use a string as input of awk? Usually awk takes as input the path of the file that you want to process. Here there is a very simple solution to give to process a string with awk without the necessity of store that string into a file: echo “string that you want to […]

Tags: , , ,