Linux

Last updated: March 21th, 2020

Bash

How to create 100% CPU load in linux?

1. Find out how many processors your CPU has

$ sudo cat /proc/cpuinfo

2. Note the line with the text processer:. If the number is 0 this means you have only one proc. If the number is 1 this means you have 2 procs, etc.

3. Start the following command the number of processers you have

$ sudo yes > /dev/null &

4. Control the CPU on your system using the command

$ top

5. Remove all processes that make your computer have CPU 100%

$ sudo killall yes

How to list only directories linux?

$ ls -d */
$ ls -d /home/user/Documents/*/

Awk

How to print the first two columns of a csv text file separated with comma?

$ awk -F',' '{print $1" "$2}' file

Sed

How to replace all occurances of a text pattern in a text file?

This works on centos and co

$ sed -i 's/old/new/g' file

On FreeBSD/macOS and co the flag -i does not work. On macOS you can install gnu-sed

$ brew install gnu-sed

and then use gsed

$ gsed -i 's/old/new/g' file