📜 ⬆️ ⬇️

* nix-way: Even if you have been eaten, you have at least two ways out.

In the process of working with GNU / Linux operating systems, you usually get used to doing some operations with the same means. The UNIX philosophy (* nix-way) implies the existence of a large number of simple programs for performing simple actions, and the results of the work can be transferred between different programs through streams. But now imagine that a situation arises when someone unintentionally, by stupidity or from bad motives, deleted an executable file, which was a binary file of some command that you more or less often used. And then what to do?

And this is where the fun begins. Practice shows that many things can be done in more than one way. I tried to make a small list of interchangeable actions that in Linux can be performed in more than one way.


')
1) Line numbering
nl <file> 
=
 cat -n <file> 


2) Viewing the route table
 route -e 
=
 netstat -r 
=
 ip route 


3) View the list of network interfaces
 ifconfig -s 
=
 netstat -i 
=
 ip addr 


4) User creation:
 adduser <username> 
=
 useradd <username>; mkdir /home/<username>; chown <username>:<username> /home/<username>; passwd <username> 


5) Lock user password
 passwd -l <username> 
=
 usermod -L <username> 


6) Unlock user password
 passwd -u <username> 
=
 usermod -U <username> 


7) Adding a user to a group
 adduser <username> <groupname> 
=
 usermod -aG <groupname> <username> 


8) Change the file ownership group
 chown :<groupname> <filename> 
=
 chgrp <groupname> <filename> 


9) View the contents of the directory
 ls 
=
 dir 
=
 vdir 


10) Creating a hard link
 ln <file> <linkname> 
=
 cp -l <file> <linkname> 


11) Creating a symbolic link
 ln -s <file> <linkname> 
=
 cp -s <file> <linkname> 


12) Replacing traceroute with the ping command. Not quite an honest way, because different types of ICMP packets, but generally suitable if all hosts of the route are pinged.
 traceroute remote-host 
=
pingtrace.sh (If you specify an IP address as an argument, the route is VERY fast)
 #!/bin/bash REMOTE_HOST=$1 REMOTE_HOST_2=`host $1 | grep 'has address' | awk '{printf $4}'` TARGET_HOST="_" TARGET_TTL=1 echo Tracing host $REMOTE_HOST\($REMOTE_HOST_2\) while [ "$REMOTE_HOST" != "$TARGET_HOST" -a "$REMOTE_HOST_2" != "$TARGET_HOST" ] do TARGET_HOST=`ping -c 1 -t $TARGET_TTL $REMOTE_HOST | grep 'exceeded' | awk '{printf $2}'` if [ "$TARGET_HOST" != "" ] then echo $TARGET_HOST, TTL=$TARGET_TTL TARGET_TTL=$(($TARGET_TTL+1)) else echo $REMOTE_HOST, TTL=$TARGET_TTL exit fi done 


In the comments, I hope there will be many more such examples.

Source: https://habr.com/ru/post/145073/


All Articles