Linux Tips and Tricks
@reboot /home/xyz/myscript.sh
Do remember to enable crond on boot.
Here is a command that will let you know about the available shells on your Linux distribution:
#chsh -l
To change your login shell, use the following command:
# chsh
lsusb – Lists all USB devices. Use -v for verbose output.
lsmod – Lists the status of modules in the Linux kernel.
lsattr – Lists file attributes on a second extended Linux file system.
lsof – Lists the file descriptors opened by all the processes. A very useful command when a process fails to close any file descriptors.
ls -lSr Show files by size, biggest last
pushd . Put current dir on stack so you can popd back to it
1. To view the content of a tar file, issue the following command:
#tar -tvf /path/to/file.tar
2. To view the content of an rpm file, use the command given below:
#rpm -qlp /path/to/file.rpm
$ uname -a
Kernel version and system architecture
Built in variables:
$1-$N Stores the arguments (variables) that were passed to the shell program from the command line.
$? Stores the exit value of the last command that was executed.
$0 Stores the first word of the entered command (the name of the shell program).
$* Stores all the arguments that were entered on the command line ($1 $2 ...).
"$@" Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...).
UDPnmap -sU -O
As all of us know, if you make changes in a file using VIM editor, the changes are permanent and you cannot get the old version back after you save and quit the editor.
But VIM v7.3 allows you to get the old version back even after quitting the editor.
Here is a tip that shows you how to configure VIM to remember changes.
To enable Undo, execute the following commands in VIM just before starting to edit the file.
:set undofile
:set undodir=/tmp
This is to be done every time you start editing a file. In case you need the configuration to be there for all files that you open in VIM, create a file called '.exrc' or '.vimrc' in $HOME directory. In my case, it is /myhome.
Open the just created file and add the following commands:
# vi /myhome/.exrc
set undofile
set undodir=/tmp
Save and close the file.
:wq
From now onwards, the Undo history is maintained in the background for all files that you edit with VIM.
Iperf is a tool that measures the bandwidth and the quality of a network link. It can be installed very easily on any Linux system. One host must be set as the client and the other one as the server. Make sure that iperf is installed on both systems. If it is not installed, then use your package manager to install it before trying this tip.
Now run iperf on one of the Linux systems as the server, as shown below:
linux-erv3:/home/test/Desktop # iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
Go to the second Linux system and run iperf -c as the client:
linux-6bg3:~ # iperf -c 192.168.1.100
------------------------------------------------------------
Client connecting to 192.168.1.100, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------
[ 3] local 192.168.1.109 port 39572 connected with 192.168.1.100 port 5001
^C[ ID] Interval Transfer Bandwidth
[ 3] 0.0- 6.3 sec 6.38 MBytes 8.51 Mbits/sec
By default, the iperf client connects to the iperf server on the TCP port 5001 and the bandwidth displayed by iperf is the bandwidth from the client to the server. In the above example, it is 8.51 Mbits/sec between two Linux test systems connected over a wireless network.
netstat -i
To display the kernel routing table:
netstat -rn
To display all open network sockets:
netstat -uta
To display network statistics:
netstat -s
BASH Script
Convert images to ascii art
$ asciiview Tux.png -driver curses
To download a web page(s):
#wget -m -r -l5
Show information about mounted volumes:
#df -h
Networking
ethtool eth0 Show status of ethernet interface eth0
ethtool --change eth0 autoneg off speed 100 duplex full Manually set ethernet interface speed
iw dev wlan0 link Show link status of wireless interface wlan0
iw dev wlan0 set bitrates legacy-2.4 1 Manually set wireless interface speed
• iw dev wlan0 scan List wireless networks in range
• ip link show List network interfaces
ip link set dev eth0 name wan Rename interface eth0 to wan
ip link set dev eth0 up Bring interface eth0 up (or down)
• ip addr show List addresses for interfaces
ip addr add 1.2.3.4/24 brd + dev eth0 Add (or del) ip and mask (255.255.255.0)
• ip route show List routing table
ip route add default via 1.2.3.254 Set default gateway to 1.2.3.254
• ss -tupl List internet services on a system
• ss -tup List active connections to/from system
• host pixelbeat.org Lookup DNS ip address for name or vice versa
• hostname -i Lookup local ip address (equivalent to host `hostname`)
• whois pixelbeat.org Lookup whois info for hostname or ip address
Text Manipulation
sed 's/string1/string2/g' Replace string1 with string2
sed 's/\(.*\)1/\12/g' Modify anystring1 to anystring2
sed '/^ *#/d; /^ *$/d' Remove comments and blank lines
sed ':a; /\\$/N; s/\\\n//; ta' Concatenate lines with trailing \
sed 's/[ \t]*$//' Remove trailing spaces from lines
sed 's/\([`"$\]\)/\\\1/g' Escape shell metacharacters active within double quotes
• seq 10 | sed "s/^/ /; s/ *\(.\{7,\}\)/\1/" Right align numbers
• seq 10 | sed p | paste - - Duplicate a column
sed -n '1000{p;q}' Print 1000th line
sed -n '10,20p;20q' Print lines 10 to 20
sed -n 's/.*
sed -i 42d ~/.ssh/known_hosts Delete a particular line
sort -t. -k1,1n -k2,2n -k3,3n -k4,4n Sort IPV4 ip addresses
• echo 'Test' | tr '[:lower:]' '[:upper:]' Case conversion
• tr -dc '[:print:]' < /dev/urandom Filter non printable characters
• tr -s '[:blank:]' '\t'
• history | wc -l Count lines
• seq 10 | paste -s -d ' '
Debugging
• strace -c ls >/dev/null Summarise/profile system calls made by command
• strace -f -e open ls >/dev/null List system calls made by command
• strace -f -e trace=write -e write=1,2 ls >/dev/null Monitor what's written to stdout and stderr
• ltrace -f -e getenv ls >/dev/null List library calls made by command
• tcpdump not port 22 Show network traffic except ssh. See also tcpdump_not_me
Ref:
http://www.cheat-sheets.org/saved-copy/ubunturef.pdf
http://www.cheat-sheets.org/saved-copy/unix_command_quickref.pdf
http://www.pixelbeat.org/cmdline.html
http://jd40c.com/linux.html
* Delete line above current line at VIM : dgg
* Delete line above at VIM : jdG
3 comments:
https://github.com/rkgade/the-art-of-command-line
https://github.com/alebcay/awesome-shell
http://redsymbol.net/articles/unofficial-bash-strict-mode/
https://github.com/agarrharr/awesome-cli-apps
https://github.com/Idnan/bash-guide
https://www.thegeekstuff.com/2010/12/50-unix-linux-sysadmin-tutorials/
http://linux4beginners.info/
Post a Comment