Linux commands
OS Version
uname -srm
cat /proc/version
hostnamectl
Make archive
tar cvf - /etc /home | gzip > test.tar.gz
Extract archive
gunzip < test.tar.gz | tar xvf -
Convert file's encoding
iconv -f UTF-8 -t CP1252 <in_file> > <out_file>
Linux Performance Monitoring
vmstat
iostat
Information about the Linux networking
netstat -a -n
Monitor processes
top
Use [] in grep to find a process and not include the grep command itself when you pipe ps -ef output to grep
ps -ef | grep inet[d]
Use the IFS shell variable to split a line into fields:
grep root /etc/passwd | IFS=: read user x1 uid gid x2 home shell
print $uid $home
To send all output (stdout and stderr) generated by a command to the same file use
command >file 2>&1
To send all output (stdout and stderr) generated by a command to a file and to the terminal (stdout) use
command 2>&1 | tee file
String Substitution Operators
${varname:-value}
Return value of varname if it exists and it is not null; otherwise return value.
${varname:=value}
Return value of varname if it exists and it is not null; otherwise set varname to value and return value.
${varname:?message}
Return value of varname if it exists and it is not null; otherwise print varname: message and abort current command or script. Default message is parameter null or not set.
${varname:+value}
Return value, if varname exists and it is not null; otherwise return null.
Pattern-matching Operators
${varname#pattern}
If pattern matches the beginning of varname's value, delete the shortest part that matches and return the rest.
${varname##pattern}
If pattern matches the beginning of varname's value, delete the longest part that matches and return the rest.
${varname%pattern}
If pattern matches the end of varname's value, delete the shortest part that matches and return the rest.
${varname%%pattern}
If pattern matches the end of varname's value, delete the longest part that matches and return the rest.
expr command
expr index string string2
to display the numerical position in string
of first character in string2
that matches.
expr substr string position length
extracts length
characters of substring from string
starting at position
.