Skip to content

www.leonenkov.ru

Comprehensive notes of a lifelong learner

  • Home
  • Author

short

Find all files which contain specific text and print these file names to the console

20.12.202322.05.2024 ~ Roman
If a file contains either word “some” or word “text” then print its name
1
2
3
# q = quiet; that means that grep will exit with status "0" (success)
# if a file contains either word "some" or word "text"
find . -type f -exec bash -c "grep -q -e some -e text {} && echo {}" \;

Restore UNIX acess permissions for all subfolders and files of the specified directory

27.01.202122.05.2024 ~ Roman
1
2
3
4
# Reset access rights to 'rwxr-xr-x' for all subfolders of the specified directory
find /home/username/public -type d -exec chmod 0755 {} \;
# Reset access rights to 'rw-r--r--' for all files of the specified directory
find /home/username/public -type f -exec chmod 0644 {} \;

Be aware – this site doesn’t use cookies!

27.01.202122.05.2024 ~ Roman
funny

The image was taken from here.

How to compare two folders in UNIX using diff

24.01.202122.05.2024 ~ Roman
1
2
# If it's required to compare two folders by their files names
$ diff <(cd folder1 && find | sort) <(cd folder2 && find | sort)
1
2
# ... or if you want deep comparison
$ diff --brief -rb folder1 folder2

Swapping 2 JS variables’ values in one line

24.01.202122.05.2024 ~ Roman
1
2
3
let a = 10, b = 20;
[a, b] = [b, a];
console.log(a, b); // => 20, 10

His favorite language…

18.01.202122.05.2024 ~ Roman

The hilarious image above was taken from this post on reddit. I just couldn’t hold myself from copying it here.