Linux Commands

1) **find . -name 'core' | xargs rm** -searches files with core in name in current directory and removes them

2) **find . -name 'core' -exec rm {} \;** - searches files with core in name in current directory and removes them

3) **tar czf - $PWD | ( cd folder; tar -xvf - )** - archive current working directory brings files from standard output and goes to some folder and unpacks files from standard input

4) **userdel -r project3** - removes user from system with his home directory

5) **rpm -qa** - lists all packages installed in system

6) **rpm -qi bash-4\* -** lists all bash packages with system

7) **rpm -ql bash -** list all files in bash package

8**) rpm -qc bash -** list configuration files of bash packages

9) **rpm -q --whatrequires bash** - determines what other packages on system depend on the Bash packages

10)**rpm - ivh \*.rpm** - installing

11) **rpm -e name\_of\_package - removes package** | additionaly when some package depends from that rpm -e --nodeps -e name\_of\_package

12) **yum search headers** - searching package with "headers" in the name

13) **yum/dnf whatprovides libmprf.so.4** - looking from package with this file

14) **dpkg -l** - all current installed software in debian| ubuntu

15) **Compiling package**

* .**/configure** -help - By default each component will install into the appropriate directory in /usr/local , option **--prefix=/home/<USERNAME/local/** gives us option to prevent this behaviour. Sometimes , there is autogen.sh file
* **make**
* **make install**

16) **Editing libriaries** ( standard location is /usr/lib, /usr/lib64, /usr/local/bin/)

-editing /etc/ld.so.conf or create custom configuiration files in /etc/ld.so.conf.d/, or use LD\_LIBRARY\_PATH

17) **Useradd [options] LOGIN**

-d changing home directory

-e YYYY-MM-DD

-G Groups

18) **usermod -L login** -locks account

**usermod -U login** -unlock account

**usermod -e login** -expiration date

19) **SUID, GUID-** allows a program to be run with permission from the program owner or group

owner -4 - chmod 4755 /bin/ls or chmod u+s /bin/ls

group 2 - chmod 2755 /bin/ls or chmod g+s /bin/ls

20) **Sticky bit** - special permission that can be used to prevent users from deleting other user files or directories.

chmod +t /tmp/specialfolder

21) **usermod login -a -G wheel** - adding user login to the wheel group and thus grant sudo rights

22) **tcpdump -w /tmp/trace.pcap -i eth0** - writing packet capture to disk from eth0

23) **tcpdump "not (tcp port 22 and host 192.168.1.1)" -** skipping port 22 and host 192.168.1.1

24) **nmcli c s | d s** - connection show, device show

25) **ipconfig dev ip netmask nmask broadcast bcast or ip a add ip/CIDR dev eth1**

26) ip -6 a add 2001:DB8::1/64 dev eth

27) auto eth0

iface eth0 inet static

address 192.168.1.45

netmask 255.255.255.0

gateway 192.168.1.1

28) **ip route add default via 192.168.1.1 dev -- adding default route**

29) /etc/fstab - remounting remote file systems, **options : \_netdev**

30) NFS --firewall in centos 7, if something go wrong: check if you have open port for mountd, rpcbind and nfs, or do showmount -e

31) groupadd webwork , chmod g+rws /var/www/html, chown :webwork /var/www/html, useradd -aG webwork user

32) sed -i -e '26d' ~/.ssh/known\_hosts - removing 26 line from that file

33) Linux shorcuts :

* **ctrl + a**- go to the beginning of the line
* **crtl + e**- go to the end of the line
* **crtl + k**-  removes everything after the postion of the cursor
* **crtl + u** - removes everything back the position of the cursor
* **crtl + l** - clears the screen
* **crtl + w** - removes last word
* **crlt + b** - go back one digit
* **crtl + f** - go forward one digit
* **crtl + d** - removes one digit
* **crtl + p** - last command

34) **cut -f1 -d : /etc/passwd** - field 1 from that file , delimiter is colon

35) **sed 's/fulltime/partime/ file** - changes fulltime to partime

36) **sed '0,/partime/s/partime/promotion/' team** - first occurrence of partime , change for promotion

37)test commands -

* test **-f** test - checking if file test is existing
* test **-w** test - checking is file is writable
* test 1 -**gt** 2 - checking if 1 is greather than
* test 1 **-lt** 2   - checking if
* test 1 -**eq** 1 && echo "this is true" || echo "this is false"

38)  for loop

* **for name in `ls`; do echo $name; done ;**

​39) **RSYNC**

* rsync -r dir1/ dir2 - regular files and directories content of dir1 to dir2
* rsync -ar dir1/ dir2 - all files
* rsync -anv dir1/ 192.168.4.220:/home/user/bkup1
* if dir1 has been remove myfile9 and after normal rsync to dir2 myfile9 still exist we have to rsync -av --delete dir1/ 192.168.4.220:/home/user/bkup2 which removes also file on remote machine.
* --exclude='example.tar'
* --include=`myfiles\*'.tar
* --maxsize=`200m` -- max size 200M

 --exclude-from 'exclude.txt'

**40) ALTERNATIVES**

1. alternatives --install /usr/bin/java java /opt/java/bin/java 200000
2. if we install java from rpm or deb alternatives --config java and we switch version
3. to check we need to java -version or ls -al /etc/alternatives/java\*