Linux Tricks

41) how to fetch only the numbers in grep from file?

#grep -Eo ‘[0-9]{1,9}’ <file name>

[gaurav@server1 ~]$cat file1
Z      603   300 java <defunct>
Z     5473   304 java <defunct>
Z      603   308 java <defunct>
[gaurav@server1 ~]$grep -Eo '[0-9]{1,9}' file1
603
300
5473
304
603
308
[gaurav@server1 ~]#

42) Print the last word of each line in Linux using “awk” command?

#awk ‘{print $NF}’ <file name>

[gaurav@server1 ~]$ cat testfile1
12345 567 7878 66
er3   t45t y6y46y
4y6 y656y y5yefsr
46y6 65y7 y66uyuy
yy46y6y jgfdsbfj uw6753
[gaurav@server1 ~]$ awk '{print $NF}' testfile1
66
y6y46y
y5yefsr
y66uyuy
uw6753
[gaurav@server1 ~]$

43) how to take backup of a single table in the mysql database?

#mysqldump -u <username> -p <password> <Database name> <tablename>  > <Dump location>

Example:

[root@server1 ~]# mysqldump -u -p  openfire  ofVCard >  /root/bavkupofvCard.sql

44) Remove the blank space of the file on Linux?

# sed ‘s/\s//g’ <filename> | tr -d ‘\n’

[gaurav@server1 ~]$ cat testfile1
12345 567 7878 66
er3   t45t y6y46y
4y6 y656y y5yefsr
46y6 65y7 y66uyuy
yy46y6y jgfdsbfj uw6753
[root@pidgin ~]$ sed 's/\s//g' testfile1 | tr -d '\n'
12345567787866er3t45ty6y46y4y6y656yy5yefsr46y665y7y66uyuyyy46y6yjgfdsbfjuw6753

or

#grep -v -e ‘^$’ <filename>

45) Remove all content of the file on Linux?

#:> <filename>

[gaurav@server1 ~]$ cat testfile1
12345 567 7878 66
er3   t45t y6y46y
4y6 y656y y5yefsr
46y6 65y7 y66uyuy
yy46y6y jgfdsbfj uw6753
[gaurav@server1 ~]$ :> testfile1
[gaurav@server1 ~]$ cat testfile1
[gaurav@server1 ~]$

 

46) how to change splash screen ubuntu.

Step1:Go to /etc/default directory.

Step2:sudo nano grub

Step3:Change these parameter on that file:

GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=true
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=”splash”
GRUB_CMDLINE_LINUX=””

Step4:Copy the image to /boot/grub/ dir.

cp -v image.jpg ~/boot/grub/

Step5:sudo update-grub

47) Run a Linux command after every reboot.

#crontab -e
 @reboot /home/gaurav/Oraclelistener.sh
~
~
:wq

48) Comment out hashes in large configuration files.

#cat <filename>| egrep -v ^#

[root@server1 ~]# cat /etc/vsftpd/vsftpd.conf | egrep -v ^#
anonymous_enable=NO
local_enable=NO
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=NO
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES

49) Linux Trick with “cat” command. 

#cat > testfile1.txt

[gaurav@client1 ~]$ cat > testfile1.txt
Linux is the future.Linux was originally developed as a
free operating system for personal computers based on the Intel x86 architecture
[gaurav@client1 ~]$ cat  testfile1.txt
Linux is the future.Linux was originally developed as a
free operating system for personal computers based on the Intel x86 architecture
[hcladmin@pidgin ~]$

Note: CTRL + d to exit.

50) Open Vim and jump to end of file.

#vim + <filename>

[gaurav@client1 ~]$vim + testfile1.txt