Linux Notes
From Logic Wiki
Command line
cd - : go back to previous directory
cd ~ : go back to home directory
CTRL + L : clear screen but scroll history remains
reset : clear screen and scroll history
CTRL + R : search in command history by providing partial command
history : lists the command history. -> !102 : runs the command in line 102
HISTTTIMEFORMAT="%Y-%m-%d %T " : history will come with date time after this
Combining commands
sudo find /var/log/syslog*.gz -print0 | xargs -0 sudo gunzip
- sudo's are to overcome rights
- find all syslog zip files
- -print0 is to format output (like prepare for combined command)
- | to combine
- xargs -0 to catch formatted output of the first command
- unzip them
find /var/log/syslog* -type f -print0 | xargs -0 cat | grep -c "NetworkManager.*warn"
ifconfig
this is like ipconfig but lots of other info is there
ifconfig | grep "inet addr"
it only lists the lines starting with "inet addr"
ifconfig | grep "inet addr" | head -n 1
it's like top 1 in sql select
ifconfig | grep "inet addr" | head -n 1 | cut -d ":" -f 2
now we cut the line into two parts from ":" and take the second part
ifconfig | grep "inet addr" | head -n 1 | cut -d ":" -f 2 | cut -d " " -f 1
now we cut the line into two parts again from " " and take the first part to get ip address