Useful commands
Find process, which listens for 12345 port:
lsof -i tcp:12345
Generate password (16 symbols in length):
tr -dc A-Za-z0-9_ < /dev/urandom | head -c 16 | xargs
Find files changed during past two days (start from the current directory):
find . -mtime -2 -ls
Show: user, process, parent process, threads count, command:
ps axo user,pid,ppid,nlwp,cmd
User max processes amount:
ulimit -u
Find a process using ps, grep and awk commands, and kill it:
kill -9 `ps aux | grep java | grep -v grep | awk '{print($2)}'`
Show: system information
uname -a
Show: CPU information
cat /proc/cpuinfo
Show: Operating System information
cat /etc/os-release
Show: Operating System information (v.2)
ls -1 /etc/*release*
cat /etc/*release*
Show: video card information
/sbin/lspci -v -s `/sbin/lspci | awk '/VGA/{print $1}'`
Check if 8080 port is active:
netstat -na | grep 8080
Colored output:
echo -e '\E[30m black \E[31mred \E[32mgreen \E[33myellow \E[34mblue \E[35mmagenta \E[36mcyan \E[37mwhite'
echo -e '\E[30;41mblack on red\E[30;40m'
echo -e '\E[40m black \E[41mred \E[42mgreen \E[43myellow \E[44mblue \E[45mmagenta \E[46mcyan \E[47mwhite\E[40m'
Change prompt format:
$ PS1='\t \u@\h:\w> '
22:48:25 user@server:~> PS1='Type in command: '
Type in command: echo WOW
WOW
Type in command:
Split files into parts of 10000000 bytes:
split -b 10000000 files.zip files
Join previously splitted files:
cat files* > files.zip
Remove carriage return (^M) characters:
dos2unix windows.file.sh
Run in background without output:
./a.sh > /dev/null 2>&1 &
Display user last login:
last usrname