Category: shell
-
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 – tar – package and compress files and directory
Create an archive To create an archive of the entire test directory, issue the following command: tar cvf my_arch.tar /home/oracle/alex/test Compress the Files or Directory with gzip tar cvf – filenames | gzip > file.tar.gz Compress the Files or Directory with bzip2 tar cvf – directorypath | bzip2 > file.tar.bz2 If you want to include…
-
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 – 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…