Mounting Point/Logical Volume/Physical Partition/Physical Volume
realpathgpasswdinitsystemd : provides a system and service manager that runs as PID 1 and starts the rest of the systemUpstart : an event-based replacement for the /sbin/init daemoninetdxinetd : a secure replacement for inetdinit
/sbin/init Program of CentOS 5/etc/init.d Directory (April 4, 2009)
/etc/init.d/command start|stop|reload|restartsystemd
proc File System/proc/meminfo and free output for Red Hat Enterprise Linux 5, 6 and 7(May 27 2016)bash -c 'ls -l'source ~/.bashrc, . ~/.bashrc, source ~/.profilereturn instead of exit`echo $CODE` | base64`-f file, -d file, -eq, -ne,…)$*, $@, $#, $?, $-, $$, $0, $!, $_${parameter:-word}, ${parameter:=word}, ${parameter:?word}, ${parameter:+word}, ${parameter##word}, ${parameter%%word}, …$(( expression ))!!, !-1, !!:$go version | grep -oE 'go[1-9]\.[1-9]'go version | sed 's/.*go$[1-9]\.[1-9][0-9]*$.*/\1/'<< EOMcommand > /dev/null 2>&1echo " abc" | { read str; echo ${str## }; } #remove leading spacescat << HERE > config.json ...if [ -d /var/lib/httpd ], if [ ! -d /var/lib/httpd ], if [ -d /var/lib/httpd -a -d /var/log/httpd ]ssh or xhost/sbin/init Program
/etc/rc.d/rc.localjournalctl.desktop file (Feb 11 ‘14)/etc/environment, /etc/profile.d/*.sh~/.profileapt-get
apt-cacheapt-file : searching files in packages for the APT package management system.apt
tcp
/proc/sys/net/ipv4/Command |
Description |
Readings |
|---|---|---|
|
find files |
|
|
return user identity |
|
|
read and execute ex commands from file |
|
|
evaluates commands in a computer file in the current execution context |
|
|
allows users to run programs with the security privileges of another user (normally the superuser, or root) |
|
|
word, line, and byte or character count |
|
|
search a file for a pattern |
|
|
reads standard input and writes it to both standard output and one or more files, effectively duplicating its input. |
|
|
command line tool and library for transferring data with URLs |
|
|
non-interactive download of files from the Web |
curl vs wgetsusu -s /bin/bash nobody '-c echo Hi' for account with /sbin/nologinsudoteecurlcurl with heredoccurl -s -o /dev/null -w '%{http_code}' http://www.google.com/sedsed Manual
sed# sed -i 's/\r$//g' filenameawkdpkg -l | awk '{print $2}'readread Man Pageread</read> builtin command](http://wiki.bash-hackers.org/commands/builtin/read)useradduseradd Man Page| Command | Description | Misc |
|---|---|---|
top |
||
netstat |
||
lsof |
displays information about files open to Unix processes | |
strace |
||
tcpdump |
||
sysctl |
a tool for examining and changing kernel parameters at runtime |
toplsoflsof homepage
lsof on Wikipedialsof in Ubuntustracesysctlnetstattcpdumptcpdump homepage : a powerful command-line packet analyzertcpdump on Wikipediatcpudmp -n -s0 -A -i eth0 dst port 80tcpdump -n -i eth0 -A -x dst port 443 and greater 100pcap-filter man page : explains filter expressionsiperfiperf3arp, ifconfig, iptunnel, iwconfig, nameif, netstat, route -> traceroutetraceroute man pageiptablesiptables on Wikipedia
conntrackPAC ManagerwatchscreenFor Linux, /etc/issues file contains more detailed information on what Linux product it is.
$ cat /etc/issue
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Kernel \r on an \m
$ sysctl -a | more
$ cat /proc/meminfo
MemTotal: 3922904 kB
MemFree: 3037280 kB
...
$ df
...
You can identify TCP/IP ports currently in use using netstat command. The options of netstat is slightly different among operating systems.
For UNIX,
$ netstat -na
For Linux,
$ netstat -nap
You need root privilege to take effect of -p option To find out whether a given port is being used or not, use grep command.
$ netstat -nap | grep -E '(^Proto)|(8080)'
For Windows,
$ netstat -nao
For more about netstat, refer topics in Wikipedia.
To identify what shell a user is set to use by default, you can check SHELL variable.
$ echo $SHELL
/bin/bash
$ bin/ksh
$ echo $SHELL
/bin/bash
As the above example shows, SHELL variable contains the login default shell type not the one currently in use.
To hide both the normal output and error output, redirect stdout and stderr to null device
% npm ls -g json >/dev/null 2>&1
% #or
# npm ls -g y18n &>/dev/null
To hide only the error output, redirect stderr to null device
% npm ls -g json 2>/dev/null
find command excluding files with 'Permission denied'When executing find command in simplest format, you may get lots of lines just saying that 'Permission denied'. Most cases, those are not what you want, and lots of permission denied lines can disturb you identifying the wanted result.
You can use stderr redirection to cut out permission denied files (or directories).
% find / -name '*.jar' 2>/dev/null
If you want to find files with extension of ‘jar’ and print them with full path, use find command with -exec operator like the following.
% find . -name '*.jar' -exec ls -l {} \;
For more about find command and -exec operator including strange ‘{}’ or ‘\;’ in the above example, refer the followings.
% find /home |xargs grep "password"
For more about xargs, refer the followings.
To find large files(not directories) under current directory and list them in pages, use the following command.
% find . -type f -exec du -k {} 2>/dev/null \; | sort -nr | more
To filter out small files, you can use size option with find command, or to filter out some subdirectories you can redirect the result to grep command. The following command will list files whose size are more than 1 mega-byte under current directory recursively except the subdirectories starting with ‘svn’ in order of their size.
% find . -type f -size +1000000c -exec du -k {} 2>/dev/null \; | sort -nr | grep -E "\./svn.*" -v
Using find command
% find /proc/sys -type f 2>/dev/null | more
% find . -type f -name "*.*" | sed -r 's/^.+(\.\w+)$/\1/' | sort | uniq
% find . -type f -print | wc -l
% tar -tvf archive.tar | grep "^-.*" | wc -l
grep commandTo find lines not matching the specified patterns in a file, you can use -v option with grep command.
$ svn list -R http://.../repos1 | grep -v -E '(.*java|.*/)'
You don’t need to be bothered to find out how to use complex negative patterns with regex.
odYou can view non ascii base files in hexadecimal format using od command.
% od -A d -x journal.log
For more about od, refer the following.
less -S% less -S known_hosts
ps command without line wrappingYou can redirect the result to cat or less command, or use ww flag.
% ps auxf | cat
...
% ps auxfww
...
% ps auxf | less -+S
#)% cat /etc/apt/sources.list | grep -P '^[^#].*'
du commandYou can sort the output of du command applying pipe to sort command.
% du -m | sort -n
For more about du and sort, read the followings.
wget commandwget provide --accept or -A switch which can represent multiple files using comma separated list, wild card, or character class. But it’s not that -A switch support regular expression.
$ su - hdfs -c "(cd ~; wget -x -P samples/flight/rawdata -A '198[7-9].csv.bz2' http://stat-computing.org/dataexpo/2009/)"
$ su - hdfs -c "(cd ~; wget -x -P samples/flight/rawdata -A '199[0-9].csv.bz2' http://stat-computing.org/dataexpo/2009/)"
$ su - hdfs -c "(cd ~; wget -x -P samples/flight/rawdata -A '200[0-8].csv.bz2' http://stat-computing.org/dataexpo/2009/)"
$ su - hdfs -c "(cd ~; wget -x -P samples/flight/rawdata -A 'airports.csv, carriers.csv, plane-data.csv' http://stat-computing.org/dataexpo/2009/)"
For more, refer the following
tcpdumpsudo tcpdump -s 0 -A -i eth1 dst port 80
fruits=(Apple Banana Kiwi)
for f in ${fruits[@]}; do
echo $f
done;
For correlated arrays,
fruits=(Apple Banana Kiwi)
colors=(red yellow green)
for (( i=0; i<${#fruits[@]}; i++)); do
echo ${fruits[$i]} is ${colors[$i]}
done;
declare -a m
m[0]='a b c d'
m[1]='e f g h'
m[2]='i j k l'
m[3]='m n o p'
m[4]='q r s t'
for r in "${m[@]}"; do
echo $r
for c in $r; do
echo $c
done
done
awk and sed intermediate level code 1awk -F, '{if (($1 ~ /vm[0-9]*/) && (substr($1, 3, length($1) - 1) + 0 < 97)) print $1 " " $2}' ../../vms.csv | while read vm ip; do
no=${vm##vm} # remove left 'vm'
org_no=$(($(($((no - 1))/org_size)) + 1))
peer_str="{\"requests\": \"grpcs://${ip}:7051\", \"events\": \"grpcs://${ip}:7053\", \"server-hostname\": \"peer${no}\", \"tls_cacerts\": \"tlsCerts/org${org_no}.com/tlsca${org_no}-cert.pem\"}"
# Defines paired peer no : (vm1-vm2, vm3-vm4, ...)
if [ $((no % 2)) -eq 1 ]; then
no2=$((no + 1))
else
no2=$((no - 1))
fi
# For current peer vm
sed -i -r 's#@@peer1@@#\"peer1\": '"$peer_str"',#' ./generated/vm${no}/channelConfig.json
if [ $? -ne 0 ]; then
echo "Fail to update 'peer1' part of './generated/vm${no}/channelConfig.json' file."
exit 1
else
echo "Successfully updated 'peer1' part of './generated/vm${no}/channelConfig.json' file."
fi
# For paired peer vm
sed -i -r 's#@@peer2@@#\"peer2\": '"$peer_str"'#' ./generated/vm${no2}/channelConfig.json
if [ $? -ne 0 ]; then
echo "Fail to update 'peer2' part of './generated/vm${no2}/channelConfig.json' file."
exit 1
else
echo "Successfully updated 'peer2' part of './generated/vm${no2}/channelConfig.json' file."
fi
done
Using apt
$ sudo apt update # update
...
$ sudo apt list *golang-1.8* --installed # search
...
$ sudo apt install golang-1.8 # upgrade
...
$ sudo apt show golang-1.8 # confirm
...
$ sudo apt-file list golang-1.8 # confirm all the files installed
Not using apt
$ sudo apt-get update # update
...
$ sudo dpkg -l | awk '{print $2}' | grep golang-1.8 # search
...
$ sudo apt-get install golang-1.8 # upgrade
...
$ sudo apt-cache show golang-1.8 # confirm
...
$ sudo apt-file list golang-1.8 # confirm all the files installed
$ sudo apt-get install nodejs=6.10.2*
$ sudo apt list --installed