Category: OS
-
Unix – Executing Top once or Every X Seconds
Top Every Second -Version 1 top -c -b Top Every Second -Version 2 top -c -b -d 1 Top Every 5 Seconds top -c -b -d 5 Top Only once top -c -b -n 1 top -h procps-ng version 3.3.3 usage: top -hv | -bcHiSs -d delay -n limit -u|U user | -p pid[,pid] -w…
-
Postgres – Which users are Currently Connected to the database
Postgres Database – Who is Currently Connected SELECT * FROM pg_stat_activity order by client_addr;
-
Unix – ps – finding running processes
ps -fA|grep postgres PS(1) User Commands PS(1) NAME ps – report a snapshot of the current processes. SYNOPSIS ps [options] DESCRIPTION ps displays information about a selection of the active processes. If you want a repetitive update of the selection and the displayed information, use top(1) instead. This version of ps accepts several kinds of…
-
Unix – using tail and grep together
Tail Examples tail -f postgres.log|grep “exec” | awk ‘{print $1,$16,$7}’ Tail Examples tail -f /var/log/postgresql.log | egrep “errors” tail –help Usage: tail [OPTION]… [FILE]… Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or when FILE…
-
Unix – Find the Files open by a process
Files Open by Process ls -l /proc/PROCID/fd Count Files Open by Process lsof -p PROCID|wc -l #alternative ls -l /proc/PROCID/fd| wc -l lsof -h lsof 4.86 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s] [-F [f]] [-g [s]] [-i [i]] [+|-L [l]]…
-
Unix – Kill Processes
KILL kill -KILL 9573 > man kill KILL(1) User Commands KILL(1) NAME kill – send a signal to a process SYNOPSIS kill [options] […] DESCRIPTION The default signal for kill is TERM. Use -l or -L to list available signals. Particularly useful signals include HUP, INT, KILL, STOP, CONT, and 0. Alternate signals may be…
-
Unix – Grep, egrep and Recursive Grep
# files containing “import” in subdirectories grep -rHn “import” * # files containing “import” or “except” grep -rHnE “import|except” * # only .py files containing “import” or “except” grep –color –include=”*.py” -rHnE “import|except” * # python files, text files and java files grep –color –include=”*[py|txt|java]” -rHnE “^import [a-z,\s]+$” * # same as above with extended…
-
bzip2 – compress and decompress
Compress Files using bzip bzip2 archivefile1.txt Folder Compression The “.bz2” file extension is commonly used by the compression program bzip2, which is the counter part of bunzip2. You can use the “-r” option to recursively compress all the files under the specified directory. For example: tar cvf – foldername | bzip2 > foldername.tar.bz2 Keeping the…
-
Unix – Set date and time
sudo date -s “01/18/2013 17:18:00” # Fri Jan 18 17:18:00 CET 2013 sudo date -s “YYYY-mm-DD HH:MM:SS-MS:00” Example: sudo date -s “2013-01-16 13:57:56-06:00” > man date DATE(1) User Commands DATE(1) NAME date – print or set the system date and time SYNOPSIS date [OPTION]… [+FORMAT] date [-u|–utc|–universal] [MMDDhhmm[[CC]YY][.ss]] DESCRIPTION Display the current time in the…
-
Unix – find files and directories using the find and grep commands
Find Files containing solr # python files, text files and java files grep –color –include=”*[py|txt|java]” -rHnE “^import [a-z,\s]+$” * # same as above with extended find . -regextype posix-extended -iregex “.*.py|.*.txt|.*.txt” -exec grep –color -rHnE “import|except” ‘{}’ \; -print #find . -name “*.py” -exec grep –color -rHnE “import|except” ‘{}’ \; -print Find Files containing solr…