<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://knowledgenerd.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Creator</id>
	<title>KnowledgeNerd - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://knowledgenerd.net/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Creator"/>
	<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Special:Contributions/Creator"/>
	<updated>2026-10-30T15:21:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=35</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=35"/>
		<updated>2025-03-25T14:20:18Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Compress */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing files and directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, finding and searching inside files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates a compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -c filename.foo &amp;gt; filename.foo.gz (it creates a compressed version: filename.foo.gz and keeps your original file also.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List files in archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X specific permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration related commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating system restart / reboot / shut down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server related commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network related commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network interface commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot;, &amp;quot;bar.txt&amp;quot; &amp;amp; &amp;quot;baz.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:/dir\{foo.txt,bar.txt,baz.txt\} .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@xxx.xxx.xxx.xxx:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=SQL&amp;diff=34</id>
		<title>SQL</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=SQL&amp;diff=34"/>
		<updated>2021-03-26T22:38:30Z</updated>

		<summary type="html">&lt;p&gt;Creator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQL and MySQL queries ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Select ===&lt;br /&gt;
&lt;br /&gt;
==== ROW_COUNT / Affected Rows ====&lt;br /&gt;
&lt;br /&gt;
 SELECT ROW_COUNT();&lt;br /&gt;
ROW_COUNT() returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE, DELETE, or INSERT. For other statements, the value may not be meaningful.&lt;br /&gt;
&lt;br /&gt;
==== Concatenate ====&lt;br /&gt;
&lt;br /&gt;
 SELECT CONCAT('Rows affected: ',ROW_COUNT()) AS 'Affected Rows';&lt;br /&gt;
&lt;br /&gt;
==== CASE ====&lt;br /&gt;
&lt;br /&gt;
Case Expression / conditional statement / if statement&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT CASE WHEN columnZ &amp;lt;&amp;gt; 0 THEN 4&lt;br /&gt;
            WHEN columnY &amp;lt;&amp;gt; 0 THEN 3&lt;br /&gt;
            WHEN columnX &amp;lt;&amp;gt; 0 THEN 2&lt;br /&gt;
            WHEN columnW &amp;lt;&amp;gt; 0 THEN 1&lt;br /&gt;
            ELSE 0&lt;br /&gt;
       END AS your_alias_name&lt;br /&gt;
FROM ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT u.name,&lt;br /&gt;
  up.points,&lt;br /&gt;
  CASE WHEN u.access &amp;lt;&amp;gt; 0 THEN FROM_UNIXTIME(u.access) ELSE '' END AS 'Last activity on site',&lt;br /&gt;
FROM userpoints up INNER JOIN users u ON up.uid = u.uid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sort ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Joins ===&lt;br /&gt;
&lt;br /&gt;
MySQL cases (can apply to MS SQL also, but not confirmed yet).&lt;br /&gt;
&lt;br /&gt;
Different &amp;lt;code&amp;gt;JOIN&amp;lt;/code&amp;gt; types:&lt;br /&gt;
* '''JOIN''' or '''INNER JOIN''': Return rows when there is at least one match in both tables&lt;br /&gt;
* '''LEFT JOIN''': Return all rows from the left table, even if there are no matches in the right table&lt;br /&gt;
* '''RIGHT JOIN''': Return all rows from the right table, even if there are no matches in the left table&lt;br /&gt;
* '''FULL JOIN''': Return rows when there is a match in one of the tables&lt;br /&gt;
&lt;br /&gt;
Example data:&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse; float: left;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;5&amp;quot; | Persons table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;text-align: left;&amp;quot; | P_Id&lt;br /&gt;
!Lastname&lt;br /&gt;
!Firstname&lt;br /&gt;
!Address&lt;br /&gt;
!City&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Hansen&lt;br /&gt;
|Ola&lt;br /&gt;
|Timoteivn 10&lt;br /&gt;
| Sandnes&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|Svendson&lt;br /&gt;
|Tove&lt;br /&gt;
|Borgvn 23&lt;br /&gt;
| Sandnes&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Pettersen&lt;br /&gt;
|Kari&lt;br /&gt;
|Storgt 20&lt;br /&gt;
|Stavanger&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border-collapse: collapse; border: 1px solid #000000; margin-left: 340px;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; | Orders table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | O_Id&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | OrderNo&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | P_Id&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 1&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 77895&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 2&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 44678&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 3&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 22456&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 24562&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 5&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 34764&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== INNER JOIN ====&lt;br /&gt;
&lt;br /&gt;
INNER JOIN is same as JOIN. As a matter of fact INNER JOIN is a default type of JOIN and that's why you don't have to include INNER keyword. Returns rows when there is at least one match in both tables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
INNER JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The result-set will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola     24562&lt;br /&gt;
Hansen    Ola     22456&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Other examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT mes.*, ind.uid&lt;br /&gt;
FROM pm_message mes&lt;br /&gt;
INNER JOIN pm_index ind ON mes.mid = ind.mid&lt;br /&gt;
WHERE ind.uid = 1234&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LEFT JOIN ====&lt;br /&gt;
&lt;br /&gt;
The LEFT JOIN keyword returns all rows from the left table (first table), even if there are no matches in the right table (table to join).&lt;br /&gt;
&lt;br /&gt;
'''Note!''' In some databases LEFT JOIN is called LEFT OUTER JOIN. In MySQL LEFT OUTER JOIN is equal to LEFT JOIN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
LEFT JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result-set will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola     22456&lt;br /&gt;
Hansen    Ola   24562&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
Svendson  Tove    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RIGHT JOIN ====&lt;br /&gt;
&lt;br /&gt;
The RIGHT JOIN keyword returns all the rows from the right table (second table), even if there are no matches in the left table (first table).&lt;br /&gt;
&lt;br /&gt;
'''Note!''' In some databases RIGHT JOIN is called RIGHT OUTER JOIN. In MySQL RIGHT OUTER JOIN is equal to RIGHT JOIN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
RIGHT JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result-set will look like this (all the orders with containing persons - if any):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
            34764&lt;br /&gt;
Hansen    Ola   22456&lt;br /&gt;
Hansen    Ola   24562&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FULL JOIN ====&lt;br /&gt;
&lt;br /&gt;
The FULL JOIN keyword return rows when there is a match in one of the tables. FULL JOIN = FULL OUTER JOIN.&lt;br /&gt;
* '''Note!''' MySQL lacks support for FULL OUTER JOIN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
FULL JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola   22456&lt;br /&gt;
Hansen    Ola     24562&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
Svendson  Tove   &lt;br /&gt;
            34764&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With '''MySQL''' you can mitigate the FULL JOIN by using LEFT JOIN, RIGHT JOIN and UNION together.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT p.LastName, p.FirstName, o.OrderNo&lt;br /&gt;
FROM persons p&lt;br /&gt;
LEFT JOIN orders o ON p.P_Id = o.P_Id&lt;br /&gt;
UNION&lt;br /&gt;
SELECT p.LastName, p.FirstName, o.OrderNo&lt;br /&gt;
FROM persons p&lt;br /&gt;
RIGHT JOIN orders o ON p.P_Id = o.P_Id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola   22456&lt;br /&gt;
Hansen    Ola     24562&lt;br /&gt;
Svendson  Tove    &lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
        34764&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNION ====&lt;br /&gt;
&lt;br /&gt;
The UNION operator is used to combine the result-set of two or more SELECT statements.&lt;br /&gt;
&lt;br /&gt;
Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.&lt;br /&gt;
&lt;br /&gt;
SQL UNION Syntax&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT column_name(s) FROM table_name1&lt;br /&gt;
UNION&lt;br /&gt;
SELECT column_name(s) FROM table_name2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Note: The '''UNION''' operator selects only '''distinct values''' by default. To allow duplicate values, use '''UNION ALL'''. The column names in the result-set of a UNION are always equal to the column names in the first SELECT statement in the UNION.&lt;br /&gt;
&lt;br /&gt;
Example data:&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse; float: left;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; | Employees_Norway table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;text-align: left;&amp;quot; | E_ID&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | E_Name&lt;br /&gt;
|-&lt;br /&gt;
|01&lt;br /&gt;
|Hansen, Ola&lt;br /&gt;
|-&lt;br /&gt;
|02&lt;br /&gt;
|Svendson, Tove&lt;br /&gt;
|-&lt;br /&gt;
|03&lt;br /&gt;
|Svendson, Stephen&lt;br /&gt;
|-&lt;br /&gt;
|04&lt;br /&gt;
|Pettersen, Kari&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse; margin-left: 190px;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; | Employees_USA table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;text-align: left;&amp;quot; | E_ID&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | E_Name&lt;br /&gt;
|-&lt;br /&gt;
|01&lt;br /&gt;
|Turner, Sally&lt;br /&gt;
|-&lt;br /&gt;
|02&lt;br /&gt;
|Kent, Clark&lt;br /&gt;
|-&lt;br /&gt;
|03&lt;br /&gt;
|Svendson, Stephen&lt;br /&gt;
|-&lt;br /&gt;
|04&lt;br /&gt;
|Scott, Stephen&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* List '''all the different employees''' in Norway and USA&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT E_Name FROM Employees_Norway&lt;br /&gt;
UNION&lt;br /&gt;
SELECT E_Name FROM Employees_USA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result-set will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
E_Name&lt;br /&gt;
Hansen, Ola&lt;br /&gt;
Svendson, Tove&lt;br /&gt;
Svendson, Stephen&lt;br /&gt;
Pettersen, Kari&lt;br /&gt;
Turner, Sally&lt;br /&gt;
Kent, Clark&lt;br /&gt;
Scott, Stephen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note''': Only distinct employee names are shown.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* List '''all employees''' in Norway and USA&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT E_Name FROM Employees_Norway&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT E_Name FROM Employees_USA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
E_Name&lt;br /&gt;
Hansen, Ola&lt;br /&gt;
Svendson, Tove&lt;br /&gt;
Svendson, Stephen&lt;br /&gt;
Pettersen, Kari&lt;br /&gt;
Turner, Sally&lt;br /&gt;
Kent, Clark&lt;br /&gt;
Svendson, Stephen&lt;br /&gt;
Scott, Stephen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note''': Showing all names (Svendson, Stephen x 2).&lt;br /&gt;
&lt;br /&gt;
=== GROUP BY ===&lt;br /&gt;
&lt;br /&gt;
Select how many comments each users have made and sort those descending&lt;br /&gt;
 SELECT uid, COUNT(uid) AS commentcount FROM comments GROUP BY uid ORDER BY commentcount DESC&lt;br /&gt;
&lt;br /&gt;
=== IN Clause Order ===&lt;br /&gt;
&lt;br /&gt;
Result set won't be in the same order than IN-clause's ids:&lt;br /&gt;
 SELECT topic_id, topic_title from phpbb_topics where topic_id IN(5435, 23, 324)&lt;br /&gt;
&lt;br /&gt;
Result set will be ordered as you like:&lt;br /&gt;
 SELECT topic_id, topic_title from phpbb_topics where topic_id IN(5435, 23, 324) ORDER BY FIND_IN_SET(topic_id, '23,324,5435')&lt;br /&gt;
&lt;br /&gt;
=== Substring ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTRING('Quadratically',5); // prints 'ratically'&lt;br /&gt;
SELECT SUBSTRING('foobarbar' FROM 4); // prints 'barbar'&lt;br /&gt;
SELECT SUBSTRING('Quadratically',5,6); // prints 'ratica'&lt;br /&gt;
SELECT SUBSTRING('Sakila', -3); // prints 'ila'&lt;br /&gt;
SELECT SUBSTRING('Sakila', -5, 3); // prints 'aki'&lt;br /&gt;
SELECT SUBSTRING('Sakila' FROM -4 FOR 2); // prints 'ki'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Update ===&lt;br /&gt;
&lt;br /&gt;
Update with replace:&lt;br /&gt;
Replace url_alias table's dst column's all 'forums' words with 'keskustelu'&lt;br /&gt;
 UPDATE url_alias SET dst = REPLACE(dst, 'forums', 'keskustelu')&lt;br /&gt;
&lt;br /&gt;
Update with subquery:&lt;br /&gt;
 UPDATE `gsmvalidation` SET confirmedtime = (SELECT NOW())&lt;br /&gt;
 WHERE id = (SELECT id FROM (SELECT id,uid,codesended from `gsmvalidation`) AS temp WHERE uid = 1 ORDER BY `codesended` DESC LIMIT 1)&lt;br /&gt;
&lt;br /&gt;
=== Insert ===&lt;br /&gt;
&lt;br /&gt;
Insert single row:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO `drupal6`.`url_alias` (&lt;br /&gt;
`pid` ,&lt;br /&gt;
`src` ,&lt;br /&gt;
`dst` ,&lt;br /&gt;
`language`&lt;br /&gt;
)&lt;br /&gt;
VALUES (&lt;br /&gt;
NULL , 'phpbbforum/index.php', 'forums/index.php', ''&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insert multiple rows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO url_alias (src, dst)&lt;br /&gt;
VALUES&lt;br /&gt;
('phpbbforum','forums'),&lt;br /&gt;
('phpbbforum/index.php', 'forums/index.php'),&lt;br /&gt;
('phpbbforum/viewtopic.php', 'forums/viewtopic.php');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insert all rows from other table after emptying the destination table first:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TRUNCATE TABLE drupal622.dr_access;&lt;br /&gt;
INSERT INTO drupal622.dr_access SELECT * FROM drupal510.access;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Custom insert (there's no language column in source table):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO drupal622.dr_url_alias (pid,src,dst,language) SELECT pid,src,dst,'' FROM drupal510.url_alias&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Delete ===&lt;br /&gt;
&lt;br /&gt;
 DELETE FROM Persons WHERE LastName = 'Smith'&lt;br /&gt;
&lt;br /&gt;
=== Time and date ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Convert timestamp to date'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT u.created FROM users u // 1346693013&lt;br /&gt;
SELECT FROM_UNIXTIME(u.created) as 'User created' FROM users u // 2012-09-03 18:23:33&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(u.created)) as 'User created' FROM users u // 2012-09-03&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Convert date to timestamp'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT UNIX_TIMESTAMP('2012-08-01') // 1343775600&lt;br /&gt;
SELECT UNIX_TIMESTAMP('2012-08-01 01:02:03') //1343779323&lt;br /&gt;
// post_time = timestamp&lt;br /&gt;
SELECT * FROM phpbb_posts WHERE post_time BETWEEN UNIX_TIMESTAMP('2012-08-01') AND UNIX_TIMESTAMP('2012-09-05')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert datetime field values (CAST &amp;amp; DATE_FORMAT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT confirmedtime FROM gsm WHERE uid = 1 //2010-10-27 14:58:39&lt;br /&gt;
SELECT CAST(confirmedtime AS DATE) AS confirmedtime FROM gsm WHERE uid = 1 //2010-10-27&lt;br /&gt;
SELECT CAST('2012-09-04' AS DATETIME) // 2012-09-04 00:00:00&lt;br /&gt;
SELECT CAST('2012-09-04' AS DATE) // 2012-09-04&lt;br /&gt;
SELECT DATE_FORMAT(confirmedtime,'%d.%m.%Y') AS confirmedtime FROM gsm WHERE uid = 1 //27.10.2010&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select current datetime or timestamp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT NOW()     -- 2010-09-09 08:54:53&lt;br /&gt;
SELECT CURDATE() -- 2010-09-09&lt;br /&gt;
SELECT CURTIME() -- 08:55:35&lt;br /&gt;
SELECT UNIX_TIMESTAMP(NOW()) -- 1314961714&lt;br /&gt;
SELECT UNIX_TIMESTAMP('2005-03-27 02:00:00') -- 1111885200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select something where date is 2012-09-04&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// userdata is in following format (timestamp-id): 1346746755-193&lt;br /&gt;
// two hours is added to timestamp to get Finnish time (GMT+2)&lt;br /&gt;
WHERE DATE(FROM_UNIXTIME((SELECT SUBSTRING(userdata, 1,10)+7200))) = CAST('2012-09-04' AS DATE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Minus 1 day from current time for begintime field and add 20 years to endtime field&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT DATE_SUB(NOW(), INTERVAL 1 DAY), DATE_ADD(`endtime`, INTERVAL 20 YEAR)&lt;br /&gt;
FROM `publishdates`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update rows which don't have publish from value (startpublish_value). new value this time - 2 days.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UPDATE `publishdates`&lt;br /&gt;
SET `startpublish` = DATE_SUB(NOW(), INTERVAL 2 DAY)&lt;br /&gt;
WHERE `startpublish` IS NULL OR `field_startpublish_value` = '0000-00-00 00:00:00'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insert data to datetime (YYYY-mm-dd H:i:s) and date formatted fields&lt;br /&gt;
 INSERT INTO logs (datetime,date) VALUES ('2005-06-12 23:56:25', '2005-06-12');&lt;br /&gt;
&lt;br /&gt;
If you are using a DATE_FORMAT function to format date e.g. '%d.%m.%Y' and use variable placeholders e.g. %f, '%s' in same sql, you have to add DATE_FORMAT parameters through variable placeholder. Otherwise day %d takes the first variables value. Right way to do it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$dateFormat = &amp;quot;%d.%m.%Y&amp;quot;;&lt;br /&gt;
$gsmValidated = db_fetch_object(db_query(&amp;quot;SELECT DATE_FORMAT(confirmedtime, '%s') AS confirmedtime FROM gsmvalidation WHERE uid = %f AND gsmtoconfirm = '%s' AND confirmedtime != '' ORDER BY `confirmedtime` DESC LIMIT 1&amp;quot;, $dateFormat, $uid, $gsmnumberStr));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
cast and between&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// $D1 and $D2 are posted variables in PHP&lt;br /&gt;
SELECT * FROM Sales WHERE TransactionDate BETWEEN CAST('$D1' as DATETIME) and CAST($D2 as DATETIME)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Auto Increment Values ===&lt;br /&gt;
&lt;br /&gt;
==== Show Next Value ====&lt;br /&gt;
&lt;br /&gt;
Show next autoincrement value from files-table (check Auto_increment column):&lt;br /&gt;
 SHOW TABLE STATUS LIKE 'files'&lt;br /&gt;
or better way to do it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT AUTO_INCREMENT FROM information_schema.tables&lt;br /&gt;
WHERE table_name = 'files'&lt;br /&gt;
AND table_schema = 'drupal6'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or show each tables' auto_increment values:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT table_name, AUTO_INCREMENT FROM information_schema.tables&lt;br /&gt;
WHERE AUTO_INCREMENT IS NOT NULL AND table_schema = 'drupal6'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or select highest autoincrement value and add 1 to it:&lt;br /&gt;
 SELECT MAX(fid)+1 FROM 'files'&lt;br /&gt;
* Note: If someone inserted new row after your query the next id is not up to date anymore. That happens also if the row with max id have been deleted.&lt;br /&gt;
&lt;br /&gt;
==== Show Updated Row's Auto Increment ID Value ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO 'files' ('fid', 'filename') VALUES ('','image.jpg');&lt;br /&gt;
SELECT LAST_INSERT_ID();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reset Autoincrement Value ====&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE visitors AUTO_INCREMENT = 1&lt;br /&gt;
&lt;br /&gt;
If the highest value for the column is already greater than new auto-increment value then it will be set to the highest value plus 1&lt;br /&gt;
&lt;br /&gt;
=== Replace ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
REPLACE('where_to_look', 'what_to_look', 'the_replacement')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select name and age. Convert the age column to number and replace 'years' string and whitespaces.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT name, CONVERT(INT, REPLACE(REPLACE(age, 'years', ''), ' ', '')) AS age&lt;br /&gt;
FROM persons&lt;br /&gt;
ORDER BY age DESC&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update (limit to 10) nodes_revisions table's body fields content. Change readfile paths from &amp;lt;code&amp;gt;/var/www/html/&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/srv/www/docroot/&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UPDATE node_revisions&lt;br /&gt;
SET body = REPLACE(body, '/var/www/html/', '/srv/www/docroot/')&lt;br /&gt;
WHERE body LIKE '%readfile(\'/var/www%'&lt;br /&gt;
LIMIT 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Convert And Cast ===&lt;br /&gt;
&lt;br /&gt;
==== Convert String Into a Number ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- content string is 1346761037-192&lt;br /&gt;
SELECT CAST(SUBSTRING(content, 12) AS UNSIGNED INTEGER) AS theID&lt;br /&gt;
SELECT CONVERT(SUBSTRING(content, 12), SIGNED INTEGER) AS theID&lt;br /&gt;
SELECT SUBSTRING(content, 12) * 1 AS theID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Convert BLOB Into a String ====&lt;br /&gt;
&lt;br /&gt;
 SELECT CONVERT(exampleColumn USING utf8) AS exampleColumn FROM exampleTable&lt;br /&gt;
&lt;br /&gt;
* In PhpMyAdmin you can also:&lt;br /&gt;
** download the blob data, by clicking e.g. [BLOB - 6B] link (activates download), downloading it to your computer and opening it with text editor.&lt;br /&gt;
** select &amp;quot;+ Options&amp;quot; from browse data mode and select &amp;lt;code&amp;gt;Show BLOB contents&amp;lt;/code&amp;gt; checkbox.&lt;br /&gt;
&lt;br /&gt;
==== Search String From BLOB ====&lt;br /&gt;
&lt;br /&gt;
BLOB data is stored as a binary data thus it's case sensitive. You can make a case sensitive query by (returns only 'The'):&lt;br /&gt;
 SELECT * FROM `dr_locales_source` WHERE source LIKE '%The%'&lt;br /&gt;
&lt;br /&gt;
If you want to make case-insensitive comparison (e.g. The, the, thE), you can convert BLOB to string using utf8 encoding:&lt;br /&gt;
 SELECT * FROM `dr_locales_source` WHERE CONVERT(source USING UTF8) LIKE '%The%'&lt;br /&gt;
&lt;br /&gt;
=== NULL ===&lt;br /&gt;
&lt;br /&gt;
Find NULL values:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT * FROM USERS&lt;br /&gt;
WHERE 'middle_name' IS NULL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find values different than NULL:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT * FROM USERS&lt;br /&gt;
WHERE 'middle_name' IS NOT NULL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Explain ===&lt;br /&gt;
&lt;br /&gt;
* Good source: http://www.slideshare.net/phpcodemonkey/mysql-explain-explained&lt;br /&gt;
&lt;br /&gt;
Tool to optimize queries. The '''EXPLAIN''' statement can be used either as a way to obtain information about how MySQL executes a statement, or as a synonym for '''DESCRIBE'''.&lt;br /&gt;
&lt;br /&gt;
Get details of the table:&lt;br /&gt;
 EXPLAIN drupal7.node_revision&lt;br /&gt;
 DESCRIBE drupal7.node_revision&lt;br /&gt;
&lt;br /&gt;
Obtain information about the query:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
EXPLAIN SELECT n.nid, n.title, n.type, frb.body_value, nr . *&lt;br /&gt;
FROM node n&lt;br /&gt;
JOIN node_revision nr ON n.nid = nr.nid&lt;br /&gt;
JOIN field_revision_body frb ON n.nid = frb.entity_id&lt;br /&gt;
ORDER BY n.nid DESC&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''EXPLAIN EXTENDED''' can be used to obtain additional information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
EXPLAIN EXTENDED SELECT n.nid, n.title&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A good way to keep up to date which queries need optimization and further investigation with &amp;lt;code&amp;gt;EXPLAIN&amp;lt;/code&amp;gt; statement is to enable '''MySQL's Slow Query Log'''&lt;br /&gt;
&lt;br /&gt;
* Use the mysqladmin command line tool to identify more general problems. The Following query will show mysql server's extended status information and updates it every 10 seconds.&lt;br /&gt;
 mysqladmin -u dbuser -p -r -i 10 extended-status&lt;br /&gt;
&lt;br /&gt;
Example: Booking application schema&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;4&amp;quot; | attendees table&lt;br /&gt;
|-&lt;br /&gt;
!attendee_id&lt;br /&gt;
!surname&lt;br /&gt;
!conference_id&lt;br /&gt;
!registration_status&lt;br /&gt;
|-&lt;br /&gt;
| INTEGER (PK)&lt;br /&gt;
| VARCHAR&lt;br /&gt;
| INTEGER(FK)&lt;br /&gt;
| TINYINT&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;4&amp;quot; | conferences table&lt;br /&gt;
|-&lt;br /&gt;
!conference_id&lt;br /&gt;
!location_id&lt;br /&gt;
!topic_id&lt;br /&gt;
!date&lt;br /&gt;
|-&lt;br /&gt;
| INTEGER (PK)&lt;br /&gt;
| INTEGER(FK)&lt;br /&gt;
| INTEGER(FK)&lt;br /&gt;
| DATE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
EXPLAIN SELECT * FROM attendees WHERE conference_id = 123 AND registration_status &amp;gt; 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''possible_keys''' - All possible indicies mysql could use. Query will choose the best one of the availeble ones (if any).&lt;br /&gt;
* '''key''' - The chosen index key for the query. If NULL, no useful index was found --&amp;gt; query needs to be optimized.&lt;br /&gt;
* '''rows''' - All the rows needed to scan for your query&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
!table&lt;br /&gt;
!possible_keys&lt;br /&gt;
!key&lt;br /&gt;
!rows&lt;br /&gt;
|-&lt;br /&gt;
|attendees&lt;br /&gt;
|NULL&lt;br /&gt;
|NULL&lt;br /&gt;
|14052&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conclusion:&lt;br /&gt;
* No suitable indexes found for this query&lt;br /&gt;
* Mysql had to do a full table scan (almost always the slowest query)&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE ADD INDEX conf (conference_id);&lt;br /&gt;
 ALTER TABLE ADD INDEX reg (registration_status);&lt;br /&gt;
 EXPLAIN SELECT * FROM attendees WHERE conference_id = 123 AND registration_status &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
!table&lt;br /&gt;
!possible_keys&lt;br /&gt;
!key&lt;br /&gt;
!rows&lt;br /&gt;
|-&lt;br /&gt;
|attendees&lt;br /&gt;
|conf,reg&lt;br /&gt;
|conf&lt;br /&gt;
|331&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* Mysql chose the more unique index '''conf''' and had to scan only 331 rows compared to previous full table scan with 14052 rows&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Databases ===&lt;br /&gt;
&lt;br /&gt;
==== Create a Database ====&lt;br /&gt;
&lt;br /&gt;
===== mysql Commandline Tool =====&lt;br /&gt;
&lt;br /&gt;
First access the MySQL server&lt;br /&gt;
 mysql -u root -p&lt;br /&gt;
&lt;br /&gt;
Create database&lt;br /&gt;
 CREATE DATABASE exampledatabase;&lt;br /&gt;
&lt;br /&gt;
If you want to grant permissions also for someone else than root user&lt;br /&gt;
 GRANT ALL ON exampledatabase.* TO exampleuser@localhost IDENTIFIED BY &amp;quot;examplepassword&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Exit mysql admin&lt;br /&gt;
 quit&lt;br /&gt;
&lt;br /&gt;
You can now test login with previously specified user&lt;br /&gt;
 mysql -u exampleuser -p&lt;br /&gt;
&lt;br /&gt;
Check if you see the right databases&lt;br /&gt;
 SHOW DATABASES;&lt;br /&gt;
&lt;br /&gt;
==== Select a Database ====&lt;br /&gt;
&lt;br /&gt;
 USE exampledatabase;&lt;br /&gt;
&lt;br /&gt;
==== Delete / Drop a Database ====&lt;br /&gt;
&lt;br /&gt;
 DROP DATABASE `phpbb3seo`&lt;br /&gt;
Note! MySQL won't free the space after database is deleted. Instead of that it will reuse the space later when new data is added. File is probably: /var/lib/mysql/ibdata1.&lt;br /&gt;
* To shrink the size you will need to dump all databases and then restore them again.&lt;br /&gt;
* You can also do the following: Set innodb_file_per_table in your config file, which will create a separate file per table. That will then allow you to delete these files once a database is dropped and also allow you to use the OPTIMIZE TABLE command to rebuild ibd files if you shrink the data in a particular table.&lt;br /&gt;
&lt;br /&gt;
=== Tables ===&lt;br /&gt;
&lt;br /&gt;
[[MySQL_Server#MySQL_Datatypes | MySQL Datatypes]]&lt;br /&gt;
&lt;br /&gt;
==== Create a Table ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `url_alias` (&lt;br /&gt;
  `pid` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `src` varchar(128) NOT NULL DEFAULT '',&lt;br /&gt;
  `dst` varchar(128) NOT NULL DEFAULT '',&lt;br /&gt;
  `language` varchar(12) NOT NULL DEFAULT '',&lt;br /&gt;
  PRIMARY KEY (`pid`),&lt;br /&gt;
  UNIQUE KEY `dst_language_pid` (`dst`,`language`,`pid`),&lt;br /&gt;
  KEY `src_language_pid` (`src`,`language`,`pid`)&lt;br /&gt;
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=35;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a Temporary Table ====&lt;br /&gt;
&lt;br /&gt;
todo&lt;br /&gt;
&lt;br /&gt;
==== Copy a Table ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE `drupal6`.`permission_bak` (&lt;br /&gt;
`pid` int( 11 ) NOT NULL AUTO_INCREMENT ,&lt;br /&gt;
`rid` int( 10 ) unsigned NOT NULL DEFAULT '0',&lt;br /&gt;
`perm` longtext,&lt;br /&gt;
`tid` int( 10 ) unsigned NOT NULL DEFAULT '0',&lt;br /&gt;
PRIMARY KEY ( `pid` ) ,&lt;br /&gt;
KEY `rid` ( `rid` )&lt;br /&gt;
) ENGINE = MYISAM DEFAULT CHARSET = utf8;&lt;br /&gt;
&lt;br /&gt;
INSERT INTO `drupal6`.`permission_bak`&lt;br /&gt;
SELECT *&lt;br /&gt;
FROM `drupal6`.`permission` ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete / Drop Table ====&lt;br /&gt;
&lt;br /&gt;
 DROP TABLE dr_imagecache_action&lt;br /&gt;
To avoid an error message in case the table don't exist (&amp;lt;code&amp;gt;#1051 - Unknown table 'dr_imagecache_action' &amp;lt;/code&amp;gt;) use &amp;lt;code&amp;gt;IF EXISTS&amp;lt;/code&amp;gt; check:&lt;br /&gt;
 DROP TABLE IF EXISTS dr_imagecache_action&lt;br /&gt;
&lt;br /&gt;
==== Drop Multiple Tables ====&lt;br /&gt;
&lt;br /&gt;
If you want to drop multiple tables using wildcard in table name, here's solution.&lt;br /&gt;
Use &amp;lt;code&amp;gt;SHOW TABLES&amp;lt;/code&amp;gt; to get the wanted table list, e.g.&lt;br /&gt;
 SHOW TABLES LIKE 'phpbb_%';&lt;br /&gt;
&lt;br /&gt;
Then just form your remove query with resulted text:&lt;br /&gt;
 DROP TABLE phpbb_tbl1,phpbb_tbl2, phpbb_tbl3;&lt;br /&gt;
&lt;br /&gt;
If you want to do this with shell commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u your_user -D your_database_name -e &amp;quot;show tables&amp;quot; -s | &lt;br /&gt;
  egrep &amp;quot;^Whatever_&amp;quot; | &lt;br /&gt;
  xargs -I &amp;quot;@@&amp;quot; echo mysql -u your_user -D your_database_name -e &amp;quot;DROP TABLE @@&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See more from: http://stackoverflow.com/questions/456751/drop-mysql-databases-matching-some-wildcard&lt;br /&gt;
&lt;br /&gt;
==== Copy Multiple Tables Using Linux Shell Scripting ====&lt;br /&gt;
&lt;br /&gt;
Execute a SQL query to get the wanted table names, e.g.&lt;br /&gt;
 SHOW TABLES LIKE 'phpbb_%';&lt;br /&gt;
&lt;br /&gt;
Save table names to text file:&lt;br /&gt;
 vim tablenames.txt&lt;br /&gt;
&lt;br /&gt;
Execute shell command to get the right queries. Pipe table names through &amp;lt;code&amp;gt;xargs&amp;lt;/code&amp;gt; which takes each line in the list of table names, and inserts it in the &amp;quot;@@&amp;quot; part in the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat tablenames.txt | &lt;br /&gt;
  xargs -I &amp;quot;@@&amp;quot; echo &amp;quot;CREATE TABLE drupal6.dr_@@ LIKE drupal5bu.@@; INSERT INTO drupal6.dr_@@ SELECT * FROM drupal5bu.@@;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can execute sql queries straight to sql-server by removing &amp;quot;echo&amp;quot;-part and adding mysql commands, e.g.&lt;br /&gt;
 mysql -u root -D database_name -e &amp;quot;sql query;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== Rename Table ====&lt;br /&gt;
&lt;br /&gt;
 RENAME TABLE `drupal6`.`dr_imagecache_action_bak` TO `drupal6`.`dr_imagecache_action` ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Print Table Names ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW TABLES; #print tables from current database&lt;br /&gt;
SHOW TABLES FROM drupal622; #show table names from specific database&lt;br /&gt;
SELECT table_name FROM information_schema.tables WHERE table_schema = 'drupal622'; #get table names from information_schema database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Columns ===&lt;br /&gt;
&lt;br /&gt;
==== Edit column ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE `dr_url_alias` CHANGE `language` `language` VARCHAR( 12 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'exampledefaultvalue'&lt;br /&gt;
ALTER TABLE dr_imagecache_preset CHANGE presetid presetid int(10) UNSIGNED NOT NULL AUTO_INCREMENT&lt;br /&gt;
ALTER TABLE `dr_content_node_field` CHANGE `db_storage` `db_storage` TINYINT NOT NULL DEFAULT 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add Column ====&lt;br /&gt;
&lt;br /&gt;
Add it as a first column in table with &amp;lt;code&amp;gt;FIRST&amp;lt;/code&amp;gt; word at the end of sql.&lt;br /&gt;
 ALTER TABLE `dr_permission` ADD `pid` INT( 11 ) NOT NULL AUTO_INCREMENT FIRST&lt;br /&gt;
&lt;br /&gt;
Add timestamp column (int) after starttime column&lt;br /&gt;
 ALTER TABLE `sportlog` ADD `timestamp` INT NOT NULL AFTER `starttime`&lt;br /&gt;
&lt;br /&gt;
Add multiple columns:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE `content_type_youtube_video`&lt;br /&gt;
  ADD COLUMN `field_youtube_video_status` int(10) unsigned NOT NULL DEFAULT '1',&lt;br /&gt;
  ADD COLUMN `field_youtube_video_version` int(10) unsigned NOT NULL DEFAULT '0';&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indexes ===&lt;br /&gt;
&lt;br /&gt;
Index types: primary, index, unique, fulltext&lt;br /&gt;
&lt;br /&gt;
==== Definition ====&lt;br /&gt;
&lt;br /&gt;
* Primary key&lt;br /&gt;
* Unique key (combination of three columns?)&lt;br /&gt;
* Key (Normal key to make data search from the table faster)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PRIMARY KEY (`pid`),&lt;br /&gt;
UNIQUE KEY `dst_language_pid` (`dst`,`language`,`pid`),&lt;br /&gt;
KEY `src_language_pid` (`src`,`language`,`pid`)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add Index ====&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_users_roles` ADD INDEX ( `rid` )&lt;br /&gt;
&lt;br /&gt;
==== Add Unique Index ====&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_contemplate_files` ADD UNIQUE (`site`) &lt;br /&gt;
&lt;br /&gt;
==== Remove Index ====&lt;br /&gt;
&lt;br /&gt;
You might want to remove one of the duplicate indicies, e.g. if you get following message in MySQLAdmin: &amp;quot;The following indexes appear to be equal and one of them should be removed: site_2, site&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_contemplate_files` DROP INDEX `site_2`&lt;br /&gt;
&lt;br /&gt;
==== Update Index ====&lt;br /&gt;
&lt;br /&gt;
To rename indexes you have to recreate the index&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_contemplate_files` DROP INDEX `site_2` ,&lt;br /&gt;
 ADD UNIQUE `site` ( `site` )&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
&lt;br /&gt;
[[MySQL_Server#Views]]&lt;br /&gt;
&lt;br /&gt;
=== Backup database using mysqldump tool ===&lt;br /&gt;
&lt;br /&gt;
[[Mysqldump]]&lt;br /&gt;
&lt;br /&gt;
=== Backup database using phpMyAdmin web ui ===&lt;br /&gt;
&lt;br /&gt;
Type e.g. URL http://localhost/phpmyadmin in your browser and choose:&lt;br /&gt;
&lt;br /&gt;
* databases --&amp;gt; export&lt;br /&gt;
* Export format: SQL&lt;br /&gt;
* Save as file (e.g. gzipped)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Restore / Import Database ===&lt;br /&gt;
&lt;br /&gt;
'''Restore database from a file'''&lt;br /&gt;
 mysql -u root -p drupal6 &amp;lt; /root/Desktop/drupal6_20100912.sql&lt;br /&gt;
&lt;br /&gt;
If you get following error message:&lt;br /&gt;
&amp;lt;code&amp;gt;ERROR 1049 (42000): Unknown database 'drupal6'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...you have to create the database before restoring:&lt;br /&gt;
 mysql -u root -p -e 'CREATE DATABASE drupal6;'&lt;br /&gt;
&lt;br /&gt;
'''Restore compressed backup file'''&lt;br /&gt;
 gunzip &amp;lt; drupal6_bu_20110126.sql.gz | mysql -u root -p drupal6&lt;br /&gt;
&lt;br /&gt;
=== Restore Table ===&lt;br /&gt;
&lt;br /&gt;
'''Restore single database table from a file'''&lt;br /&gt;
 mysql -u root -p drupal6 &amp;lt; /root/Desktop/users.sql&lt;br /&gt;
&lt;br /&gt;
'''Restore compressed backup file (zip or lzip)'''&lt;br /&gt;
 gunzip &amp;lt; users.sql.gz | mysql -u root -p drupal6&lt;br /&gt;
 lzip -d &amp;lt; /var/backups/users.sql.lz | mysql -u root -p drupal6 (note! unpacks the file and removes .lz file!)&lt;br /&gt;
 lzip -d --keep &amp;lt; /var/backups/users.sql.lz | mysql -u root -p drupal6 (note! keeps .lz file, without leaving uncompressed file)&lt;br /&gt;
&lt;br /&gt;
=== Manage database users ===&lt;br /&gt;
&lt;br /&gt;
==== Show All Users ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT User,Host FROM mysql.user;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== GRANT / Create User ====&lt;br /&gt;
&lt;br /&gt;
Create example user (if doesn't exist?) and give all permissions to example database&lt;br /&gt;
 GRANT ALL PRIVILEGES ON `exampledatabase`.* TO 'exampleuser'@'localhost';&lt;br /&gt;
Create example user and give all permissions to example database and assign a password&lt;br /&gt;
 GRANT ALL ON exampledatabase.* TO exampleuser@localhost IDENTIFIED BY &amp;quot;examplepassword&amp;quot;;&lt;br /&gt;
Give example user selected permissions to drupal6_bu database&lt;br /&gt;
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `drupal6\_bu`.* TO 'exampleuser'@'182.128.10.2';&lt;br /&gt;
&lt;br /&gt;
Related error messages:&lt;br /&gt;
 Error: SELECT command denied to user 'drupal'@'www.site.com' for table 'url_alias'&lt;br /&gt;
&lt;br /&gt;
==== REVOKE ====&lt;br /&gt;
&lt;br /&gt;
Revoke all permissions and grant right from example user to example database&lt;br /&gt;
 REVOKE ALL PRIVILEGES ON `exampledatabase`.* FROM exampleuser@localhost;&lt;br /&gt;
 REVOKE GRANT OPTION ON `exampledatabase`.* FROM 'exampleuser'@'localhost';&lt;br /&gt;
 REVOKE DROP ON `exampledatabase`.* FROM 'exampleuser'@'localhost';&lt;br /&gt;
&lt;br /&gt;
==== DELETE USER ====&lt;br /&gt;
&lt;br /&gt;
 DROP USER exampleUser@localhost&lt;br /&gt;
&lt;br /&gt;
=== Check The Size Of Your Databases ===&lt;br /&gt;
&lt;br /&gt;
Execute the following query to your SQL Server:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema 'Database name', sum( data_length + index_length ) / 1024 / 1024 'Database size (MB)'&lt;br /&gt;
 FROM information_schema.TABLES GROUP BY table_schema&lt;br /&gt;
&lt;br /&gt;
=== Check Database Table Information, e.g. Size (Show Table Info) ===&lt;br /&gt;
&lt;br /&gt;
* Show table information. In addition to table size it shows also a lot of other information related to tables, e.g. table's mysql engine, update time if MyISAM&lt;br /&gt;
columns: Name, Engine, Version, Row_format, Rows, Avg_row_length, Data_length, Max_data_length, Index_length, Data_free, Auto_increment, Create_time, Update_time, Check_time, Collation, Checksum, Create_options, Comment&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW TABLE STATUS&lt;br /&gt;
SHOW TABLE STATUS LIKE 'sessions'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More &amp;lt;code&amp;gt;SHOW&amp;lt;/code&amp;gt; commands: http://dev.mysql.com/doc/refman/5.1/en/show.html&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=SQL&amp;diff=33</id>
		<title>SQL</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=SQL&amp;diff=33"/>
		<updated>2021-03-26T22:37:56Z</updated>

		<summary type="html">&lt;p&gt;Creator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQL and MySQL queries ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Select ===&lt;br /&gt;
&lt;br /&gt;
==== ROW_COUNT / Affected Rows ====&lt;br /&gt;
&lt;br /&gt;
 SELECT ROW_COUNT();&lt;br /&gt;
ROW_COUNT() returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE, DELETE, or INSERT. For other statements, the value may not be meaningful.&lt;br /&gt;
&lt;br /&gt;
==== Concatenate ====&lt;br /&gt;
&lt;br /&gt;
 SELECT CONCAT('Rows affected: ',ROW_COUNT()) AS 'Affected Rows';&lt;br /&gt;
&lt;br /&gt;
==== CASE ====&lt;br /&gt;
&lt;br /&gt;
Case Expression / conditional statement / if statement&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT CASE WHEN columnZ &amp;lt;&amp;gt; 0 THEN 4&lt;br /&gt;
            WHEN columnY &amp;lt;&amp;gt; 0 THEN 3&lt;br /&gt;
            WHEN columnX &amp;lt;&amp;gt; 0 THEN 2&lt;br /&gt;
            WHEN columnW &amp;lt;&amp;gt; 0 THEN 1&lt;br /&gt;
            ELSE 0&lt;br /&gt;
       END AS your_alias_name&lt;br /&gt;
FROM ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT u.name,&lt;br /&gt;
  up.points,&lt;br /&gt;
  CASE WHEN u.access &amp;lt;&amp;gt; 0 THEN FROM_UNIXTIME(u.access) ELSE '' END AS 'Last activity on site',&lt;br /&gt;
FROM userpoints up INNER JOIN users u ON up.uid = u.uid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sort ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Joins ===&lt;br /&gt;
&lt;br /&gt;
MySQL cases (can apply to MS SQL also, but not confirmed yet).&lt;br /&gt;
&lt;br /&gt;
Different &amp;lt;code&amp;gt;JOIN&amp;lt;/code&amp;gt; types:&lt;br /&gt;
* '''JOIN''' or '''INNER JOIN''': Return rows when there is at least one match in both tables&lt;br /&gt;
* '''LEFT JOIN''': Return all rows from the left table, even if there are no matches in the right table&lt;br /&gt;
* '''RIGHT JOIN''': Return all rows from the right table, even if there are no matches in the left table&lt;br /&gt;
* '''FULL JOIN''': Return rows when there is a match in one of the tables&lt;br /&gt;
&lt;br /&gt;
Example data:&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse; float: left;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;5&amp;quot; | Persons table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;text-align: left;&amp;quot; | P_Id&lt;br /&gt;
!Lastname&lt;br /&gt;
!Firstname&lt;br /&gt;
!Address&lt;br /&gt;
!City&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Hansen&lt;br /&gt;
|Ola&lt;br /&gt;
|Timoteivn 10&lt;br /&gt;
| Sandnes&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|Svendson&lt;br /&gt;
|Tove&lt;br /&gt;
|Borgvn 23&lt;br /&gt;
| Sandnes&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Pettersen&lt;br /&gt;
|Kari&lt;br /&gt;
|Storgt 20&lt;br /&gt;
|Stavanger&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border-collapse: collapse; border: 1px solid #000000; margin-left: 340px;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; | Orders table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | O_Id&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | OrderNo&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | P_Id&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 1&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 77895&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 2&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 44678&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 3&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 22456&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 24562&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 5&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 34764&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== INNER JOIN ====&lt;br /&gt;
&lt;br /&gt;
INNER JOIN is same as JOIN. As a matter of fact INNER JOIN is a default type of JOIN and that's why you don't have to include INNER keyword. Returns rows when there is at least one match in both tables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
INNER JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The result-set will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola     24562&lt;br /&gt;
Hansen    Ola     22456&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Other examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT mes.*, ind.uid&lt;br /&gt;
FROM pm_message mes&lt;br /&gt;
INNER JOIN pm_index ind ON mes.mid = ind.mid&lt;br /&gt;
WHERE ind.uid = 1234&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LEFT JOIN ====&lt;br /&gt;
&lt;br /&gt;
The LEFT JOIN keyword returns all rows from the left table (first table), even if there are no matches in the right table (table to join).&lt;br /&gt;
&lt;br /&gt;
'''Note!''' In some databases LEFT JOIN is called LEFT OUTER JOIN. In MySQL LEFT OUTER JOIN is equal to LEFT JOIN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
LEFT JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result-set will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola     22456&lt;br /&gt;
Hansen    Ola   24562&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
Svendson  Tove    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RIGHT JOIN ====&lt;br /&gt;
&lt;br /&gt;
The RIGHT JOIN keyword returns all the rows from the right table (second table), even if there are no matches in the left table (first table).&lt;br /&gt;
&lt;br /&gt;
'''Note!''' In some databases RIGHT JOIN is called RIGHT OUTER JOIN. In MySQL RIGHT OUTER JOIN is equal to RIGHT JOIN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
RIGHT JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result-set will look like this (all the orders with containing persons - if any):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
            34764&lt;br /&gt;
Hansen    Ola   22456&lt;br /&gt;
Hansen    Ola   24562&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FULL JOIN ====&lt;br /&gt;
&lt;br /&gt;
The FULL JOIN keyword return rows when there is a match in one of the tables. FULL JOIN = FULL OUTER JOIN.&lt;br /&gt;
* '''Note!''' MySQL lacks support for FULL OUTER JOIN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
FULL JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola   22456&lt;br /&gt;
Hansen    Ola     24562&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
Svendson  Tove   &lt;br /&gt;
            34764&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With '''MySQL''' you can mitigate the FULL JOIN by using LEFT JOIN, RIGHT JOIN and UNION together.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT p.LastName, p.FirstName, o.OrderNo&lt;br /&gt;
FROM persons p&lt;br /&gt;
LEFT JOIN orders o ON p.P_Id = o.P_Id&lt;br /&gt;
UNION&lt;br /&gt;
SELECT p.LastName, p.FirstName, o.OrderNo&lt;br /&gt;
FROM persons p&lt;br /&gt;
RIGHT JOIN orders o ON p.P_Id = o.P_Id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola   22456&lt;br /&gt;
Hansen    Ola     24562&lt;br /&gt;
Svendson  Tove    &lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
        34764&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNION ====&lt;br /&gt;
&lt;br /&gt;
The UNION operator is used to combine the result-set of two or more SELECT statements.&lt;br /&gt;
&lt;br /&gt;
Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.&lt;br /&gt;
&lt;br /&gt;
SQL UNION Syntax&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT column_name(s) FROM table_name1&lt;br /&gt;
UNION&lt;br /&gt;
SELECT column_name(s) FROM table_name2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Note: The '''UNION''' operator selects only '''distinct values''' by default. To allow duplicate values, use '''UNION ALL'''. The column names in the result-set of a UNION are always equal to the column names in the first SELECT statement in the UNION.&lt;br /&gt;
&lt;br /&gt;
Example data:&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse; float: left;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; | Employees_Norway table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;text-align: left;&amp;quot; | E_ID&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | E_Name&lt;br /&gt;
|-&lt;br /&gt;
|01&lt;br /&gt;
|Hansen, Ola&lt;br /&gt;
|-&lt;br /&gt;
|02&lt;br /&gt;
|Svendson, Tove&lt;br /&gt;
|-&lt;br /&gt;
|03&lt;br /&gt;
|Svendson, Stephen&lt;br /&gt;
|-&lt;br /&gt;
|04&lt;br /&gt;
|Pettersen, Kari&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse; margin-left: 190px;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; | Employees_USA table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;text-align: left;&amp;quot; | E_ID&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | E_Name&lt;br /&gt;
|-&lt;br /&gt;
|01&lt;br /&gt;
|Turner, Sally&lt;br /&gt;
|-&lt;br /&gt;
|02&lt;br /&gt;
|Kent, Clark&lt;br /&gt;
|-&lt;br /&gt;
|03&lt;br /&gt;
|Svendson, Stephen&lt;br /&gt;
|-&lt;br /&gt;
|04&lt;br /&gt;
|Scott, Stephen&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* List '''all the different employees''' in Norway and USA&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT E_Name FROM Employees_Norway&lt;br /&gt;
UNION&lt;br /&gt;
SELECT E_Name FROM Employees_USA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result-set will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
E_Name&lt;br /&gt;
Hansen, Ola&lt;br /&gt;
Svendson, Tove&lt;br /&gt;
Svendson, Stephen&lt;br /&gt;
Pettersen, Kari&lt;br /&gt;
Turner, Sally&lt;br /&gt;
Kent, Clark&lt;br /&gt;
Scott, Stephen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note''': Only distinct employee names are shown.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* List '''all employees''' in Norway and USA&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT E_Name FROM Employees_Norway&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT E_Name FROM Employees_USA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
E_Name&lt;br /&gt;
Hansen, Ola&lt;br /&gt;
Svendson, Tove&lt;br /&gt;
Svendson, Stephen&lt;br /&gt;
Pettersen, Kari&lt;br /&gt;
Turner, Sally&lt;br /&gt;
Kent, Clark&lt;br /&gt;
Svendson, Stephen&lt;br /&gt;
Scott, Stephen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note''': Showing all names (Svendson, Stephen x 2).&lt;br /&gt;
&lt;br /&gt;
=== GROUP BY ===&lt;br /&gt;
&lt;br /&gt;
Select how many comments each users have made and sort those descending&lt;br /&gt;
 SELECT uid, COUNT(uid) AS commentcount FROM comments GROUP BY uid ORDER BY commentcount DESC&lt;br /&gt;
&lt;br /&gt;
=== IN Clause Order ===&lt;br /&gt;
&lt;br /&gt;
Result set won't be in the same order than IN-clause's ids:&lt;br /&gt;
 SELECT topic_id, topic_title from phpbb_topics where topic_id IN(5435, 23, 324)&lt;br /&gt;
&lt;br /&gt;
Result set will be ordered as you like:&lt;br /&gt;
 SELECT topic_id, topic_title from phpbb_topics where topic_id IN(5435, 23, 324) ORDER BY FIND_IN_SET(topic_id, '23,324,5435')&lt;br /&gt;
&lt;br /&gt;
=== Substring ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTRING('Quadratically',5); // prints 'ratically'&lt;br /&gt;
SELECT SUBSTRING('foobarbar' FROM 4); // prints 'barbar'&lt;br /&gt;
SELECT SUBSTRING('Quadratically',5,6); // prints 'ratica'&lt;br /&gt;
SELECT SUBSTRING('Sakila', -3); // prints 'ila'&lt;br /&gt;
SELECT SUBSTRING('Sakila', -5, 3); // prints 'aki'&lt;br /&gt;
SELECT SUBSTRING('Sakila' FROM -4 FOR 2); // prints 'ki'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Update ===&lt;br /&gt;
&lt;br /&gt;
Update with replace:&lt;br /&gt;
Replace url_alias table's dst column's all 'forums' words with 'keskustelu'&lt;br /&gt;
 UPDATE url_alias SET dst = REPLACE(dst, 'forums', 'keskustelu')&lt;br /&gt;
&lt;br /&gt;
Update with subquery:&lt;br /&gt;
 UPDATE `gsmvalidation` SET confirmedtime = (SELECT NOW())&lt;br /&gt;
 WHERE id = (SELECT id FROM (SELECT id,uid,codesended from `gsmvalidation`) AS temp WHERE uid = 1 ORDER BY `codesended` DESC LIMIT 1)&lt;br /&gt;
&lt;br /&gt;
=== Insert ===&lt;br /&gt;
&lt;br /&gt;
Insert single row:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO `drupal6`.`url_alias` (&lt;br /&gt;
`pid` ,&lt;br /&gt;
`src` ,&lt;br /&gt;
`dst` ,&lt;br /&gt;
`language`&lt;br /&gt;
)&lt;br /&gt;
VALUES (&lt;br /&gt;
NULL , 'phpbbforum/index.php', 'forums/index.php', ''&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insert multiple rows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO url_alias (src, dst)&lt;br /&gt;
VALUES&lt;br /&gt;
('phpbbforum','forums'),&lt;br /&gt;
('phpbbforum/index.php', 'forums/index.php'),&lt;br /&gt;
('phpbbforum/viewtopic.php', 'forums/viewtopic.php');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insert all rows from other table after emptying the destination table first:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TRUNCATE TABLE drupal622.dr_access;&lt;br /&gt;
INSERT INTO drupal622.dr_access SELECT * FROM drupal510.access;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Custom insert (there's no language column in source table):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO drupal622.dr_url_alias (pid,src,dst,language) SELECT pid,src,dst,'' FROM drupal510.url_alias&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Delete ===&lt;br /&gt;
&lt;br /&gt;
 DELETE FROM Persons WHERE LastName = 'Smith'&lt;br /&gt;
&lt;br /&gt;
=== Time and date ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Convert timestamp to date'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT u.created FROM users u // 1346693013&lt;br /&gt;
SELECT FROM_UNIXTIME(u.created) as 'User created' FROM users u // 2012-09-03 18:23:33&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(u.created)) as 'User created' FROM users u // 2012-09-03&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Convert date to timestamp'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT UNIX_TIMESTAMP('2012-08-01') // 1343775600&lt;br /&gt;
SELECT UNIX_TIMESTAMP('2012-08-01 01:02:03') //1343779323&lt;br /&gt;
// post_time = timestamp&lt;br /&gt;
SELECT * FROM phpbb_posts WHERE post_time BETWEEN UNIX_TIMESTAMP('2012-08-01') AND UNIX_TIMESTAMP('2012-09-05')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert datetime field values (CAST &amp;amp; DATE_FORMAT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT confirmedtime FROM gsm WHERE uid = 1 //2010-10-27 14:58:39&lt;br /&gt;
SELECT CAST(confirmedtime AS DATE) AS confirmedtime FROM gsm WHERE uid = 1 //2010-10-27&lt;br /&gt;
SELECT CAST('2012-09-04' AS DATETIME) // 2012-09-04 00:00:00&lt;br /&gt;
SELECT CAST('2012-09-04' AS DATE) // 2012-09-04&lt;br /&gt;
SELECT DATE_FORMAT(confirmedtime,'%d.%m.%Y') AS confirmedtime FROM gsm WHERE uid = 1 //27.10.2010&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select current datetime or timestamp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT NOW()     -- 2010-09-09 08:54:53&lt;br /&gt;
SELECT CURDATE() -- 2010-09-09&lt;br /&gt;
SELECT CURTIME() -- 08:55:35&lt;br /&gt;
SELECT UNIX_TIMESTAMP(NOW()) -- 1314961714&lt;br /&gt;
SELECT UNIX_TIMESTAMP('2005-03-27 02:00:00') -- 1111885200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select something where date is 2012-09-04&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// userdata is in following format (timestamp-id): 1346746755-193&lt;br /&gt;
// two hours is added to timestamp to get Finnish time (GMT+2)&lt;br /&gt;
WHERE DATE(FROM_UNIXTIME((SELECT SUBSTRING(userdata, 1,10)+7200))) = CAST('2012-09-04' AS DATE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Minus 1 day from current time for begintime field and add 20 years to endtime field&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT DATE_SUB(NOW(), INTERVAL 1 DAY), DATE_ADD(`endtime`, INTERVAL 20 YEAR)&lt;br /&gt;
FROM `publishdates`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update rows which don't have publish from value (startpublish_value). new value this time - 2 days.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UPDATE `publishdates`&lt;br /&gt;
SET `startpublish` = DATE_SUB(NOW(), INTERVAL 2 DAY)&lt;br /&gt;
WHERE `startpublish` IS NULL OR `field_startpublish_value` = '0000-00-00 00:00:00'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insert data to datetime (YYYY-mm-dd H:i:s) and date formatted fields&lt;br /&gt;
 INSERT INTO logs (datetime,date) VALUES ('2005-06-12 23:56:25', '2005-06-12');&lt;br /&gt;
&lt;br /&gt;
If you are using a DATE_FORMAT function to format date e.g. '%d.%m.%Y' and use variable placeholders e.g. %f, '%s' in same sql, you have to add DATE_FORMAT parameters through variable placeholder. Otherwise day %d takes the first variables value. Right way to do it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$dateFormat = &amp;quot;%d.%m.%Y&amp;quot;;&lt;br /&gt;
$gsmValidated = db_fetch_object(db_query(&amp;quot;SELECT DATE_FORMAT(confirmedtime, '%s') AS confirmedtime FROM gsmvalidation WHERE uid = %f AND gsmtoconfirm = '%s' AND confirmedtime != '' ORDER BY `confirmedtime` DESC LIMIT 1&amp;quot;, $dateFormat, $uid, $gsmnumberStr));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
cast and between&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// $D1 and $D2 are posted variables in PHP&lt;br /&gt;
SELECT * FROM Sales WHERE TransactionDate BETWEEN CAST('$D1' as DATETIME) and CAST($D2 as DATETIME)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Auto Increment Values ===&lt;br /&gt;
&lt;br /&gt;
==== Show Next Value ====&lt;br /&gt;
&lt;br /&gt;
Show next autoincrement value from files-table (check Auto_increment column):&lt;br /&gt;
 SHOW TABLE STATUS LIKE 'files'&lt;br /&gt;
or better way to do it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT AUTO_INCREMENT FROM information_schema.tables&lt;br /&gt;
WHERE table_name = 'files'&lt;br /&gt;
AND table_schema = 'drupal6'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or show each tables' auto_increment values:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT table_name, AUTO_INCREMENT FROM information_schema.tables&lt;br /&gt;
WHERE AUTO_INCREMENT IS NOT NULL AND table_schema = 'drupal6'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or select highest autoincrement value and add 1 to it:&lt;br /&gt;
 SELECT MAX(fid)+1 FROM 'files'&lt;br /&gt;
* Note: If someone inserted new row after your query the next id is not up to date anymore. That happens also if the row with max id have been deleted.&lt;br /&gt;
&lt;br /&gt;
==== Show Updated Row's Auto Increment ID Value ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO 'files' ('fid', 'filename') VALUES ('','image.jpg');&lt;br /&gt;
SELECT LAST_INSERT_ID();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reset Autoincrement Value ====&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE visitors AUTO_INCREMENT = 1&lt;br /&gt;
&lt;br /&gt;
If the highest value for the column is already greater than new auto-increment value then it will be set to the highest value plus 1&lt;br /&gt;
&lt;br /&gt;
=== Replace ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
REPLACE('where_to_look', 'what_to_look', 'the_replacement')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select name and age. Convert the age column to number and replace 'years' string and whitespaces.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT name, CONVERT(INT, REPLACE(REPLACE(age, 'years', ''), ' ', '')) AS age&lt;br /&gt;
FROM persons&lt;br /&gt;
ORDER BY age DESC&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update (limit to 10) nodes_revisions table's body fields content. Change readfile paths from &amp;lt;code&amp;gt;/var/www/html/&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/srv/www/docroot/&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UPDATE node_revisions&lt;br /&gt;
SET body = REPLACE(body, '/var/www/html/', '/srv/www/docroot/')&lt;br /&gt;
WHERE body LIKE '%readfile(\'/var/www%'&lt;br /&gt;
LIMIT 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Convert And Cast ===&lt;br /&gt;
&lt;br /&gt;
==== Convert String Into a Number ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- content string is 1346761037-192&lt;br /&gt;
SELECT CAST(SUBSTRING(content, 12) AS UNSIGNED INTEGER) AS theID&lt;br /&gt;
SELECT CONVERT(SUBSTRING(content, 12), SIGNED INTEGER) AS theID&lt;br /&gt;
SELECT SUBSTRING(content, 12) * 1 AS theID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Convert BLOB Into a String ====&lt;br /&gt;
&lt;br /&gt;
 SELECT CONVERT(exampleColumn USING utf8) AS exampleColumn FROM exampleTable&lt;br /&gt;
&lt;br /&gt;
* In PhpMyAdmin you can also:&lt;br /&gt;
** download the blob data, by clicking e.g. [BLOB - 6B] link (activates download), downloading it to your computer and opening it with text editor.&lt;br /&gt;
** select &amp;quot;+ Options&amp;quot; from browse data mode and select &amp;lt;code&amp;gt;Show BLOB contents&amp;lt;/code&amp;gt; checkbox.&lt;br /&gt;
&lt;br /&gt;
==== Search String From BLOB ====&lt;br /&gt;
&lt;br /&gt;
BLOB data is stored as a binary data thus it's case sensitive. You can make a case sensitive query by (returns only 'The'):&lt;br /&gt;
 SELECT * FROM `dr_locales_source` WHERE source LIKE '%The%'&lt;br /&gt;
&lt;br /&gt;
If you want to make case-insensitive comparison (e.g. The, the, thE), you can convert BLOB to string using utf8 encoding:&lt;br /&gt;
 SELECT * FROM `dr_locales_source` WHERE CONVERT(source USING UTF8) LIKE '%The%'&lt;br /&gt;
&lt;br /&gt;
=== NULL ===&lt;br /&gt;
&lt;br /&gt;
Find NULL values:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT * FROM USERS&lt;br /&gt;
WHERE 'middle_name' IS NULL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find values different than NULL:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT * FROM USERS&lt;br /&gt;
WHERE 'middle_name' IS NOT NULL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Explain ===&lt;br /&gt;
&lt;br /&gt;
* Good source: http://www.slideshare.net/phpcodemonkey/mysql-explain-explained&lt;br /&gt;
&lt;br /&gt;
Tool to optimize queries. The '''EXPLAIN''' statement can be used either as a way to obtain information about how MySQL executes a statement, or as a synonym for '''DESCRIBE'''.&lt;br /&gt;
&lt;br /&gt;
Get details of the table:&lt;br /&gt;
 EXPLAIN drupal7.node_revision&lt;br /&gt;
 DESCRIBE drupal7.node_revision&lt;br /&gt;
&lt;br /&gt;
Obtain information about the query:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
EXPLAIN SELECT n.nid, n.title, n.type, frb.body_value, nr . *&lt;br /&gt;
FROM node n&lt;br /&gt;
JOIN node_revision nr ON n.nid = nr.nid&lt;br /&gt;
JOIN field_revision_body frb ON n.nid = frb.entity_id&lt;br /&gt;
ORDER BY n.nid DESC&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''EXPLAIN EXTENDED''' can be used to obtain additional information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
EXPLAIN EXTENDED SELECT n.nid, n.title&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A good way to keep up to date which queries need optimization and further investigation with &amp;lt;code&amp;gt;EXPLAIN&amp;lt;/code&amp;gt; statement is to enable '''MySQL's Slow Query Log'''&lt;br /&gt;
&lt;br /&gt;
* Use the mysqladmin command line tool to identify more general problems. The Following query will show mysql server's extended status information and updates it every 10 seconds.&lt;br /&gt;
 mysqladmin -u dbuser -p -r -i 10 extended-status&lt;br /&gt;
&lt;br /&gt;
Example: Booking application schema&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;4&amp;quot; | attendees table&lt;br /&gt;
|-&lt;br /&gt;
!attendee_id&lt;br /&gt;
!surname&lt;br /&gt;
!conference_id&lt;br /&gt;
!registration_status&lt;br /&gt;
|-&lt;br /&gt;
| INTEGER (PK)&lt;br /&gt;
| VARCHAR&lt;br /&gt;
| INTEGER(FK)&lt;br /&gt;
| TINYINT&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;4&amp;quot; | conferences table&lt;br /&gt;
|-&lt;br /&gt;
!conference_id&lt;br /&gt;
!location_id&lt;br /&gt;
!topic_id&lt;br /&gt;
!date&lt;br /&gt;
|-&lt;br /&gt;
| INTEGER (PK)&lt;br /&gt;
| INTEGER(FK)&lt;br /&gt;
| INTEGER(FK)&lt;br /&gt;
| DATE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
EXPLAIN SELECT * FROM attendees WHERE conference_id = 123 AND registration_status &amp;gt; 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''possible_keys''' - All possible indicies mysql could use. Query will choose the best one of the availeble ones (if any).&lt;br /&gt;
* '''key''' - The chosen index key for the query. If NULL, no useful index was found --&amp;gt; query needs to be optimized.&lt;br /&gt;
* '''rows''' - All the rows needed to scan for your query&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
!table&lt;br /&gt;
!possible_keys&lt;br /&gt;
!key&lt;br /&gt;
!rows&lt;br /&gt;
|-&lt;br /&gt;
|attendees&lt;br /&gt;
|NULL&lt;br /&gt;
|NULL&lt;br /&gt;
|14052&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conclusion:&lt;br /&gt;
* No suitable indexes found for this query&lt;br /&gt;
* Mysql had to do a full table scan (almost always the slowest query)&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE ADD INDEX conf (conference_id);&lt;br /&gt;
 ALTER TABLE ADD INDEX reg (registration_status);&lt;br /&gt;
 EXPLAIN SELECT * FROM attendees WHERE conference_id = 123 AND registration_status &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
!table&lt;br /&gt;
!possible_keys&lt;br /&gt;
!key&lt;br /&gt;
!rows&lt;br /&gt;
|-&lt;br /&gt;
|attendees&lt;br /&gt;
|conf,reg&lt;br /&gt;
|conf&lt;br /&gt;
|331&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* Mysql chose the more unique index '''conf''' and had to scan only 331 rows compared to previous full table scan with 14052 rows&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Databases ===&lt;br /&gt;
&lt;br /&gt;
==== Create a Database ====&lt;br /&gt;
&lt;br /&gt;
===== mysql Commandline Tool =====&lt;br /&gt;
&lt;br /&gt;
First access the MySQL server&lt;br /&gt;
 mysql -u root -p&lt;br /&gt;
&lt;br /&gt;
Create database&lt;br /&gt;
 CREATE DATABASE exampledatabase;&lt;br /&gt;
&lt;br /&gt;
If you want to grant permissions also for someone else than root user&lt;br /&gt;
 GRANT ALL ON exampledatabase.* TO exampleuser@localhost IDENTIFIED BY &amp;quot;examplepassword&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Exit mysql admin&lt;br /&gt;
 quit&lt;br /&gt;
&lt;br /&gt;
You can now test login with previously specified user&lt;br /&gt;
 mysql -u exampleuser -p&lt;br /&gt;
&lt;br /&gt;
Check if you see the right databases&lt;br /&gt;
 SHOW DATABASES;&lt;br /&gt;
&lt;br /&gt;
==== Select a Database ====&lt;br /&gt;
&lt;br /&gt;
 USE exampledatabase;&lt;br /&gt;
&lt;br /&gt;
==== Delete / Drop a Database ====&lt;br /&gt;
&lt;br /&gt;
 DROP DATABASE `phpbb3seo`&lt;br /&gt;
Note! MySQL won't free the space after database is deleted. Instead of that it will reuse the space later when new data is added. File is probably: /var/lib/mysql/ibdata1.&lt;br /&gt;
* To shrink the size you will need to dump all databases and then restore them again.&lt;br /&gt;
* You can also do the following: Set innodb_file_per_table in your config file, which will create a separate file per table. That will then allow you to delete these files once a database is dropped and also allow you to use the OPTIMIZE TABLE command to rebuild ibd files if you shrink the data in a particular table.&lt;br /&gt;
&lt;br /&gt;
=== Tables ===&lt;br /&gt;
&lt;br /&gt;
[[MySQL_Server#MySQL_Datatypes | MySQL Datatypes]]&lt;br /&gt;
&lt;br /&gt;
==== Create a Table ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `url_alias` (&lt;br /&gt;
  `pid` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `src` varchar(128) NOT NULL DEFAULT '',&lt;br /&gt;
  `dst` varchar(128) NOT NULL DEFAULT '',&lt;br /&gt;
  `language` varchar(12) NOT NULL DEFAULT '',&lt;br /&gt;
  PRIMARY KEY (`pid`),&lt;br /&gt;
  UNIQUE KEY `dst_language_pid` (`dst`,`language`,`pid`),&lt;br /&gt;
  KEY `src_language_pid` (`src`,`language`,`pid`)&lt;br /&gt;
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=35;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a Temporary Table ====&lt;br /&gt;
&lt;br /&gt;
todo&lt;br /&gt;
&lt;br /&gt;
==== Copy a Table ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE `drupal6`.`permission_bak` (&lt;br /&gt;
`pid` int( 11 ) NOT NULL AUTO_INCREMENT ,&lt;br /&gt;
`rid` int( 10 ) unsigned NOT NULL DEFAULT '0',&lt;br /&gt;
`perm` longtext,&lt;br /&gt;
`tid` int( 10 ) unsigned NOT NULL DEFAULT '0',&lt;br /&gt;
PRIMARY KEY ( `pid` ) ,&lt;br /&gt;
KEY `rid` ( `rid` )&lt;br /&gt;
) ENGINE = MYISAM DEFAULT CHARSET = utf8;&lt;br /&gt;
&lt;br /&gt;
INSERT INTO `drupal6`.`permission_bak`&lt;br /&gt;
SELECT *&lt;br /&gt;
FROM `drupal6`.`permission` ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete/drop Table ====&lt;br /&gt;
&lt;br /&gt;
 DROP TABLE dr_imagecache_action&lt;br /&gt;
To avoid an error message in case the table don't exist (&amp;lt;code&amp;gt;#1051 - Unknown table 'dr_imagecache_action' &amp;lt;/code&amp;gt;) use &amp;lt;code&amp;gt;IF EXISTS&amp;lt;/code&amp;gt; check:&lt;br /&gt;
 DROP TABLE IF EXISTS dr_imagecache_action&lt;br /&gt;
&lt;br /&gt;
==== Drop Multiple Tables ====&lt;br /&gt;
&lt;br /&gt;
If you want to drop multiple tables using wildcard in table name, here's solution.&lt;br /&gt;
Use &amp;lt;code&amp;gt;SHOW TABLES&amp;lt;/code&amp;gt; to get the wanted table list, e.g.&lt;br /&gt;
 SHOW TABLES LIKE 'phpbb_%';&lt;br /&gt;
&lt;br /&gt;
Then just form your remove query with resulted text:&lt;br /&gt;
 DROP TABLE phpbb_tbl1,phpbb_tbl2, phpbb_tbl3;&lt;br /&gt;
&lt;br /&gt;
If you want to do this with shell commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u your_user -D your_database_name -e &amp;quot;show tables&amp;quot; -s | &lt;br /&gt;
  egrep &amp;quot;^Whatever_&amp;quot; | &lt;br /&gt;
  xargs -I &amp;quot;@@&amp;quot; echo mysql -u your_user -D your_database_name -e &amp;quot;DROP TABLE @@&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See more from: http://stackoverflow.com/questions/456751/drop-mysql-databases-matching-some-wildcard&lt;br /&gt;
&lt;br /&gt;
==== Copy Multiple Tables Using Linux Shell Scripting ====&lt;br /&gt;
&lt;br /&gt;
Execute a SQL query to get the wanted table names, e.g.&lt;br /&gt;
 SHOW TABLES LIKE 'phpbb_%';&lt;br /&gt;
&lt;br /&gt;
Save table names to text file:&lt;br /&gt;
 vim tablenames.txt&lt;br /&gt;
&lt;br /&gt;
Execute shell command to get the right queries. Pipe table names through &amp;lt;code&amp;gt;xargs&amp;lt;/code&amp;gt; which takes each line in the list of table names, and inserts it in the &amp;quot;@@&amp;quot; part in the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat tablenames.txt | &lt;br /&gt;
  xargs -I &amp;quot;@@&amp;quot; echo &amp;quot;CREATE TABLE drupal6.dr_@@ LIKE drupal5bu.@@; INSERT INTO drupal6.dr_@@ SELECT * FROM drupal5bu.@@;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can execute sql queries straight to sql-server by removing &amp;quot;echo&amp;quot;-part and adding mysql commands, e.g.&lt;br /&gt;
 mysql -u root -D database_name -e &amp;quot;sql query;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== Rename Table ====&lt;br /&gt;
&lt;br /&gt;
 RENAME TABLE `drupal6`.`dr_imagecache_action_bak` TO `drupal6`.`dr_imagecache_action` ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Print Table Names ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW TABLES; #print tables from current database&lt;br /&gt;
SHOW TABLES FROM drupal622; #show table names from specific database&lt;br /&gt;
SELECT table_name FROM information_schema.tables WHERE table_schema = 'drupal622'; #get table names from information_schema database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Columns ===&lt;br /&gt;
&lt;br /&gt;
==== Edit column ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE `dr_url_alias` CHANGE `language` `language` VARCHAR( 12 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'exampledefaultvalue'&lt;br /&gt;
ALTER TABLE dr_imagecache_preset CHANGE presetid presetid int(10) UNSIGNED NOT NULL AUTO_INCREMENT&lt;br /&gt;
ALTER TABLE `dr_content_node_field` CHANGE `db_storage` `db_storage` TINYINT NOT NULL DEFAULT 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add Column ====&lt;br /&gt;
&lt;br /&gt;
Add it as a first column in table with &amp;lt;code&amp;gt;FIRST&amp;lt;/code&amp;gt; word at the end of sql.&lt;br /&gt;
 ALTER TABLE `dr_permission` ADD `pid` INT( 11 ) NOT NULL AUTO_INCREMENT FIRST&lt;br /&gt;
&lt;br /&gt;
Add timestamp column (int) after starttime column&lt;br /&gt;
 ALTER TABLE `sportlog` ADD `timestamp` INT NOT NULL AFTER `starttime`&lt;br /&gt;
&lt;br /&gt;
Add multiple columns:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE `content_type_youtube_video`&lt;br /&gt;
  ADD COLUMN `field_youtube_video_status` int(10) unsigned NOT NULL DEFAULT '1',&lt;br /&gt;
  ADD COLUMN `field_youtube_video_version` int(10) unsigned NOT NULL DEFAULT '0';&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indexes ===&lt;br /&gt;
&lt;br /&gt;
Index types: primary, index, unique, fulltext&lt;br /&gt;
&lt;br /&gt;
==== Definition ====&lt;br /&gt;
&lt;br /&gt;
* Primary key&lt;br /&gt;
* Unique key (combination of three columns?)&lt;br /&gt;
* Key (Normal key to make data search from the table faster)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PRIMARY KEY (`pid`),&lt;br /&gt;
UNIQUE KEY `dst_language_pid` (`dst`,`language`,`pid`),&lt;br /&gt;
KEY `src_language_pid` (`src`,`language`,`pid`)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add Index ====&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_users_roles` ADD INDEX ( `rid` )&lt;br /&gt;
&lt;br /&gt;
==== Add Unique Index ====&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_contemplate_files` ADD UNIQUE (`site`) &lt;br /&gt;
&lt;br /&gt;
==== Remove Index ====&lt;br /&gt;
&lt;br /&gt;
You might want to remove one of the duplicate indicies, e.g. if you get following message in MySQLAdmin: &amp;quot;The following indexes appear to be equal and one of them should be removed: site_2, site&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_contemplate_files` DROP INDEX `site_2`&lt;br /&gt;
&lt;br /&gt;
==== Update Index ====&lt;br /&gt;
&lt;br /&gt;
To rename indexes you have to recreate the index&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_contemplate_files` DROP INDEX `site_2` ,&lt;br /&gt;
 ADD UNIQUE `site` ( `site` )&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
&lt;br /&gt;
[[MySQL_Server#Views]]&lt;br /&gt;
&lt;br /&gt;
=== Backup database using mysqldump tool ===&lt;br /&gt;
&lt;br /&gt;
[[Mysqldump]]&lt;br /&gt;
&lt;br /&gt;
=== Backup database using phpMyAdmin web ui ===&lt;br /&gt;
&lt;br /&gt;
Type e.g. URL http://localhost/phpmyadmin in your browser and choose:&lt;br /&gt;
&lt;br /&gt;
* databases --&amp;gt; export&lt;br /&gt;
* Export format: SQL&lt;br /&gt;
* Save as file (e.g. gzipped)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Restore / Import Database ===&lt;br /&gt;
&lt;br /&gt;
'''Restore database from a file'''&lt;br /&gt;
 mysql -u root -p drupal6 &amp;lt; /root/Desktop/drupal6_20100912.sql&lt;br /&gt;
&lt;br /&gt;
If you get following error message:&lt;br /&gt;
&amp;lt;code&amp;gt;ERROR 1049 (42000): Unknown database 'drupal6'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...you have to create the database before restoring:&lt;br /&gt;
 mysql -u root -p -e 'CREATE DATABASE drupal6;'&lt;br /&gt;
&lt;br /&gt;
'''Restore compressed backup file'''&lt;br /&gt;
 gunzip &amp;lt; drupal6_bu_20110126.sql.gz | mysql -u root -p drupal6&lt;br /&gt;
&lt;br /&gt;
=== Restore Table ===&lt;br /&gt;
&lt;br /&gt;
'''Restore single database table from a file'''&lt;br /&gt;
 mysql -u root -p drupal6 &amp;lt; /root/Desktop/users.sql&lt;br /&gt;
&lt;br /&gt;
'''Restore compressed backup file (zip or lzip)'''&lt;br /&gt;
 gunzip &amp;lt; users.sql.gz | mysql -u root -p drupal6&lt;br /&gt;
 lzip -d &amp;lt; /var/backups/users.sql.lz | mysql -u root -p drupal6 (note! unpacks the file and removes .lz file!)&lt;br /&gt;
 lzip -d --keep &amp;lt; /var/backups/users.sql.lz | mysql -u root -p drupal6 (note! keeps .lz file, without leaving uncompressed file)&lt;br /&gt;
&lt;br /&gt;
=== Manage database users ===&lt;br /&gt;
&lt;br /&gt;
==== Show All Users ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT User,Host FROM mysql.user;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== GRANT / Create User ====&lt;br /&gt;
&lt;br /&gt;
Create example user (if doesn't exist?) and give all permissions to example database&lt;br /&gt;
 GRANT ALL PRIVILEGES ON `exampledatabase`.* TO 'exampleuser'@'localhost';&lt;br /&gt;
Create example user and give all permissions to example database and assign a password&lt;br /&gt;
 GRANT ALL ON exampledatabase.* TO exampleuser@localhost IDENTIFIED BY &amp;quot;examplepassword&amp;quot;;&lt;br /&gt;
Give example user selected permissions to drupal6_bu database&lt;br /&gt;
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `drupal6\_bu`.* TO 'exampleuser'@'182.128.10.2';&lt;br /&gt;
&lt;br /&gt;
Related error messages:&lt;br /&gt;
 Error: SELECT command denied to user 'drupal'@'www.site.com' for table 'url_alias'&lt;br /&gt;
&lt;br /&gt;
==== REVOKE ====&lt;br /&gt;
&lt;br /&gt;
Revoke all permissions and grant right from example user to example database&lt;br /&gt;
 REVOKE ALL PRIVILEGES ON `exampledatabase`.* FROM exampleuser@localhost;&lt;br /&gt;
 REVOKE GRANT OPTION ON `exampledatabase`.* FROM 'exampleuser'@'localhost';&lt;br /&gt;
 REVOKE DROP ON `exampledatabase`.* FROM 'exampleuser'@'localhost';&lt;br /&gt;
&lt;br /&gt;
==== DELETE USER ====&lt;br /&gt;
&lt;br /&gt;
 DROP USER exampleUser@localhost&lt;br /&gt;
&lt;br /&gt;
=== Check The Size Of Your Databases ===&lt;br /&gt;
&lt;br /&gt;
Execute the following query to your SQL Server:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema 'Database name', sum( data_length + index_length ) / 1024 / 1024 'Database size (MB)'&lt;br /&gt;
 FROM information_schema.TABLES GROUP BY table_schema&lt;br /&gt;
&lt;br /&gt;
=== Check Database Table Information, e.g. Size (Show Table Info) ===&lt;br /&gt;
&lt;br /&gt;
* Show table information. In addition to table size it shows also a lot of other information related to tables, e.g. table's mysql engine, update time if MyISAM&lt;br /&gt;
columns: Name, Engine, Version, Row_format, Rows, Avg_row_length, Data_length, Max_data_length, Index_length, Data_free, Auto_increment, Create_time, Update_time, Check_time, Collation, Checksum, Create_options, Comment&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW TABLE STATUS&lt;br /&gt;
SHOW TABLE STATUS LIKE 'sessions'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More &amp;lt;code&amp;gt;SHOW&amp;lt;/code&amp;gt; commands: http://dev.mysql.com/doc/refman/5.1/en/show.html&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=VBulletin&amp;diff=32</id>
		<title>VBulletin</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=VBulletin&amp;diff=32"/>
		<updated>2019-09-15T19:17:20Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Administration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Administration ==&lt;br /&gt;
&lt;br /&gt;
=== Turn on the debug mode ===&lt;br /&gt;
&lt;br /&gt;
Open the includes/config.php file and add the following code on a new line below '''&amp;lt;?php'''&lt;br /&gt;
 $config['Misc']['debug'] = true;&lt;br /&gt;
Note: You should not turn on debug mode in a live environment.&lt;br /&gt;
&lt;br /&gt;
=== Disable plugins and hooks ===&lt;br /&gt;
&lt;br /&gt;
Open the includes/config.php file and add the following code on a new line below '''&amp;lt;?php'''&lt;br /&gt;
 define('DISABLE_HOOKS', true);&lt;br /&gt;
Tip: This is a good way to check if problems on a forum is caused by plugins&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=VBulletin&amp;diff=31</id>
		<title>VBulletin</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=VBulletin&amp;diff=31"/>
		<updated>2019-09-15T19:16:57Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Disable plugins and hooks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Administration ==&lt;br /&gt;
&lt;br /&gt;
=== Turn on the debug mode ===&lt;br /&gt;
&lt;br /&gt;
Open the includes/config.php file and add the following code on a new line below '''&amp;lt;?php'''&lt;br /&gt;
 $config['Misc']['debug'] = true;&lt;br /&gt;
Note: You should not turn on debug mode in a live environment.&lt;br /&gt;
&lt;br /&gt;
=== Disable plugins and hooks ===&lt;br /&gt;
&lt;br /&gt;
Open the includes/config.php file and add the following code on a new line below '''&amp;lt;?php'''&lt;br /&gt;
 define('DISABLE_HOOKS', true);&lt;br /&gt;
Note: This is a good way to check if problems on a forum is caused by plugins&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=VBulletin&amp;diff=30</id>
		<title>VBulletin</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=VBulletin&amp;diff=30"/>
		<updated>2019-09-15T19:16:49Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Administration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Administration ==&lt;br /&gt;
&lt;br /&gt;
=== Turn on the debug mode ===&lt;br /&gt;
&lt;br /&gt;
Open the includes/config.php file and add the following code on a new line below '''&amp;lt;?php'''&lt;br /&gt;
 $config['Misc']['debug'] = true;&lt;br /&gt;
Note: You should not turn on debug mode in a live environment.&lt;br /&gt;
&lt;br /&gt;
=== Disable plugins and hooks ===&lt;br /&gt;
&lt;br /&gt;
Open the includes/config.php file and add the following code on a new line below '''&amp;lt;?php'''&lt;br /&gt;
define('DISABLE_HOOKS', true);&lt;br /&gt;
Note: This is a good way to check if problems on a forum is caused by plugins&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=VBulletin&amp;diff=29</id>
		<title>VBulletin</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=VBulletin&amp;diff=29"/>
		<updated>2019-09-15T19:13:55Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;== Administration ==  === Turn on the debug mode ===  Open the includes/config.php file and add the following code on a new line below '''&amp;lt;?php'''  $config['Misc']['debug'] =...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Administration ==&lt;br /&gt;
&lt;br /&gt;
=== Turn on the debug mode ===&lt;br /&gt;
&lt;br /&gt;
Open the includes/config.php file and add the following code on a new line below '''&amp;lt;?php'''&lt;br /&gt;
 $config['Misc']['debug'] = true;&lt;br /&gt;
Note: You should not turn on debug mode in a live environment.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=28</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=28"/>
		<updated>2019-09-10T22:12:21Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to KnowledgeNerd.net! The purpose of this website is to provide useful information related to servers, coding, web development etc. It's kind of an online notebook for a full stack developer with a bad memory (like me) :D I hope others find it useful too, even though some content might be quite old. Some of the tips might have been partly copied from other sources. If I haven't remembered to provide the source or link to the original webpage and you feel it would be appropriate in that specific case, please contact me.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
[[Linux_commands|Linux commands]]&lt;br /&gt;
&lt;br /&gt;
[[SQL|SQL]]&lt;br /&gt;
&lt;br /&gt;
[[MySQL_Server|MySQL Server]]&lt;br /&gt;
&lt;br /&gt;
[[Mysqldump|mysqldump]]&lt;br /&gt;
&lt;br /&gt;
[[Apache]]&lt;br /&gt;
&lt;br /&gt;
[[Special:AllPages| See all Pages]]&lt;br /&gt;
&lt;br /&gt;
[[Special:Categories|See all Categories]]&lt;br /&gt;
&lt;br /&gt;
[https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Disclaimer: This site doesn't take any responsibility regarding the tips and commands provided here. Even though the tips have been tested and found working, the consequences might be different in other use cases and context.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Apache&amp;diff=27</id>
		<title>Apache</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Apache&amp;diff=27"/>
		<updated>2019-09-08T21:36:14Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;Apache is a open source HTTP Server.  == Installation ==  * Get the package from: http://apache.org  == Configuring and administration==  Apache 2.0 configuration files are in...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Apache is a open source HTTP Server.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
* Get the package from:&lt;br /&gt;
http://apache.org&lt;br /&gt;
&lt;br /&gt;
== Configuring and administration==&lt;br /&gt;
&lt;br /&gt;
Apache 2.0 configuration files are in the directory '''/etc/apache2/'''&lt;br /&gt;
* main configuration file: apache2.conf (httpd.conf exists for compatibility issues)&lt;br /&gt;
&lt;br /&gt;
'''folders:'''&lt;br /&gt;
&lt;br /&gt;
'''sites-available''' -  A list of configuration files - one per site. A blank install will contain the file default. The system admin can have as many sites here as they need - however - they will not all be active.&lt;br /&gt;
&lt;br /&gt;
'''sites-enabled''' -   A list of symlinks to configuration files in sites-available. A blank install will contain a symlink 000default to sites-available/default. The sites listed here are the sites which will be active. The site to be used if no virtual hosts match will be the first file found (hence the 000 on 000default).&lt;br /&gt;
&lt;br /&gt;
'''mods-available''' -   A list of configuration files - one or more per module. Each dpkg installed module will add files here. e.g. php4.conf and php4.load are added with the libapache2-mod-php package. Again - the system admin can install whatever modules they wish - however - until they are set available they will not be active.&lt;br /&gt;
&lt;br /&gt;
'''mods-enabled''' -  A list of symlinks to configuration files in modes-available. Only modules linked in here will be activated on the webserver.&lt;br /&gt;
&lt;br /&gt;
=== htaccess ===&lt;br /&gt;
&lt;br /&gt;
.htaccess file configuration examples: [[Htaccess]]&lt;br /&gt;
&lt;br /&gt;
=== Website Configuration File ===&lt;br /&gt;
&lt;br /&gt;
Example of website configuration file: httpd.conf or /etc/apache2/sites-enabled/websitename.conf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Commands e.g. Restart Apache ===&lt;br /&gt;
&lt;br /&gt;
* Use the chkconfig command to configure Apache to start at boot:&lt;br /&gt;
 $chkconfig httpd on -- not working on ubuntu server&lt;br /&gt;
&lt;br /&gt;
* Use the following scripts to control Apache:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
start apache ............... $/etc/init.d/httpd start&lt;br /&gt;
stop apache ................ $/etc/init.d/httpd stop&lt;br /&gt;
restart apache ............. $/etc/init.d/httpd restart&lt;br /&gt;
&lt;br /&gt;
Ubuntu server:&lt;br /&gt;
start apache ............... $/etc/init.d/apache2 start&lt;br /&gt;
stop apache ................ $/etc/init.d/apache2 stop&lt;br /&gt;
restart apache ............. $/etc/init.d/apache2 restart&lt;br /&gt;
reload apache's settings ... $/etc/init.d/apache2 reload&lt;br /&gt;
force to reload settings ... $/etc/init.d/apache2 force-reload&lt;br /&gt;
start cacheclean ........... $/etc/init.d/apache2 start-htcacheclean&lt;br /&gt;
stop cacheclean?? .......... $/etc/init.d/apache2 stop-htcacheclean&lt;br /&gt;
apache's status ............ $/etc/init.d/apache2 status&lt;br /&gt;
   if running prints e.g. &amp;quot;Apache is running (pid 6135)&amp;quot; else no output.&lt;br /&gt;
Enable site ................ $a2ensite&lt;br /&gt;
Disable site ............... $a2dissite&lt;br /&gt;
Enable mod ................. $a2enmod&lt;br /&gt;
Disable mod ................ $a2dismod&lt;br /&gt;
&lt;br /&gt;
PHP:&lt;br /&gt;
php-fastcgi restart ........ $/etc/init.d/php-fastcgi restart&lt;br /&gt;
&lt;br /&gt;
Mac OS X:&lt;br /&gt;
The apachectl command act as Apache HTTP Server control interface (ctl = control tool?).&lt;br /&gt;
httpd command seems to work somehow like alias to apachectl. type httpd -h to see available options.&lt;br /&gt;
&lt;br /&gt;
start apache ............... $sudo apachectl start&lt;br /&gt;
stop apache ................ $sudo apachectl stop&lt;br /&gt;
restart apache ............. $sudo apachectl restart&lt;br /&gt;
show apache settings ....... $sudo apachectl -S&lt;br /&gt;
show apachectl commands .... $sudo apachectl -?&lt;br /&gt;
list compiled modules ...... $httpd -l  (list every module that is compiled into the server)&lt;br /&gt;
check if apache is running . $ps aux | grep httpd (you should find apache process running in /usr/sbin/httpd)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* You can test whether the Apache process is running with&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
pgrep httpd&lt;br /&gt;
$ps ax | grep httpd&lt;br /&gt;
&lt;br /&gt;
Ubuntu server:&lt;br /&gt;
pgrep apache2&lt;br /&gt;
$ps ax | grep apache2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Restart php-fastcgi ===&lt;br /&gt;
&lt;br /&gt;
For example when new module is loaded to server you have to restart php-fastcgi to start using the module&lt;br /&gt;
 /etc/init.d/php-fastcgi restart&lt;br /&gt;
&lt;br /&gt;
=== Restart php ===&lt;br /&gt;
&lt;br /&gt;
[[Nginx#Restart_PHP]]&lt;br /&gt;
&lt;br /&gt;
=== Symlinks ===&lt;br /&gt;
&lt;br /&gt;
Symlinks...&lt;br /&gt;
&lt;br /&gt;
=== Virtual Hosts ===&lt;br /&gt;
&lt;br /&gt;
Add virtual hosts / aliases.&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
1. Uncomment the following include statement from &amp;lt;code&amp;gt;bin\apache\apache2.4.9\conf\httpd.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Virtual hosts&lt;br /&gt;
#Include conf/extra/httpd-vhosts.conf&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
2. Edit bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf and check that the default localhost settings are right for your www-root:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# VirtualHost example:&lt;br /&gt;
# Almost any Apache directive may go into a VirtualHost container.&lt;br /&gt;
# The first VirtualHost section is used for all requests that do not&lt;br /&gt;
# match a ServerName or ServerAlias in any &amp;lt;VirtualHost&amp;gt; block.&lt;br /&gt;
#&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
    ServerAdmin webmaster@localhost&lt;br /&gt;
    DocumentRoot &amp;quot;d:/wamp/www&amp;quot;&lt;br /&gt;
    ServerName localhost&lt;br /&gt;
    ErrorLog &amp;quot;logs/localhost-error.log&amp;quot;&lt;br /&gt;
    CustomLog &amp;quot;logs/localhost-access.log&amp;quot; common&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
then add the following code for your examplesite.local alias:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;
    ServerAdmin webmaster@examplesite.local&lt;br /&gt;
    DocumentRoot &amp;quot;d:/wamp/www/examplesite&amp;quot;&lt;br /&gt;
    ServerName examplesite.local&lt;br /&gt;
    ServerAlias www.examplesite.local&lt;br /&gt;
    ErrorLog &amp;quot;logs/examplesite-error.log&amp;quot;&lt;br /&gt;
    CustomLog &amp;quot;logs/examplesite-access.log&amp;quot; common&lt;br /&gt;
&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Edit your hosts-file and add following line:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
127.0.0.1	      examplesite.local&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Enable Apache's url rewrite module (mod_rewrite) ===&lt;br /&gt;
&lt;br /&gt;
Use a2enmod command (as in &amp;quot;apache2 enable module &amp;lt;module&amp;gt;&amp;quot;)&lt;br /&gt;
 a2enmod rewrite&lt;br /&gt;
restart apache to activate new configuration&lt;br /&gt;
 /etc/init.d/apache2 restart&lt;br /&gt;
&lt;br /&gt;
=== Logs (Access And Error) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find -name error.log&lt;br /&gt;
find -name access.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example locations for mysql and php error logs + access log:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
./var/log/mysql/error.log&lt;br /&gt;
./var/log/apache2/error.log&lt;br /&gt;
./var/log/apache2/access.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FAQ ==&lt;br /&gt;
&lt;br /&gt;
=== PHP-Error Messages Not Showing In Browser Or Log Files ===&lt;br /&gt;
&lt;br /&gt;
Check from the php.ini that following settings are true:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display_errors = On&lt;br /&gt;
display_startup_errors = On&lt;br /&gt;
log_errors = On&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reload Apache's settings:&lt;br /&gt;
 /etc/init.d/apache2 reload&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Fatal error: Call to undefined function curl_init() in /var/www/viddler/phpviddler/phpviddler.php on line ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* You need to install PHP/CURL module (and sometimes cURL also)&lt;br /&gt;
&lt;br /&gt;
* Install the php5-curl package&lt;br /&gt;
 sudo apt-get install php5-curl&lt;br /&gt;
&lt;br /&gt;
* After installing PHP/CURL module you need to restart php-fastcgi&lt;br /&gt;
 /etc/init.d/php-fastcgi restart&lt;br /&gt;
&lt;br /&gt;
* Older php-curl &lt;br /&gt;
 $sudo apt-get install php-curl&lt;br /&gt;
&lt;br /&gt;
* To install cURL&lt;br /&gt;
 sudo apt-get install curl&lt;br /&gt;
&lt;br /&gt;
* You need to add more repositories if you got following error:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Reading package lists... Done&lt;br /&gt;
Building dependency tree... Done&lt;br /&gt;
E: Couldn't find package php4-gd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add extra repositories using the Synaptic Package Manager&lt;br /&gt;
System --&amp;gt; Administration --&amp;gt; Synaptic Package Manager --&amp;gt; settings --&amp;gt; repositories&lt;br /&gt;
Install from SPM by typing &amp;quot;php5-curl&amp;quot; to quick search.&lt;br /&gt;
&lt;br /&gt;
or from command line:&lt;br /&gt;
&lt;br /&gt;
Make a copy of repositories list&lt;br /&gt;
sudo cp -p /etc/apt/sources.list /etc/apt/sources.list_backup&lt;br /&gt;
&lt;br /&gt;
edit list and add needed rows&lt;br /&gt;
gksudo gedit /etc/apt/sources.list&lt;br /&gt;
&lt;br /&gt;
Update package list&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
&lt;br /&gt;
* restart the apache web server&lt;br /&gt;
 $sudo /etc/init.d/apache2 restart&lt;br /&gt;
&lt;br /&gt;
=== Test If CLI-PHP Is Installed On The Server ===&lt;br /&gt;
&lt;br /&gt;
Print php version:&lt;br /&gt;
 php -v&lt;br /&gt;
&lt;br /&gt;
Try to execute command line php:&lt;br /&gt;
 php -r &amp;quot;echo 'Hello World';&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Web servers]]&lt;br /&gt;
[[Category:Linux commands]]&lt;br /&gt;
[[Category:Linux]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=26</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=26"/>
		<updated>2019-09-08T21:06:57Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* SCP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing files and directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, finding and searching inside files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List files in archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X specific permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration related commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating system restart / reboot / shut down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server related commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network related commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network interface commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot;, &amp;quot;bar.txt&amp;quot; &amp;amp; &amp;quot;baz.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:/dir\{foo.txt,bar.txt,baz.txt\} .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@xxx.xxx.xxx.xxx:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=25</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=25"/>
		<updated>2019-09-08T21:06:04Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* SCP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing files and directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, finding and searching inside files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List files in archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X specific permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration related commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating system restart / reboot / shut down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server related commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network related commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network interface commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot;, &amp;quot;bar.txt&amp;quot; &amp;amp; &amp;quot;baz.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:/dir\{foo.txt,bar.txt,baz.txt\} .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=MySQL_Server&amp;diff=24</id>
		<title>MySQL Server</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=MySQL_Server&amp;diff=24"/>
		<updated>2019-09-08T19:53:04Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* MySQL Server Administration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Linux Command Line Commands For MySQL Server ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install mysql database ................. $sudo apt-get install mysql-server&lt;br /&gt;
install mysql client ................... $sudo apt-get install mysql-client&lt;br /&gt;
&lt;br /&gt;
start mysql server ..................... $service mysql start&lt;br /&gt;
start mysql server ..................... $service mysqld start&lt;br /&gt;
start mysql server ..................... $/etc/init.d/mysql start&lt;br /&gt;
start mysql server ..................... $/etc/init.d/mysqld start&lt;br /&gt;
&lt;br /&gt;
stop mysql server ...................... $/etc/init.d/mysql stop&lt;br /&gt;
restart mysql server ................... $/etc/init.d/mysql restart&lt;br /&gt;
reload mysql server configurations ..... $/etc/init.d/mysql reload&lt;br /&gt;
reload mysql server configurations ..... $/etc/init.d/mysql force-reload&lt;br /&gt;
check the status of mysql server ....... $/etc/init.d/mysql status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Preferred commands with some Linux:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service mysql start&lt;br /&gt;
service mysql stop&lt;br /&gt;
service mysql restart&lt;br /&gt;
or&lt;br /&gt;
service mysqld start&lt;br /&gt;
service mysqld stop&lt;br /&gt;
service mysqld restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mac OS X Command Line Commands For MySQL Server ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
start mysql server ..................... $sudo /usr/local/mysql/support-files/mysql.server start&lt;br /&gt;
stop mysql server ...................... $sudo /usr/local/mysql/support-files/mysql.server stop&lt;br /&gt;
restart mysql server ................... $sudo /usr/local/mysql/support-files/mysql.server restart&lt;br /&gt;
reload mysql server settings ........... $sudo /usr/local/mysql/support-files/mysql.server reload&lt;br /&gt;
force-reload mysql server settings ..... $sudo /usr/local/mysql/support-files/mysql.server force-reload&lt;br /&gt;
check the status of mysql server ....... $sudo /usr/local/mysql/support-files/mysql.server status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start MySQL Server at System Startup ===&lt;br /&gt;
&lt;br /&gt;
To start MySQL server automatically on MAC OS X system startup, create a property list file (.plist)&lt;br /&gt;
 sudo vim /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
...and add the following lines to it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;!--?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?--&amp;gt;&lt;br /&gt;
&amp;lt;plist version=&amp;quot;1.0&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;dict&amp;gt;&lt;br /&gt;
    &amp;lt;key&amp;gt;KeepAlive&amp;lt;/key&amp;gt;&lt;br /&gt;
    &amp;lt;true /&amp;gt;&lt;br /&gt;
    &amp;lt;key&amp;gt;Label&amp;lt;/key&amp;gt;&lt;br /&gt;
    &amp;lt;string&amp;gt;com.mysql.mysqld&amp;lt;/string&amp;gt;&lt;br /&gt;
    &amp;lt;key&amp;gt;ProgramArguments&amp;lt;/key&amp;gt;&lt;br /&gt;
    &amp;lt;array&amp;gt;&lt;br /&gt;
      &amp;lt;string&amp;gt;/usr/local/mysql/bin/mysqld_safe&amp;lt;/string&amp;gt;&lt;br /&gt;
      &amp;lt;string&amp;gt;--user=mysql&amp;lt;/string&amp;gt;&lt;br /&gt;
    &amp;lt;/array&amp;gt;        &lt;br /&gt;
  &amp;lt;/dict&amp;gt;&lt;br /&gt;
&amp;lt;/plist&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then update permissions and add it to launchctl:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Disable MySQL Server at System Startup ===&lt;br /&gt;
&lt;br /&gt;
 sudo rm /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
&lt;br /&gt;
Other way (which didn't work for me) is to search the service name:&lt;br /&gt;
 sudo launchctl list | grep -i mysql&lt;br /&gt;
and remove it e.g.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo launchctl remove com.mysql.mysqld&lt;br /&gt;
sudo launchctl remove com.mysql.mysqld.plist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== mysql Tool Command Line Commands ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect local mysql server ............. $mysql -u root -p&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute a Query To DB With mysql Tool ===&lt;br /&gt;
&lt;br /&gt;
Create a new database:&lt;br /&gt;
 mysql -u root -p -e 'CREATE DATABASE drupal6_bu;'&lt;br /&gt;
&lt;br /&gt;
Show all PhpBBForum tables (starting with 'phpbb_') from Drupal6 database:&lt;br /&gt;
 mysql -u root -p -e 'USE Drupal6; SHOW TABLES;' | grep 'phpbb_'&lt;br /&gt;
or with different query and writing results into a file:&lt;br /&gt;
 mysql -u root -p -N information_schema -e &amp;quot;SELECT table_name FROM TABLES WHERE table_name LIKE 'phpbb_%' AND table_schema LIKE 'Drupal6'&amp;quot; &amp;gt; phpbb_tables.txt&lt;br /&gt;
&lt;br /&gt;
* Note: &amp;lt;code&amp;gt;-N, --skip-column-names | Don't write column names in results.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill Stuck Processes ===&lt;br /&gt;
&lt;br /&gt;
Connect remote mysql server (you have to have mysql client installed on current computer):&lt;br /&gt;
 mysql -u root -p -h 123.12.1.1&lt;br /&gt;
&lt;br /&gt;
Show ongoing processes:&lt;br /&gt;
 SHOW PROCESSLIST;&lt;br /&gt;
 SHOW FULL PROCESSLIST;&lt;br /&gt;
&lt;br /&gt;
Kill stuck processes (using the id of wanted process):&lt;br /&gt;
 KILL 8494378;&lt;br /&gt;
&lt;br /&gt;
Even it says e.g. &amp;lt;code&amp;gt;Query OK, 0 rows affected (0.00 sec)&amp;lt;/code&amp;gt;, the process was quite sure killed. Check if the process have disappeared:&lt;br /&gt;
 SHOW PROCESSLIST;&lt;br /&gt;
&lt;br /&gt;
=== Kill Multiple Stuck Processes ===&lt;br /&gt;
&lt;br /&gt;
MySQL doesn't have a query to kill multiple processes and you have to do it one by one. There's still couple handy ways to do that.&lt;br /&gt;
&lt;br /&gt;
'''From MySQL Server Command Line'''&lt;br /&gt;
&lt;br /&gt;
* Prepare a wanted sql query, e.g.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT * FROM information_schema.processlist&lt;br /&gt;
WHERE USER = 'drupal' AND DB = 'drupal6' AND TIME &amp;gt; 200;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Option 1''': When you have all the processes as results which you want to terminate, execute following query, copy and clean the output and execute it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT CONCAT('KILL ', ID, ';') FROM information_schema.processlist&lt;br /&gt;
WHERE USER = 'drupal' AND DB = 'drupal6' AND TIME &amp;gt; 200;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Option 2''': When you have all the processes as results which you want to terminate, execute following query and save kill statements to a file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT CONCAT('KILL ', ID, ';') FROM information_schema.processlist&lt;br /&gt;
WHERE USER = 'drupal' AND DB = 'drupal6' AND TIME &amp;gt; 200 INTO OUTFILE '/tmp/sql-kill-stuck.txt';&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Execute commands from the created file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SOURCE /tmp/sql-kill-stuck.txt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''From PHP-Script'''&lt;br /&gt;
&lt;br /&gt;
* Following is only an example, it's good to narrow the result set with WHERE statement so you don't kill e.g. possible replication threads.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$result = mysql_query(&amp;quot;SHOW FULL PROCESSLIST&amp;quot;);&lt;br /&gt;
while ($row=mysql_fetch_array($result)) {&lt;br /&gt;
  $process_id=$row[&amp;quot;Id&amp;quot;];&lt;br /&gt;
  if ($row[&amp;quot;Time&amp;quot;] &amp;gt; 200 ) {&lt;br /&gt;
    $sql=&amp;quot;KILL $process_id&amp;quot;;&lt;br /&gt;
    mysql_query($sql);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MySQL Server Administration ==&lt;br /&gt;
&lt;br /&gt;
=== MySQL Server Configuration File ===&lt;br /&gt;
&lt;br /&gt;
You can find it by typing:&lt;br /&gt;
 find -name my.cnf&lt;br /&gt;
&lt;br /&gt;
It can locate e.g. in:&lt;br /&gt;
 /etc/mysql/my.cnf&lt;br /&gt;
&lt;br /&gt;
=== Reset mysql root password ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service mysql stop&lt;br /&gt;
mysqld_safe --skip-grant-tables &amp;amp;&lt;br /&gt;
# Log into MySQL server&lt;br /&gt;
mysql&lt;br /&gt;
# Replace NEW-PASS-HERE with desired new root password&lt;br /&gt;
UPDATE mysql.user SET Password=PASSWORD('NEW-PASS-HERE') WHERE User='root';&lt;br /&gt;
FLUSH PRIVILEGES;&lt;br /&gt;
exit;&lt;br /&gt;
mysqladmin -u root -p shutdown&lt;br /&gt;
service mysql start&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Enable MySQL Server Slow Query Log ====&lt;br /&gt;
&lt;br /&gt;
MySQL has a feature that allows you to log slow running queries to a file. To enable you just need to add some lines to your my.cnf file, and restart. To log the queries taking longer than two seconds to the specified log file, add the following (or uncomment lines if exists):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
log-slow-queries = /var/log/mysql/mysql-slow.log&lt;br /&gt;
long_query_time = 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backup Database ===&lt;br /&gt;
&lt;br /&gt;
* [[Mysqldump |Backup database using mysqldump tool]]&lt;br /&gt;
* [[SQL#Backup_database_using_phpMyAdmin_web_ui |Backup database using phpMyAdmin web ui ]]&lt;br /&gt;
&lt;br /&gt;
=== Restore Database ===&lt;br /&gt;
&lt;br /&gt;
* [[SQL#Restore_Database]]&lt;br /&gt;
&lt;br /&gt;
== MySQL Server Logs ==&lt;br /&gt;
&lt;br /&gt;
Located e.g. in /var/www/drupal/ (files: mysql.log, mysql-slow.log)&lt;br /&gt;
* http://dev.mysql.com/doc/refman/5.1/en/server-logs.html&lt;br /&gt;
&lt;br /&gt;
== MySQL Server Tips ==&lt;br /&gt;
&lt;br /&gt;
=== Check MySQL Server Version ===&lt;br /&gt;
&lt;br /&gt;
 mysql --version&lt;br /&gt;
 // prints e.g. mysql  Ver 14.14 Distrib 5.1.37, for debian-linux-gnu (i486) using  EditLine wrapper&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== If MySQL Server is stuck and website using it is down ===&lt;br /&gt;
&lt;br /&gt;
* Click Server/Palvelin --&amp;gt; Processes/Prosessit&lt;br /&gt;
* Choose Kill/Lopeta for processes which are stuck&lt;br /&gt;
* (You can see processes also from (but can't kill them): Check ongoing queries/locks from processlist (Database: information_schema - Table: PROCESSLIST) e.g. with phpMyAdmin)&lt;br /&gt;
* If there's a lot of locked queries for certain table (e.g. phpbb_sessions) you could try to change table type e.g. from MyISAM to InnoDB&lt;br /&gt;
* If there's a lot of queries which are increasing, you can stop your webserver to prevent generating more queries&lt;br /&gt;
* Restart MySQL server if there's something wrong with the queries&lt;br /&gt;
&lt;br /&gt;
==== Kill MySQL Processes ====&lt;br /&gt;
&lt;br /&gt;
Besides phpMyAdmin, you can kill processes by typing:&lt;br /&gt;
 KILL thread_id&lt;br /&gt;
&lt;br /&gt;
* Check: [[MySQL_Server#Kill_Stuck_Processes]]&lt;br /&gt;
* More information from: http://dev.mysql.com/doc/refman/5.1/en/kill.html&lt;br /&gt;
&lt;br /&gt;
=== MyISAM vs. InnoDB ===&lt;br /&gt;
&lt;br /&gt;
Claims for different database engines. Claims aren't surely facts.&lt;br /&gt;
&lt;br /&gt;
==== MyISAM ====&lt;br /&gt;
&lt;br /&gt;
'''Pros'''&lt;br /&gt;
* Is faster for applications like phpbb&lt;br /&gt;
* Uses simpler structure thus takes less space and has better performance with simple queries&lt;br /&gt;
* Much faster for large text based primary keys&lt;br /&gt;
* You can use mysqlhotcopy which is faster than mysqldump&lt;br /&gt;
* MyISAM supports FULL-TEXT indexes while InnoDB does not&lt;br /&gt;
&lt;br /&gt;
'''Cons'''&lt;br /&gt;
* Supports only table locking&lt;br /&gt;
* No support for transactions&lt;br /&gt;
* No data integrity (e.g. relationship constraints) check, responsibility is left e.g. for database administrators and application developers.&lt;br /&gt;
&lt;br /&gt;
==== InnoDB ====&lt;br /&gt;
&lt;br /&gt;
'''Pros'''&lt;br /&gt;
* You can use inno hot backup, which don't lock the database during backup (writes ahead log). InnoDB Hot Backup has been renamed to MySQL Enterprise Backup, which is included as part of the MySQL Enterprise Edition.&lt;br /&gt;
* Supports row locking&lt;br /&gt;
* Give better performance results in inserting and updating data records&lt;br /&gt;
* Uses clustered indexes to reduce IO operations for PK access&lt;br /&gt;
* Has transactions while MyISAM does not&lt;br /&gt;
* Has better crash recovery&lt;br /&gt;
* (InnoDB is newer while MyISAM is older)&lt;br /&gt;
&lt;br /&gt;
'''Cons'''&lt;br /&gt;
* No FULL-TEXT support&lt;br /&gt;
* Consumes more system resources such as RAM. As a matter of fact, it is recommended by many that InnoDB engine be turned off if there’s no substantial need for it after installation of MySQL.&lt;br /&gt;
&lt;br /&gt;
==== Conclusions ====&lt;br /&gt;
&lt;br /&gt;
* If your project is small and doesn't have any issues with DB leave MyISAM&lt;br /&gt;
* If you have write-heavy load (like community site, where users add many content items) choose InnoDB&lt;br /&gt;
&lt;br /&gt;
==== Change Table Engine From MyISAM to InnoDB And Vice Versa  ====&lt;br /&gt;
&lt;br /&gt;
To change a MyISAM table to an InnoDB table:&lt;br /&gt;
 ALTER TABLE table_name ENGINE = InnoDB;&lt;br /&gt;
&lt;br /&gt;
To convert an InnoDB table to a MyISAM table:&lt;br /&gt;
 ALTER TABLE table_name ENGINE = MyISAM;&lt;br /&gt;
&lt;br /&gt;
* Tip: When converting from MyISAM to InnoDB you can speed up the transformation. Before converting the table, adjust order so that the primary key column is in order:&lt;br /&gt;
 ALTER TABLE tablename ORDER BY 'primary_key_column';&lt;br /&gt;
&lt;br /&gt;
* This will pre-arrange the table so that it can be converted quickly without a lot of re-arranging required in MySQL. Then, simply change the table engine:&lt;br /&gt;
 ALTER TABLE tablename ENGINE = INNODB;&lt;br /&gt;
&lt;br /&gt;
== MySQL Tips ==&lt;br /&gt;
&lt;br /&gt;
=== Select inside update query ===&lt;br /&gt;
&lt;br /&gt;
If you get following error message:&lt;br /&gt;
 #1093 - You can't specify target table 'gsmvalidation' for update in FROM clause&lt;br /&gt;
&lt;br /&gt;
When executing following query:&lt;br /&gt;
 UPDATE `gsmvalidation` SET confirmedtime = (SELECT NOW()) WHERE id = (SELECT id FROM `gsmvalidation` WHERE uid = 1 ORDER BY `codesended` DESC LIMIT 1)&lt;br /&gt;
&lt;br /&gt;
The reason is that in MySQL, you can't modify the same table which you use in the SELECT part. You have to make another subquery and give alias for table name.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
 UPDATE `gsmvalidation` SET confirmedtime = (SELECT NOW())&lt;br /&gt;
 WHERE id = (SELECT id FROM (SELECT id,uid,codesended from `gsmvalidation`) AS temp WHERE uid = 1 ORDER BY `codesended` DESC LIMIT 1)&lt;br /&gt;
&lt;br /&gt;
=== MySQL server has gone away error ===&lt;br /&gt;
&lt;br /&gt;
If you get the following error while restoring a big database:&lt;br /&gt;
 ERROR 2006 (HY000) at line ##: MySQL server has gone away&lt;br /&gt;
&lt;br /&gt;
..make sure that the value &amp;lt;code&amp;gt;max_allowed_packet&amp;lt;/code&amp;gt; is big enough in /etc/my.cnf:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
max_allowed_packet=64M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart MySQL server to apply changes. If you can't find the mysql config file, check [[Config_files | Config files page]]&lt;br /&gt;
&lt;br /&gt;
=== After Restoring Mysql Database Phpmyadmin Won't Show The Tables ===&lt;br /&gt;
&lt;br /&gt;
* Problem: I exported a production database and created a development database from the backup.  Now when I try to check the contents of the database from phpmyadmin, there's no tables in it. I can see the tables with &amp;lt;code&amp;gt;SHOW TABLES;&amp;lt;/code&amp;gt; command and from mysql command line but not from phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
* Possible reason: The imported database has VIEW(S) defined by a user that don't exist in the new computer's mysql users.&lt;br /&gt;
&lt;br /&gt;
* Solution: Create a missing user or drop the view(s) and create them again with an existing user.&lt;br /&gt;
&lt;br /&gt;
* Case: Exporting and importing Drupal 6 database with Ubercart module&lt;br /&gt;
&lt;br /&gt;
Drupal 6 database includes 3 views when Uber Cart module is installed:&lt;br /&gt;
dr_uc_order_products_pair_vw, dr_uc_order_products_qty_vw, dr_uc_order_products_user_vw&lt;br /&gt;
&lt;br /&gt;
Check the information and creation script of the specific view&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW CREATE VIEW dr_uc_order_products_pair_vw&lt;br /&gt;
Results:&lt;br /&gt;
View: dr_uc_order_products_pair_vw&lt;br /&gt;
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`drupal`@`www.p... &lt;br /&gt;
character_set_client: utf8&lt;br /&gt;
collation_connection: utf8_general_ci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get the full &amp;quot;Create view&amp;quot; code, click &amp;quot;Print view (with full texts)&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE ALGORITHM=UNDEFINED DEFINER=`drupal`@`www.yoursite.com` SQL SECURITY DEFINER VIEW `dr_uc_order_products_pair_vw` AS select `op1`.`nid` AS `nid`,`op2`.`nid` AS `pair_nid`,sum(`op2`.`qty`) AS `pair_sum_qty`,count(`op2`.`nid`) AS `order_count` from (`dr_uc_order_products` `op1` join `dr_uc_order_products` `op2`) where ((`op1`.`order_id` = `op2`.`order_id`) and (`op1`.`nid` &amp;lt;&amp;gt; `op2`.`nid`)) group by `op1`.`nid`,`op2`.`nid` order by `op1`.`nid`,count(`op2`.`nid`) desc,sum(`op2`.`qty`) desc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you try to check the contents of the view:&lt;br /&gt;
 SELECT * FROM dr_uc_order_products_pair_vw&lt;br /&gt;
You'll get an error message:&lt;br /&gt;
 #1449 - The user specified as a definer ('drupal'@'www.yoursite.com') does not exist&lt;br /&gt;
&lt;br /&gt;
Now you can drop the views causing problem and recreate those with the right users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP VIEW dr_uc_order_products_pair_vw;&lt;br /&gt;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `dr_uc_order_products_pair_vw` AS select `op1`.`nid` AS `nid`,`op2`.`nid` AS `pair_nid`,sum(`op2`.`qty`) AS `pair_sum_qty`,count(`op2`.`nid`) AS `order_count` from (`dr_uc_order_products` `op1` join `dr_uc_order_products` `op2`) where ((`op1`.`order_id` = `op2`.`order_id`) and (`op1`.`nid` &amp;lt;&amp;gt; `op2`.`nid`)) group by `op1`.`nid`,`op2`.`nid` order by `op1`.`nid`,count(`op2`.`nid`) desc,sum(`op2`.`qty`) desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Views ==&lt;br /&gt;
&lt;br /&gt;
=== List Views ===&lt;br /&gt;
&lt;br /&gt;
Phpmyadmin shows different icon (eye) for views in table listing compared to normal tables.&lt;br /&gt;
You can get a list of all views in specific database with a sql query&lt;br /&gt;
 SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW';&lt;br /&gt;
&lt;br /&gt;
=== Check Views ===&lt;br /&gt;
&lt;br /&gt;
Shows the properties of a view and it's creation statement&lt;br /&gt;
 SHOW CREATE VIEW test_view&lt;br /&gt;
&lt;br /&gt;
=== Create Views ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `test_view` AS select `test-table`.`id` AS `id`,`test-table`.`age` AS `age` from `test-table` 	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
..or from phpmyadmin, execute a sql query for wanted result set and click &amp;quot;Create View&amp;quot; link from bottom section of the page.&lt;br /&gt;
&lt;br /&gt;
=== Delete Views ===&lt;br /&gt;
&lt;br /&gt;
 DROP VIEW test_view&lt;br /&gt;
&lt;br /&gt;
=== Replace Views ===&lt;br /&gt;
&lt;br /&gt;
When creating a new view from phpmyadmin you can specify an existing name and check the &amp;quot;OR REPLACE&amp;quot; box.&lt;br /&gt;
&lt;br /&gt;
== Stored Procedures and Functions ==&lt;br /&gt;
&lt;br /&gt;
Since MySQL version 5.0 there have been a support for stored procedures, triggers and events. Stored procedures are saved in mysql database's proc table.&lt;br /&gt;
* http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspx&lt;br /&gt;
&lt;br /&gt;
=== Create a Stored Procedure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER //&lt;br /&gt;
CREATE PROCEDURE GetAllArticles()&lt;br /&gt;
  BEGIN&lt;br /&gt;
  SELECT * FROM articles;&lt;br /&gt;
  END //&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Call the Stored Procedure ===&lt;br /&gt;
&lt;br /&gt;
 CALL DatabaseName.StroredPrecedureName();&lt;br /&gt;
&lt;br /&gt;
=== Alter a Stored Procedure ===&lt;br /&gt;
&lt;br /&gt;
Note! With the ALTER PROCEDURE Statement you can change only the characteristics and if you want to change in statement list then you have to DROP the procedure and CREATE again.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER {PROCEDURE | FUNCTION} {proc_name | func_name} [characteristic ...]&lt;br /&gt;
  characteristic: SQL SECURITY {DEFINER | INVOKER}| COMMENT 'string'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Drop a Stored Procedure ===&lt;br /&gt;
&lt;br /&gt;
 DROP PROCEDURE IF EXISTS exampleSproc;&lt;br /&gt;
&lt;br /&gt;
=== Variables in Sprocs ===&lt;br /&gt;
&lt;br /&gt;
* Save count of articles into a variable and print it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER //&lt;br /&gt;
CREATE PROCEDURE HowMany()&lt;br /&gt;
  BEGIN&lt;br /&gt;
  DECLARE articlecount INT DEFAULT 0;&lt;br /&gt;
  SELECT COUNT(*) INTO articlecount FROM articles;&lt;br /&gt;
  SELECT articlecount;&lt;br /&gt;
  END //&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER //&lt;br /&gt;
CREATE PROCEDURE HowMany()&lt;br /&gt;
  BEGIN&lt;br /&gt;
  DECLARE articlecount INT DEFAULT 0;&lt;br /&gt;
  SET articlecount = 33;&lt;br /&gt;
  SELECT CONCAT('Article count: ',articlecount) AS 'End Result';&lt;br /&gt;
  END //&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Parameters in Sprocs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER $$&lt;br /&gt;
CREATE PROCEDURE testdatabase.ShowArticles(IN emails VARCHAR(255))&lt;br /&gt;
  BEGIN&lt;br /&gt;
  SELECT * FROM users WHERE email IN (emails);&lt;br /&gt;
  END $$&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* http://www.mysqltutorial.org/stored-procedures-parameters.aspx&lt;br /&gt;
&lt;br /&gt;
=== Misc Sprocs ===&lt;br /&gt;
&lt;br /&gt;
==== Remove Emails Sproc ====&lt;br /&gt;
&lt;br /&gt;
Stored procedure which removes wanted email addresses from newsletter tables&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER //&lt;br /&gt;
DROP PROCEDURE IF EXISTS drupal6.removeSubscribers//&lt;br /&gt;
CREATE PROCEDURE drupal6.removeSubscribers(IN emailsToRemove VARCHAR(2000))&lt;br /&gt;
  BEGIN&lt;br /&gt;
   SELECT REPLACE(emailsToRemove,' ','') INTO emailsToRemove;&lt;br /&gt;
   SELECT REPLACE(emailsToRemove,',','\',\'') INTO emailsToRemove;&lt;br /&gt;
   SELECT CONCAT('\'', emailsToRemove, '\'') INTO emailsToRemove;&lt;br /&gt;
   SET @sql1 = CONCAT('DELETE FROM simplenews_snid_tid WHERE snid IN (SELECT snid FROM simplenews_subscriptions WHERE mail IN (', emailsToRemove, ')) LIMIT 200');&lt;br /&gt;
   SET @sql2 = CONCAT('DELETE FROM simplenews_subscriptions WHERE mail IN (', emailsToRemove, ') LIMIT 200');&lt;br /&gt;
   PREPARE stmt1 FROM @sql1;&lt;br /&gt;
   PREPARE stmt2 FROM @sql2;&lt;br /&gt;
   EXECUTE stmt1;&lt;br /&gt;
   EXECUTE stmt2;&lt;br /&gt;
   SELECT CONCAT('Email addresses removed: ',ROW_COUNT()) AS 'Affected Rows';&lt;br /&gt;
   DEALLOCATE PREPARE stmt1;&lt;br /&gt;
   DEALLOCATE PREPARE stmt2;&lt;br /&gt;
   #SELECT @sql1;&lt;br /&gt;
  END //&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example call:&lt;br /&gt;
 CALL drupal6.removeSubscribers('email1@yahoo.com,email2@hotmail.com, email3@google.com');&lt;br /&gt;
&lt;br /&gt;
== MySQL Datatypes ==&lt;br /&gt;
&lt;br /&gt;
=== Text Types ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHAR( )	A fixed section from 0 to 255 characters long.&lt;br /&gt;
VARCHAR( )	A variable section from 0 to 255 characters long, e.g. VARCHAR(20)&lt;br /&gt;
TINYTEXT	A string with a maximum length of 255 characters.&lt;br /&gt;
TEXT		A string with a maximum length of 65535 characters.&lt;br /&gt;
BLOB		A string with a maximum length of 65535 characters.&lt;br /&gt;
MEDIUMTEXT	A string with a maximum length of 16777215 characters.&lt;br /&gt;
MEDIUMBLOB	A string with a maximum length of 16777215 characters.&lt;br /&gt;
LONGTEXT	A string with a maximum length of 4294967295 characters.&lt;br /&gt;
LONGBLOB	A string with a maximum length of 4294967295 characters.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Number Types ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TINYINT( )	-128 to 127 normal&lt;br /&gt;
		0 to 255 UNSIGNED.&lt;br /&gt;
TINYINT(1)	Boolean. 0 is FALSE and others TRUE.&lt;br /&gt;
SMALLINT( )	-32768 to 32767 normal&lt;br /&gt;
		0 to 65535 UNSIGNED.&lt;br /&gt;
MEDIUMINT( )	-8388608 to 8388607 normal&lt;br /&gt;
		0 to 16777215 UNSIGNED.&lt;br /&gt;
INT( )		-2147483648 to 2147483647 normal&lt;br /&gt;
		0 to 4294967295 UNSIGNED.&lt;br /&gt;
BIGINT( )	-9223372036854775808 to 9223372036854775807 normal&lt;br /&gt;
		0 to 18446744073709551615 UNSIGNED.&lt;br /&gt;
FLOAT		A small number with a floating decimal point.&lt;br /&gt;
DOUBLE( , )	A large number with a floating decimal point.&lt;br /&gt;
DECIMAL( , )	A DOUBLE stored as a string , allowing for a fixed decimal point.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Serial ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;SERIAL&amp;lt;/code&amp;gt; is an alias for &amp;lt;code&amp;gt;BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE&amp;lt;/code&amp;gt;. Good option e.g. for first ID-column.&lt;br /&gt;
&lt;br /&gt;
=== Date Types ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DATE		YYYY-MM-DD&lt;br /&gt;
DATETIME	YYYY-MM-DD HH:MM:SS&lt;br /&gt;
TIMESTAMP	e.g. YYYYMMDDHHMMSS (basicly same as datetime)&lt;br /&gt;
TIME		HH:MM:SS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=23</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=23"/>
		<updated>2019-09-08T19:40:01Z</updated>

		<summary type="html">&lt;p&gt;Creator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to KnowledgeNerd.net! The purpose of this website is to provide useful information related to servers, coding, web development etc. It's kind of an online notebook for a full stack developer with a bad memory (like me) :D I hope others find it useful too, even though some content might be quite old. Some of the tips might have been partly copied from other sources. If I haven't remembered to provide the source or link to the original webpage and you feel it would be appropriate in that specific case, please contact me.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
[[Linux_commands|Linux commands]]&lt;br /&gt;
&lt;br /&gt;
[[SQL|SQL]]&lt;br /&gt;
&lt;br /&gt;
[[MySQL_Server|MySQL Server]]&lt;br /&gt;
&lt;br /&gt;
[[Mysqldump|mysqldump]]&lt;br /&gt;
&lt;br /&gt;
[[Special:AllPages| See all Pages]]&lt;br /&gt;
&lt;br /&gt;
[[Special:Categories|See all Categories]]&lt;br /&gt;
&lt;br /&gt;
[https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Disclaimer: This site doesn't take any responsibility regarding the tips and commands provided here. Even though the tips have been tested and found working, the consequences might be different in other use cases and context.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=22</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=22"/>
		<updated>2019-09-08T19:35:52Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to KnowledgeNerd.net! The purpose of this website is to provide useful information related to servers, coding, web development etc. It's kind of an online notebook for a full stack developer with a bad memory (like me) :D I hope others find it useful too. Some of the tips might have been partly copied from other sources. If I haven't remembered to provide the source or link to the original webpage and you feel it would be appropriate in that specific case, please contact me.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
[[Linux_commands|Linux commands]]&lt;br /&gt;
&lt;br /&gt;
[[SQL|SQL]]&lt;br /&gt;
&lt;br /&gt;
[[MySQL_Server|MySQL Server]]&lt;br /&gt;
&lt;br /&gt;
[[Mysqldump|mysqldump]]&lt;br /&gt;
&lt;br /&gt;
[[Special:AllPages| See all Pages]]&lt;br /&gt;
&lt;br /&gt;
[[Special:Categories|See all Categories]]&lt;br /&gt;
&lt;br /&gt;
[https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Disclaimer: This site doesn't take any responsibility regarding the tips and commands provided here. Even though the tips have been tested and found working, the consequences might be different in other use cases and context.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=SQL&amp;diff=21</id>
		<title>SQL</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=SQL&amp;diff=21"/>
		<updated>2019-09-08T19:32:59Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;== SQL and MySQL queries ==   === Select ===  ==== ROW_COUNT / Affected Rows ====   SELECT ROW_COUNT(); ROW_COUNT() returns the number of rows changed, deleted, or inserted by...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== SQL and MySQL queries ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Select ===&lt;br /&gt;
&lt;br /&gt;
==== ROW_COUNT / Affected Rows ====&lt;br /&gt;
&lt;br /&gt;
 SELECT ROW_COUNT();&lt;br /&gt;
ROW_COUNT() returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE, DELETE, or INSERT. For other statements, the value may not be meaningful.&lt;br /&gt;
&lt;br /&gt;
==== Concatenate ====&lt;br /&gt;
&lt;br /&gt;
 SELECT CONCAT('Rows affected: ',ROW_COUNT()) AS 'Affected Rows';&lt;br /&gt;
&lt;br /&gt;
==== CASE ====&lt;br /&gt;
&lt;br /&gt;
Case Expression / conditional statement / if statement&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT CASE WHEN columnZ &amp;lt;&amp;gt; 0 THEN 4&lt;br /&gt;
            WHEN columnY &amp;lt;&amp;gt; 0 THEN 3&lt;br /&gt;
            WHEN columnX &amp;lt;&amp;gt; 0 THEN 2&lt;br /&gt;
            WHEN columnW &amp;lt;&amp;gt; 0 THEN 1&lt;br /&gt;
            ELSE 0&lt;br /&gt;
       END AS your_alias_name&lt;br /&gt;
FROM ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT u.name,&lt;br /&gt;
  up.points,&lt;br /&gt;
  CASE WHEN u.access &amp;lt;&amp;gt; 0 THEN FROM_UNIXTIME(u.access) ELSE '' END AS 'Last activity on site',&lt;br /&gt;
FROM userpoints up INNER JOIN users u ON up.uid = u.uid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sort ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Joins ===&lt;br /&gt;
&lt;br /&gt;
MySQL cases (can apply to MS SQL also, but not confirmed yet).&lt;br /&gt;
&lt;br /&gt;
Different &amp;lt;code&amp;gt;JOIN&amp;lt;/code&amp;gt; types:&lt;br /&gt;
* '''JOIN''' or '''INNER JOIN''': Return rows when there is at least one match in both tables&lt;br /&gt;
* '''LEFT JOIN''': Return all rows from the left table, even if there are no matches in the right table&lt;br /&gt;
* '''RIGHT JOIN''': Return all rows from the right table, even if there are no matches in the left table&lt;br /&gt;
* '''FULL JOIN''': Return rows when there is a match in one of the tables&lt;br /&gt;
&lt;br /&gt;
Example data:&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse; float: left;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;5&amp;quot; | Persons table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;text-align: left;&amp;quot; | P_Id&lt;br /&gt;
!Lastname&lt;br /&gt;
!Firstname&lt;br /&gt;
!Address&lt;br /&gt;
!City&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|Hansen&lt;br /&gt;
|Ola&lt;br /&gt;
|Timoteivn 10&lt;br /&gt;
| Sandnes&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|Svendson&lt;br /&gt;
|Tove&lt;br /&gt;
|Borgvn 23&lt;br /&gt;
| Sandnes&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|Pettersen&lt;br /&gt;
|Kari&lt;br /&gt;
|Storgt 20&lt;br /&gt;
|Stavanger&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border-collapse: collapse; border: 1px solid #000000; margin-left: 340px;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;3&amp;quot; | Orders table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | O_Id&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | OrderNo&lt;br /&gt;
! style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | P_Id&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 1&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 77895&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 2&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 44678&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 3&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 22456&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 4&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 24562&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 5&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 34764&lt;br /&gt;
| style=&amp;quot;border: 1px solid #000000; text-align: left;&amp;quot; | 15&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== INNER JOIN ====&lt;br /&gt;
&lt;br /&gt;
INNER JOIN is same as JOIN. As a matter of fact INNER JOIN is a default type of JOIN and that's why you don't have to include INNER keyword. Returns rows when there is at least one match in both tables.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
INNER JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The result-set will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola     24562&lt;br /&gt;
Hansen    Ola     22456&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Other examples:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT mes.*, ind.uid&lt;br /&gt;
FROM pm_message mes&lt;br /&gt;
INNER JOIN pm_index ind ON mes.mid = ind.mid&lt;br /&gt;
WHERE ind.uid = 1234&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== LEFT JOIN ====&lt;br /&gt;
&lt;br /&gt;
The LEFT JOIN keyword returns all rows from the left table (first table), even if there are no matches in the right table (table to join).&lt;br /&gt;
&lt;br /&gt;
'''Note!''' In some databases LEFT JOIN is called LEFT OUTER JOIN. In MySQL LEFT OUTER JOIN is equal to LEFT JOIN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
LEFT JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result-set will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola     22456&lt;br /&gt;
Hansen    Ola   24562&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
Svendson  Tove    &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== RIGHT JOIN ====&lt;br /&gt;
&lt;br /&gt;
The RIGHT JOIN keyword returns all the rows from the right table (second table), even if there are no matches in the left table (first table).&lt;br /&gt;
&lt;br /&gt;
'''Note!''' In some databases RIGHT JOIN is called RIGHT OUTER JOIN. In MySQL RIGHT OUTER JOIN is equal to RIGHT JOIN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
RIGHT JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result-set will look like this (all the orders with containing persons - if any):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
            34764&lt;br /&gt;
Hansen    Ola   22456&lt;br /&gt;
Hansen    Ola   24562&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== FULL JOIN ====&lt;br /&gt;
&lt;br /&gt;
The FULL JOIN keyword return rows when there is a match in one of the tables. FULL JOIN = FULL OUTER JOIN.&lt;br /&gt;
* '''Note!''' MySQL lacks support for FULL OUTER JOIN.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo&lt;br /&gt;
FROM Persons&lt;br /&gt;
FULL JOIN Orders&lt;br /&gt;
ON Persons.P_Id=Orders.P_Id&lt;br /&gt;
ORDER BY Persons.LastName&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola   22456&lt;br /&gt;
Hansen    Ola     24562&lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
Svendson  Tove   &lt;br /&gt;
            34764&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With '''MySQL''' you can mitigate the FULL JOIN by using LEFT JOIN, RIGHT JOIN and UNION together.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT p.LastName, p.FirstName, o.OrderNo&lt;br /&gt;
FROM persons p&lt;br /&gt;
LEFT JOIN orders o ON p.P_Id = o.P_Id&lt;br /&gt;
UNION&lt;br /&gt;
SELECT p.LastName, p.FirstName, o.OrderNo&lt;br /&gt;
FROM persons p&lt;br /&gt;
RIGHT JOIN orders o ON p.P_Id = o.P_Id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
LastName  FirstName   OrderNo&lt;br /&gt;
Hansen    Ola   22456&lt;br /&gt;
Hansen    Ola     24562&lt;br /&gt;
Svendson  Tove    &lt;br /&gt;
Pettersen   Kari    77895&lt;br /&gt;
Pettersen   Kari    44678&lt;br /&gt;
        34764&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== UNION ====&lt;br /&gt;
&lt;br /&gt;
The UNION operator is used to combine the result-set of two or more SELECT statements.&lt;br /&gt;
&lt;br /&gt;
Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.&lt;br /&gt;
&lt;br /&gt;
SQL UNION Syntax&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT column_name(s) FROM table_name1&lt;br /&gt;
UNION&lt;br /&gt;
SELECT column_name(s) FROM table_name2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Note: The '''UNION''' operator selects only '''distinct values''' by default. To allow duplicate values, use '''UNION ALL'''. The column names in the result-set of a UNION are always equal to the column names in the first SELECT statement in the UNION.&lt;br /&gt;
&lt;br /&gt;
Example data:&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse; float: left;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; | Employees_Norway table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;text-align: left;&amp;quot; | E_ID&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | E_Name&lt;br /&gt;
|-&lt;br /&gt;
|01&lt;br /&gt;
|Hansen, Ola&lt;br /&gt;
|-&lt;br /&gt;
|02&lt;br /&gt;
|Svendson, Tove&lt;br /&gt;
|-&lt;br /&gt;
|03&lt;br /&gt;
|Svendson, Stephen&lt;br /&gt;
|-&lt;br /&gt;
|04&lt;br /&gt;
|Pettersen, Kari&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse; margin-left: 190px;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;2&amp;quot; | Employees_USA table&lt;br /&gt;
|-&lt;br /&gt;
! style=&amp;quot;text-align: left;&amp;quot; | E_ID&lt;br /&gt;
! align=&amp;quot;left&amp;quot; | E_Name&lt;br /&gt;
|-&lt;br /&gt;
|01&lt;br /&gt;
|Turner, Sally&lt;br /&gt;
|-&lt;br /&gt;
|02&lt;br /&gt;
|Kent, Clark&lt;br /&gt;
|-&lt;br /&gt;
|03&lt;br /&gt;
|Svendson, Stephen&lt;br /&gt;
|-&lt;br /&gt;
|04&lt;br /&gt;
|Scott, Stephen&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* List '''all the different employees''' in Norway and USA&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT E_Name FROM Employees_Norway&lt;br /&gt;
UNION&lt;br /&gt;
SELECT E_Name FROM Employees_USA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The result-set will look like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
E_Name&lt;br /&gt;
Hansen, Ola&lt;br /&gt;
Svendson, Tove&lt;br /&gt;
Svendson, Stephen&lt;br /&gt;
Pettersen, Kari&lt;br /&gt;
Turner, Sally&lt;br /&gt;
Kent, Clark&lt;br /&gt;
Scott, Stephen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note''': Only distinct employee names are shown.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* List '''all employees''' in Norway and USA&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT E_Name FROM Employees_Norway&lt;br /&gt;
UNION ALL&lt;br /&gt;
SELECT E_Name FROM Employees_USA&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Result:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
E_Name&lt;br /&gt;
Hansen, Ola&lt;br /&gt;
Svendson, Tove&lt;br /&gt;
Svendson, Stephen&lt;br /&gt;
Pettersen, Kari&lt;br /&gt;
Turner, Sally&lt;br /&gt;
Kent, Clark&lt;br /&gt;
Svendson, Stephen&lt;br /&gt;
Scott, Stephen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note''': Showing all names (Svendson, Stephen x 2).&lt;br /&gt;
&lt;br /&gt;
=== GROUP BY ===&lt;br /&gt;
&lt;br /&gt;
Select how many comments each users have made and sort those descending&lt;br /&gt;
 SELECT uid, COUNT(uid) AS commentcount FROM comments GROUP BY uid ORDER BY commentcount DESC&lt;br /&gt;
&lt;br /&gt;
=== IN Clause Order ===&lt;br /&gt;
&lt;br /&gt;
Result set won't be in the same order than IN-clause's ids:&lt;br /&gt;
 SELECT topic_id, topic_title from phpbb_topics where topic_id IN(5435, 23, 324)&lt;br /&gt;
&lt;br /&gt;
Result set will be ordered as you like:&lt;br /&gt;
 SELECT topic_id, topic_title from phpbb_topics where topic_id IN(5435, 23, 324) ORDER BY FIND_IN_SET(topic_id, '23,324,5435')&lt;br /&gt;
&lt;br /&gt;
=== Substring ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT SUBSTRING('Quadratically',5); // prints 'ratically'&lt;br /&gt;
SELECT SUBSTRING('foobarbar' FROM 4); // prints 'barbar'&lt;br /&gt;
SELECT SUBSTRING('Quadratically',5,6); // prints 'ratica'&lt;br /&gt;
SELECT SUBSTRING('Sakila', -3); // prints 'ila'&lt;br /&gt;
SELECT SUBSTRING('Sakila', -5, 3); // prints 'aki'&lt;br /&gt;
SELECT SUBSTRING('Sakila' FROM -4 FOR 2); // prints 'ki'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Update ===&lt;br /&gt;
&lt;br /&gt;
Update with replace:&lt;br /&gt;
Replace url_alias table's dst column's all 'forums' words with 'keskustelu'&lt;br /&gt;
 UPDATE url_alias SET dst = REPLACE(dst, 'forums', 'keskustelu')&lt;br /&gt;
&lt;br /&gt;
Update with subquery:&lt;br /&gt;
 UPDATE `gsmvalidation` SET confirmedtime = (SELECT NOW())&lt;br /&gt;
 WHERE id = (SELECT id FROM (SELECT id,uid,codesended from `gsmvalidation`) AS temp WHERE uid = 1 ORDER BY `codesended` DESC LIMIT 1)&lt;br /&gt;
&lt;br /&gt;
=== Insert ===&lt;br /&gt;
&lt;br /&gt;
Insert single row:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO `drupal6`.`url_alias` (&lt;br /&gt;
`pid` ,&lt;br /&gt;
`src` ,&lt;br /&gt;
`dst` ,&lt;br /&gt;
`language`&lt;br /&gt;
)&lt;br /&gt;
VALUES (&lt;br /&gt;
NULL , 'phpbbforum/index.php', 'forums/index.php', ''&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insert multiple rows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO url_alias (src, dst)&lt;br /&gt;
VALUES&lt;br /&gt;
('phpbbforum','forums'),&lt;br /&gt;
('phpbbforum/index.php', 'forums/index.php'),&lt;br /&gt;
('phpbbforum/viewtopic.php', 'forums/viewtopic.php');&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insert all rows from other table after emptying the destination table first:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TRUNCATE TABLE drupal622.dr_access;&lt;br /&gt;
INSERT INTO drupal622.dr_access SELECT * FROM drupal510.access;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Custom insert (there's no language column in source table):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO drupal622.dr_url_alias (pid,src,dst,language) SELECT pid,src,dst,'' FROM drupal510.url_alias&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Delete ===&lt;br /&gt;
&lt;br /&gt;
 DELETE FROM Persons WHERE LastName = 'Smith'&lt;br /&gt;
&lt;br /&gt;
=== Time and date ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Convert timestamp to date'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT u.created FROM users u // 1346693013&lt;br /&gt;
SELECT FROM_UNIXTIME(u.created) as 'User created' FROM users u // 2012-09-03 18:23:33&lt;br /&gt;
SELECT DATE(FROM_UNIXTIME(u.created)) as 'User created' FROM users u // 2012-09-03&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Convert date to timestamp'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT UNIX_TIMESTAMP('2012-08-01') // 1343775600&lt;br /&gt;
SELECT UNIX_TIMESTAMP('2012-08-01 01:02:03') //1343779323&lt;br /&gt;
// post_time = timestamp&lt;br /&gt;
SELECT * FROM phpbb_posts WHERE post_time BETWEEN UNIX_TIMESTAMP('2012-08-01') AND UNIX_TIMESTAMP('2012-09-05')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Convert datetime field values (CAST &amp;amp; DATE_FORMAT)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT confirmedtime FROM gsm WHERE uid = 1 //2010-10-27 14:58:39&lt;br /&gt;
SELECT CAST(confirmedtime AS DATE) AS confirmedtime FROM gsm WHERE uid = 1 //2010-10-27&lt;br /&gt;
SELECT CAST('2012-09-04' AS DATETIME) // 2012-09-04 00:00:00&lt;br /&gt;
SELECT CAST('2012-09-04' AS DATE) // 2012-09-04&lt;br /&gt;
SELECT DATE_FORMAT(confirmedtime,'%d.%m.%Y') AS confirmedtime FROM gsm WHERE uid = 1 //27.10.2010&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select current datetime or timestamp&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT NOW()     -- 2010-09-09 08:54:53&lt;br /&gt;
SELECT CURDATE() -- 2010-09-09&lt;br /&gt;
SELECT CURTIME() -- 08:55:35&lt;br /&gt;
SELECT UNIX_TIMESTAMP(NOW()) -- 1314961714&lt;br /&gt;
SELECT UNIX_TIMESTAMP('2005-03-27 02:00:00') -- 1111885200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select something where date is 2012-09-04&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// userdata is in following format (timestamp-id): 1346746755-193&lt;br /&gt;
// two hours is added to timestamp to get Finnish time (GMT+2)&lt;br /&gt;
WHERE DATE(FROM_UNIXTIME((SELECT SUBSTRING(userdata, 1,10)+7200))) = CAST('2012-09-04' AS DATE)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Minus 1 day from current time for begintime field and add 20 years to endtime field&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT DATE_SUB(NOW(), INTERVAL 1 DAY), DATE_ADD(`endtime`, INTERVAL 20 YEAR)&lt;br /&gt;
FROM `publishdates`&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update rows which don't have publish from value (startpublish_value). new value this time - 2 days.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UPDATE `publishdates`&lt;br /&gt;
SET `startpublish` = DATE_SUB(NOW(), INTERVAL 2 DAY)&lt;br /&gt;
WHERE `startpublish` IS NULL OR `field_startpublish_value` = '0000-00-00 00:00:00'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Insert data to datetime (YYYY-mm-dd H:i:s) and date formatted fields&lt;br /&gt;
 INSERT INTO logs (datetime,date) VALUES ('2005-06-12 23:56:25', '2005-06-12');&lt;br /&gt;
&lt;br /&gt;
If you are using a DATE_FORMAT function to format date e.g. '%d.%m.%Y' and use variable placeholders e.g. %f, '%s' in same sql, you have to add DATE_FORMAT parameters through variable placeholder. Otherwise day %d takes the first variables value. Right way to do it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$dateFormat = &amp;quot;%d.%m.%Y&amp;quot;;&lt;br /&gt;
$gsmValidated = db_fetch_object(db_query(&amp;quot;SELECT DATE_FORMAT(confirmedtime, '%s') AS confirmedtime FROM gsmvalidation WHERE uid = %f AND gsmtoconfirm = '%s' AND confirmedtime != '' ORDER BY `confirmedtime` DESC LIMIT 1&amp;quot;, $dateFormat, $uid, $gsmnumberStr));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
cast and between&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
// $D1 and $D2 are posted variables in PHP&lt;br /&gt;
SELECT * FROM Sales WHERE TransactionDate BETWEEN CAST('$D1' as DATETIME) and CAST($D2 as DATETIME)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Auto Increment Values ===&lt;br /&gt;
&lt;br /&gt;
==== Show Next Value ====&lt;br /&gt;
&lt;br /&gt;
Show next autoincrement value from files-table (check Auto_increment column):&lt;br /&gt;
 SHOW TABLE STATUS LIKE 'files'&lt;br /&gt;
or better way to do it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT AUTO_INCREMENT FROM information_schema.tables&lt;br /&gt;
WHERE table_name = 'files'&lt;br /&gt;
AND table_schema = 'drupal6'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or show each tables' auto_increment values:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT table_name, AUTO_INCREMENT FROM information_schema.tables&lt;br /&gt;
WHERE AUTO_INCREMENT IS NOT NULL AND table_schema = 'drupal6'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
or select highest autoincrement value and add 1 to it:&lt;br /&gt;
 SELECT MAX(fid)+1 FROM 'files'&lt;br /&gt;
* Note: If someone inserted new row after your query the next id is not up to date anymore. That happens also if the row with max id have been deleted.&lt;br /&gt;
&lt;br /&gt;
==== Show Updated Row's Auto Increment ID Value ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
INSERT INTO 'files' ('fid', 'filename') VALUES ('','image.jpg');&lt;br /&gt;
SELECT LAST_INSERT_ID();&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Reset Autoincrement Value ====&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE visitors AUTO_INCREMENT = 1&lt;br /&gt;
&lt;br /&gt;
If the highest value for the column is already greater than new auto-increment value then it will be set to the highest value plus 1&lt;br /&gt;
&lt;br /&gt;
=== Replace ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
REPLACE('where_to_look', 'what_to_look', 'the_replacement')&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Select name and age. Convert the age column to number and replace 'years' string and whitespaces.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT name, CONVERT(INT, REPLACE(REPLACE(age, 'years', ''), ' ', '')) AS age&lt;br /&gt;
FROM persons&lt;br /&gt;
ORDER BY age DESC&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Update (limit to 10) nodes_revisions table's body fields content. Change readfile paths from &amp;lt;code&amp;gt;/var/www/html/&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;/srv/www/docroot/&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
UPDATE node_revisions&lt;br /&gt;
SET body = REPLACE(body, '/var/www/html/', '/srv/www/docroot/')&lt;br /&gt;
WHERE body LIKE '%readfile(\'/var/www%'&lt;br /&gt;
LIMIT 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Convert And Cast ===&lt;br /&gt;
&lt;br /&gt;
==== Convert String Into a Number ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
-- content string is 1346761037-192&lt;br /&gt;
SELECT CAST(SUBSTRING(content, 12) AS UNSIGNED INTEGER) AS theID&lt;br /&gt;
SELECT CONVERT(SUBSTRING(content, 12), SIGNED INTEGER) AS theID&lt;br /&gt;
SELECT SUBSTRING(content, 12) * 1 AS theID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Convert BLOB Into a String ====&lt;br /&gt;
&lt;br /&gt;
 SELECT CONVERT(exampleColumn USING utf8) AS exampleColumn FROM exampleTable&lt;br /&gt;
&lt;br /&gt;
* In PhpMyAdmin you can also:&lt;br /&gt;
** download the blob data, by clicking e.g. [BLOB - 6B] link (activates download), downloading it to your computer and opening it with text editor.&lt;br /&gt;
** select &amp;quot;+ Options&amp;quot; from browse data mode and select &amp;lt;code&amp;gt;Show BLOB contents&amp;lt;/code&amp;gt; checkbox.&lt;br /&gt;
&lt;br /&gt;
==== Search String From BLOB ====&lt;br /&gt;
&lt;br /&gt;
BLOB data is stored as a binary data thus it's case sensitive. You can make a case sensitive query by (returns only 'The'):&lt;br /&gt;
 SELECT * FROM `dr_locales_source` WHERE source LIKE '%The%'&lt;br /&gt;
&lt;br /&gt;
If you want to make case-insensitive comparison (e.g. The, the, thE), you can convert BLOB to string using utf8 encoding:&lt;br /&gt;
 SELECT * FROM `dr_locales_source` WHERE CONVERT(source USING UTF8) LIKE '%The%'&lt;br /&gt;
&lt;br /&gt;
=== NULL ===&lt;br /&gt;
&lt;br /&gt;
Find NULL values:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT * FROM USERS&lt;br /&gt;
WHERE 'middle_name' IS NULL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find values different than NULL:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT * FROM USERS&lt;br /&gt;
WHERE 'middle_name' IS NOT NULL&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Explain ===&lt;br /&gt;
&lt;br /&gt;
* Good source: http://www.slideshare.net/phpcodemonkey/mysql-explain-explained&lt;br /&gt;
&lt;br /&gt;
Tool to optimize queries. The '''EXPLAIN''' statement can be used either as a way to obtain information about how MySQL executes a statement, or as a synonym for '''DESCRIBE'''.&lt;br /&gt;
&lt;br /&gt;
Get details of the table:&lt;br /&gt;
 EXPLAIN drupal7.node_revision&lt;br /&gt;
 DESCRIBE drupal7.node_revision&lt;br /&gt;
&lt;br /&gt;
Obtain information about the query:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
EXPLAIN SELECT n.nid, n.title, n.type, frb.body_value, nr . *&lt;br /&gt;
FROM node n&lt;br /&gt;
JOIN node_revision nr ON n.nid = nr.nid&lt;br /&gt;
JOIN field_revision_body frb ON n.nid = frb.entity_id&lt;br /&gt;
ORDER BY n.nid DESC&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''EXPLAIN EXTENDED''' can be used to obtain additional information.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
EXPLAIN EXTENDED SELECT n.nid, n.title&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* A good way to keep up to date which queries need optimization and further investigation with &amp;lt;code&amp;gt;EXPLAIN&amp;lt;/code&amp;gt; statement is to enable '''MySQL's Slow Query Log'''&lt;br /&gt;
&lt;br /&gt;
* Use the mysqladmin command line tool to identify more general problems. The Following query will show mysql server's extended status information and updates it every 10 seconds.&lt;br /&gt;
 mysqladmin -u dbuser -p -r -i 10 extended-status&lt;br /&gt;
&lt;br /&gt;
Example: Booking application schema&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;4&amp;quot; | attendees table&lt;br /&gt;
|-&lt;br /&gt;
!attendee_id&lt;br /&gt;
!surname&lt;br /&gt;
!conference_id&lt;br /&gt;
!registration_status&lt;br /&gt;
|-&lt;br /&gt;
| INTEGER (PK)&lt;br /&gt;
| VARCHAR&lt;br /&gt;
| INTEGER(FK)&lt;br /&gt;
| TINYINT&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;2&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
! colspan=&amp;quot;4&amp;quot; | conferences table&lt;br /&gt;
|-&lt;br /&gt;
!conference_id&lt;br /&gt;
!location_id&lt;br /&gt;
!topic_id&lt;br /&gt;
!date&lt;br /&gt;
|-&lt;br /&gt;
| INTEGER (PK)&lt;br /&gt;
| INTEGER(FK)&lt;br /&gt;
| INTEGER(FK)&lt;br /&gt;
| DATE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
EXPLAIN SELECT * FROM attendees WHERE conference_id = 123 AND registration_status &amp;gt; 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''possible_keys''' - All possible indicies mysql could use. Query will choose the best one of the availeble ones (if any).&lt;br /&gt;
* '''key''' - The chosen index key for the query. If NULL, no useful index was found --&amp;gt; query needs to be optimized.&lt;br /&gt;
* '''rows''' - All the rows needed to scan for your query&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
!table&lt;br /&gt;
!possible_keys&lt;br /&gt;
!key&lt;br /&gt;
!rows&lt;br /&gt;
|-&lt;br /&gt;
|attendees&lt;br /&gt;
|NULL&lt;br /&gt;
|NULL&lt;br /&gt;
|14052&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Conclusion:&lt;br /&gt;
* No suitable indexes found for this query&lt;br /&gt;
* Mysql had to do a full table scan (almost always the slowest query)&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE ADD INDEX conf (conference_id);&lt;br /&gt;
 ALTER TABLE ADD INDEX reg (registration_status);&lt;br /&gt;
 EXPLAIN SELECT * FROM attendees WHERE conference_id = 123 AND registration_status &amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
{| cellpadding=&amp;quot;2&amp;quot; border=&amp;quot;1&amp;quot; style=&amp;quot;border-collapse: collapse;&amp;quot;&lt;br /&gt;
!table&lt;br /&gt;
!possible_keys&lt;br /&gt;
!key&lt;br /&gt;
!rows&lt;br /&gt;
|-&lt;br /&gt;
|attendees&lt;br /&gt;
|conf,reg&lt;br /&gt;
|conf&lt;br /&gt;
|331&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
* Mysql chose the more unique index '''conf''' and had to scan only 331 rows compared to previous full table scan with 14052 rows&lt;br /&gt;
&lt;br /&gt;
== MySQL ==&lt;br /&gt;
&lt;br /&gt;
=== Databases ===&lt;br /&gt;
&lt;br /&gt;
==== Create a Database ====&lt;br /&gt;
&lt;br /&gt;
===== mysql Commandline Tool =====&lt;br /&gt;
&lt;br /&gt;
First access the MySQL server&lt;br /&gt;
 mysql -u root -p&lt;br /&gt;
&lt;br /&gt;
Create database&lt;br /&gt;
 CREATE DATABASE exampledatabase;&lt;br /&gt;
&lt;br /&gt;
If you want to grant permissions also for someone else than root user&lt;br /&gt;
 GRANT ALL ON exampledatabase.* TO exampleuser@localhost IDENTIFIED BY &amp;quot;examplepassword&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
Exit mysql admin&lt;br /&gt;
 quit&lt;br /&gt;
&lt;br /&gt;
You can now test login with previously specified user&lt;br /&gt;
 mysql -u exampleuser -p&lt;br /&gt;
&lt;br /&gt;
Check if you see the right databases&lt;br /&gt;
 SHOW DATABASES;&lt;br /&gt;
&lt;br /&gt;
==== Select a Database ====&lt;br /&gt;
&lt;br /&gt;
 USE exampledatabase;&lt;br /&gt;
&lt;br /&gt;
==== Delete / Drop a Database ====&lt;br /&gt;
&lt;br /&gt;
 DROP DATABASE `phpbb3seo`&lt;br /&gt;
Note! MySQL won't free the space after database is deleted. Instead of that it will reuse the space later when new data is added. File is probably: /var/lib/mysql/ibdata1.&lt;br /&gt;
* To shrink the size you will need to dump all databases and then restore them again.&lt;br /&gt;
* You can also do the following: Set innodb_file_per_table in your config file, which will create a separate file per table. That will then allow you to delete these files once a database is dropped and also allow you to use the OPTIMIZE TABLE command to rebuild ibd files if you shrink the data in a particular table.&lt;br /&gt;
&lt;br /&gt;
=== Tables ===&lt;br /&gt;
&lt;br /&gt;
[[MySQL_Server#MySQL_Datatypes | MySQL Datatypes]]&lt;br /&gt;
&lt;br /&gt;
==== Create a Table ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE IF NOT EXISTS `url_alias` (&lt;br /&gt;
  `pid` int(10) unsigned NOT NULL AUTO_INCREMENT,&lt;br /&gt;
  `src` varchar(128) NOT NULL DEFAULT '',&lt;br /&gt;
  `dst` varchar(128) NOT NULL DEFAULT '',&lt;br /&gt;
  `language` varchar(12) NOT NULL DEFAULT '',&lt;br /&gt;
  PRIMARY KEY (`pid`),&lt;br /&gt;
  UNIQUE KEY `dst_language_pid` (`dst`,`language`,`pid`),&lt;br /&gt;
  KEY `src_language_pid` (`src`,`language`,`pid`)&lt;br /&gt;
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=35;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a Temporary Table ====&lt;br /&gt;
&lt;br /&gt;
todo&lt;br /&gt;
&lt;br /&gt;
==== Copy a Table ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE TABLE `drupal6`.`permission_bak` (&lt;br /&gt;
`pid` int( 11 ) NOT NULL AUTO_INCREMENT ,&lt;br /&gt;
`rid` int( 10 ) unsigned NOT NULL DEFAULT '0',&lt;br /&gt;
`perm` longtext,&lt;br /&gt;
`tid` int( 10 ) unsigned NOT NULL DEFAULT '0',&lt;br /&gt;
PRIMARY KEY ( `pid` ) ,&lt;br /&gt;
KEY `rid` ( `rid` )&lt;br /&gt;
) ENGINE = MYISAM DEFAULT CHARSET = utf8;&lt;br /&gt;
&lt;br /&gt;
INSERT INTO `drupal6`.`permission_bak`&lt;br /&gt;
SELECT *&lt;br /&gt;
FROM `drupal6`.`permission` ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete/drop Table ====&lt;br /&gt;
&lt;br /&gt;
 DROP TABLE dr_imagecache_action&lt;br /&gt;
To avoid an error message in case the table don't exist (&amp;lt;code&amp;gt;#1051 - Unknown table 'dr_imagecache_action' &amp;lt;/code&amp;gt;) use &amp;lt;code&amp;gt;IF EXISTS&amp;lt;/code&amp;gt; check:&lt;br /&gt;
 DROP TABLE IF EXISTS dr_imagecache_action&lt;br /&gt;
&lt;br /&gt;
==== Drop Multiple Tables ====&lt;br /&gt;
&lt;br /&gt;
If you want to drop multiple tables using wildcard in table name, here's solution.&lt;br /&gt;
Use &amp;lt;code&amp;gt;SHOW TABLES&amp;lt;/code&amp;gt; to get the wanted table list, e.g.&lt;br /&gt;
 SHOW TABLES LIKE 'phpbb_%';&lt;br /&gt;
&lt;br /&gt;
Then just form your remove query with resulted text:&lt;br /&gt;
 DROP TABLE phpbb_tbl1,phpbb_tbl2, phpbb_tbl3;&lt;br /&gt;
&lt;br /&gt;
If you want to do this with shell commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysql -u your_user -D your_database_name -e &amp;quot;show tables&amp;quot; -s | &lt;br /&gt;
  egrep &amp;quot;^Whatever_&amp;quot; | &lt;br /&gt;
  xargs -I &amp;quot;@@&amp;quot; echo mysql -u your_user -D your_database_name -e &amp;quot;DROP TABLE @@&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See more from: http://stackoverflow.com/questions/456751/drop-mysql-databases-matching-some-wildcard&lt;br /&gt;
&lt;br /&gt;
==== Copy Multiple Tables Using Linux Shell Scripting ====&lt;br /&gt;
&lt;br /&gt;
Execute a SQL query to get the wanted table names, e.g.&lt;br /&gt;
 SHOW TABLES LIKE 'phpbb_%';&lt;br /&gt;
&lt;br /&gt;
Save table names to text file:&lt;br /&gt;
 vim tablenames.txt&lt;br /&gt;
&lt;br /&gt;
Execute shell command to get the right queries. Pipe table names through &amp;lt;code&amp;gt;xargs&amp;lt;/code&amp;gt; which takes each line in the list of table names, and inserts it in the &amp;quot;@@&amp;quot; part in the command&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cat tablenames.txt | &lt;br /&gt;
  xargs -I &amp;quot;@@&amp;quot; echo &amp;quot;CREATE TABLE drupal6.dr_@@ LIKE drupal5bu.@@; INSERT INTO drupal6.dr_@@ SELECT * FROM drupal5bu.@@;&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can execute sql queries straight to sql-server by removing &amp;quot;echo&amp;quot;-part and adding mysql commands, e.g.&lt;br /&gt;
 mysql -u root -D database_name -e &amp;quot;sql query;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==== Rename Table ====&lt;br /&gt;
&lt;br /&gt;
 RENAME TABLE `drupal6`.`dr_imagecache_action_bak` TO `drupal6`.`dr_imagecache_action` ;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Print Table Names ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW TABLES; #print tables from current database&lt;br /&gt;
SHOW TABLES FROM drupal622; #show table names from specific database&lt;br /&gt;
SELECT table_name FROM information_schema.tables WHERE table_schema = 'drupal622'; #get table names from information_schema database&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Columns ===&lt;br /&gt;
&lt;br /&gt;
==== Edit column ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE `dr_url_alias` CHANGE `language` `language` VARCHAR( 12 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'exampledefaultvalue'&lt;br /&gt;
ALTER TABLE dr_imagecache_preset CHANGE presetid presetid int(10) UNSIGNED NOT NULL AUTO_INCREMENT&lt;br /&gt;
ALTER TABLE `dr_content_node_field` CHANGE `db_storage` `db_storage` TINYINT NOT NULL DEFAULT 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add Column ====&lt;br /&gt;
&lt;br /&gt;
Add it as a first column in table with &amp;lt;code&amp;gt;FIRST&amp;lt;/code&amp;gt; word at the end of sql.&lt;br /&gt;
 ALTER TABLE `dr_permission` ADD `pid` INT( 11 ) NOT NULL AUTO_INCREMENT FIRST&lt;br /&gt;
&lt;br /&gt;
Add timestamp column (int) after starttime column&lt;br /&gt;
 ALTER TABLE `sportlog` ADD `timestamp` INT NOT NULL AFTER `starttime`&lt;br /&gt;
&lt;br /&gt;
Add multiple columns:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER TABLE `content_type_youtube_video`&lt;br /&gt;
  ADD COLUMN `field_youtube_video_status` int(10) unsigned NOT NULL DEFAULT '1',&lt;br /&gt;
  ADD COLUMN `field_youtube_video_version` int(10) unsigned NOT NULL DEFAULT '0';&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Indexes ===&lt;br /&gt;
&lt;br /&gt;
Index types: primary, index, unique, fulltext&lt;br /&gt;
&lt;br /&gt;
==== Definition ====&lt;br /&gt;
&lt;br /&gt;
* Primary key&lt;br /&gt;
* Unique key (combination of three columns?)&lt;br /&gt;
* Key (Normal key to make data search from the table faster)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
PRIMARY KEY (`pid`),&lt;br /&gt;
UNIQUE KEY `dst_language_pid` (`dst`,`language`,`pid`),&lt;br /&gt;
KEY `src_language_pid` (`src`,`language`,`pid`)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add Index ====&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_users_roles` ADD INDEX ( `rid` )&lt;br /&gt;
&lt;br /&gt;
==== Add Unique Index ====&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_contemplate_files` ADD UNIQUE (`site`) &lt;br /&gt;
&lt;br /&gt;
==== Remove Index ====&lt;br /&gt;
&lt;br /&gt;
You might want to remove one of the duplicate indicies, e.g. if you get following message in MySQLAdmin: &amp;quot;The following indexes appear to be equal and one of them should be removed: site_2, site&amp;quot;&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_contemplate_files` DROP INDEX `site_2`&lt;br /&gt;
&lt;br /&gt;
==== Update Index ====&lt;br /&gt;
&lt;br /&gt;
To rename indexes you have to recreate the index&lt;br /&gt;
&lt;br /&gt;
 ALTER TABLE `dr_contemplate_files` DROP INDEX `site_2` ,&lt;br /&gt;
 ADD UNIQUE `site` ( `site` )&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
&lt;br /&gt;
[[MySQL_Server#Views]]&lt;br /&gt;
&lt;br /&gt;
=== Backup database using mysqldump tool ===&lt;br /&gt;
&lt;br /&gt;
[[Mysqldump]]&lt;br /&gt;
&lt;br /&gt;
=== Backup database using phpMyAdmin web ui ===&lt;br /&gt;
&lt;br /&gt;
Type e.g. URL http://localhost/phpmyadmin in your browser and choose:&lt;br /&gt;
&lt;br /&gt;
* databases --&amp;gt; export&lt;br /&gt;
* Export format: SQL&lt;br /&gt;
* Save as file (e.g. gzipped)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Restore Database ===&lt;br /&gt;
&lt;br /&gt;
'''Restore database from a file'''&lt;br /&gt;
 mysql -u root -p drupal6 &amp;lt; /root/Desktop/drupal6_20100912.sql&lt;br /&gt;
&lt;br /&gt;
If you get following error message:&lt;br /&gt;
&amp;lt;code&amp;gt;ERROR 1049 (42000): Unknown database 'drupal6'&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
...you have to create the database before restoring:&lt;br /&gt;
 mysql -u root -p -e 'CREATE DATABASE drupal6;'&lt;br /&gt;
&lt;br /&gt;
'''Restore compressed backup file'''&lt;br /&gt;
 gunzip &amp;lt; drupal6_bu_20110126.sql.gz | mysql -u root -p drupal6&lt;br /&gt;
&lt;br /&gt;
=== Restore Table ===&lt;br /&gt;
&lt;br /&gt;
'''Restore single database table from a file'''&lt;br /&gt;
 mysql -u root -p drupal6 &amp;lt; /root/Desktop/users.sql&lt;br /&gt;
&lt;br /&gt;
'''Restore compressed backup file (zip or lzip)'''&lt;br /&gt;
 gunzip &amp;lt; users.sql.gz | mysql -u root -p drupal6&lt;br /&gt;
 lzip -d &amp;lt; /var/backups/users.sql.lz | mysql -u root -p drupal6 (note! unpacks the file and removes .lz file!)&lt;br /&gt;
 lzip -d --keep &amp;lt; /var/backups/users.sql.lz | mysql -u root -p drupal6 (note! keeps .lz file, without leaving uncompressed file)&lt;br /&gt;
&lt;br /&gt;
=== Manage database users ===&lt;br /&gt;
&lt;br /&gt;
==== Show All Users ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT User,Host FROM mysql.user;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== GRANT / Create User ====&lt;br /&gt;
&lt;br /&gt;
Create example user (if doesn't exist?) and give all permissions to example database&lt;br /&gt;
 GRANT ALL PRIVILEGES ON `exampledatabase`.* TO 'exampleuser'@'localhost';&lt;br /&gt;
Create example user and give all permissions to example database and assign a password&lt;br /&gt;
 GRANT ALL ON exampledatabase.* TO exampleuser@localhost IDENTIFIED BY &amp;quot;examplepassword&amp;quot;;&lt;br /&gt;
Give example user selected permissions to drupal6_bu database&lt;br /&gt;
 GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `drupal6\_bu`.* TO 'exampleuser'@'182.128.10.2';&lt;br /&gt;
&lt;br /&gt;
Related error messages:&lt;br /&gt;
 Error: SELECT command denied to user 'drupal'@'www.site.com' for table 'url_alias'&lt;br /&gt;
&lt;br /&gt;
==== REVOKE ====&lt;br /&gt;
&lt;br /&gt;
Revoke all permissions and grant right from example user to example database&lt;br /&gt;
 REVOKE ALL PRIVILEGES ON `exampledatabase`.* FROM exampleuser@localhost;&lt;br /&gt;
 REVOKE GRANT OPTION ON `exampledatabase`.* FROM 'exampleuser'@'localhost';&lt;br /&gt;
 REVOKE DROP ON `exampledatabase`.* FROM 'exampleuser'@'localhost';&lt;br /&gt;
&lt;br /&gt;
==== DELETE USER ====&lt;br /&gt;
&lt;br /&gt;
 DROP USER exampleUser@localhost&lt;br /&gt;
&lt;br /&gt;
=== Check The Size Of Your Databases ===&lt;br /&gt;
&lt;br /&gt;
Execute the following query to your SQL Server:&lt;br /&gt;
&lt;br /&gt;
 SELECT table_schema 'Database name', sum( data_length + index_length ) / 1024 / 1024 'Database size (MB)'&lt;br /&gt;
 FROM information_schema.TABLES GROUP BY table_schema&lt;br /&gt;
&lt;br /&gt;
=== Check Database Table Information, e.g. Size (Show Table Info) ===&lt;br /&gt;
&lt;br /&gt;
* Show table information. In addition to table size it shows also a lot of other information related to tables, e.g. table's mysql engine, update time if MyISAM&lt;br /&gt;
columns: Name, Engine, Version, Row_format, Rows, Avg_row_length, Data_length, Max_data_length, Index_length, Data_free, Auto_increment, Create_time, Update_time, Check_time, Collation, Checksum, Create_options, Comment&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW TABLE STATUS&lt;br /&gt;
SHOW TABLE STATUS LIKE 'sessions'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More &amp;lt;code&amp;gt;SHOW&amp;lt;/code&amp;gt; commands: http://dev.mysql.com/doc/refman/5.1/en/show.html&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=MySQL_Server&amp;diff=20</id>
		<title>MySQL Server</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=MySQL_Server&amp;diff=20"/>
		<updated>2019-09-08T19:04:43Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;== Linux Command Line Commands For MySQL Server ==  &amp;lt;pre&amp;gt; install mysql database ................. $sudo apt-get install mysql-server install mysql client ......................&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Linux Command Line Commands For MySQL Server ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
install mysql database ................. $sudo apt-get install mysql-server&lt;br /&gt;
install mysql client ................... $sudo apt-get install mysql-client&lt;br /&gt;
&lt;br /&gt;
start mysql server ..................... $service mysql start&lt;br /&gt;
start mysql server ..................... $service mysqld start&lt;br /&gt;
start mysql server ..................... $/etc/init.d/mysql start&lt;br /&gt;
start mysql server ..................... $/etc/init.d/mysqld start&lt;br /&gt;
&lt;br /&gt;
stop mysql server ...................... $/etc/init.d/mysql stop&lt;br /&gt;
restart mysql server ................... $/etc/init.d/mysql restart&lt;br /&gt;
reload mysql server configurations ..... $/etc/init.d/mysql reload&lt;br /&gt;
reload mysql server configurations ..... $/etc/init.d/mysql force-reload&lt;br /&gt;
check the status of mysql server ....... $/etc/init.d/mysql status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Preferred commands with some Linux:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
service mysql start&lt;br /&gt;
service mysql stop&lt;br /&gt;
service mysql restart&lt;br /&gt;
or&lt;br /&gt;
service mysqld start&lt;br /&gt;
service mysqld stop&lt;br /&gt;
service mysqld restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Mac OS X Command Line Commands For MySQL Server ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
start mysql server ..................... $sudo /usr/local/mysql/support-files/mysql.server start&lt;br /&gt;
stop mysql server ...................... $sudo /usr/local/mysql/support-files/mysql.server stop&lt;br /&gt;
restart mysql server ................... $sudo /usr/local/mysql/support-files/mysql.server restart&lt;br /&gt;
reload mysql server settings ........... $sudo /usr/local/mysql/support-files/mysql.server reload&lt;br /&gt;
force-reload mysql server settings ..... $sudo /usr/local/mysql/support-files/mysql.server force-reload&lt;br /&gt;
check the status of mysql server ....... $sudo /usr/local/mysql/support-files/mysql.server status&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Start MySQL Server at System Startup ===&lt;br /&gt;
&lt;br /&gt;
To start MySQL server automatically on MAC OS X system startup, create a property list file (.plist)&lt;br /&gt;
 sudo vim /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
...and add the following lines to it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;!--?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?--&amp;gt;&lt;br /&gt;
&amp;lt;plist version=&amp;quot;1.0&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;dict&amp;gt;&lt;br /&gt;
    &amp;lt;key&amp;gt;KeepAlive&amp;lt;/key&amp;gt;&lt;br /&gt;
    &amp;lt;true /&amp;gt;&lt;br /&gt;
    &amp;lt;key&amp;gt;Label&amp;lt;/key&amp;gt;&lt;br /&gt;
    &amp;lt;string&amp;gt;com.mysql.mysqld&amp;lt;/string&amp;gt;&lt;br /&gt;
    &amp;lt;key&amp;gt;ProgramArguments&amp;lt;/key&amp;gt;&lt;br /&gt;
    &amp;lt;array&amp;gt;&lt;br /&gt;
      &amp;lt;string&amp;gt;/usr/local/mysql/bin/mysqld_safe&amp;lt;/string&amp;gt;&lt;br /&gt;
      &amp;lt;string&amp;gt;--user=mysql&amp;lt;/string&amp;gt;&lt;br /&gt;
    &amp;lt;/array&amp;gt;        &lt;br /&gt;
  &amp;lt;/dict&amp;gt;&lt;br /&gt;
&amp;lt;/plist&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then update permissions and add it to launchctl:  &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
&lt;br /&gt;
=== Disable MySQL Server at System Startup ===&lt;br /&gt;
&lt;br /&gt;
 sudo rm /Library/LaunchDaemons/com.mysql.mysql.plist&lt;br /&gt;
&lt;br /&gt;
Other way (which didn't work for me) is to search the service name:&lt;br /&gt;
 sudo launchctl list | grep -i mysql&lt;br /&gt;
and remove it e.g.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo launchctl remove com.mysql.mysqld&lt;br /&gt;
sudo launchctl remove com.mysql.mysqld.plist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== mysql Tool Command Line Commands ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect local mysql server ............. $mysql -u root -p&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Execute a Query To DB With mysql Tool ===&lt;br /&gt;
&lt;br /&gt;
Create a new database:&lt;br /&gt;
 mysql -u root -p -e 'CREATE DATABASE drupal6_bu;'&lt;br /&gt;
&lt;br /&gt;
Show all PhpBBForum tables (starting with 'phpbb_') from Drupal6 database:&lt;br /&gt;
 mysql -u root -p -e 'USE Drupal6; SHOW TABLES;' | grep 'phpbb_'&lt;br /&gt;
or with different query and writing results into a file:&lt;br /&gt;
 mysql -u root -p -N information_schema -e &amp;quot;SELECT table_name FROM TABLES WHERE table_name LIKE 'phpbb_%' AND table_schema LIKE 'Drupal6'&amp;quot; &amp;gt; phpbb_tables.txt&lt;br /&gt;
&lt;br /&gt;
* Note: &amp;lt;code&amp;gt;-N, --skip-column-names | Don't write column names in results.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Kill Stuck Processes ===&lt;br /&gt;
&lt;br /&gt;
Connect remote mysql server (you have to have mysql client installed on current computer):&lt;br /&gt;
 mysql -u root -p -h 123.12.1.1&lt;br /&gt;
&lt;br /&gt;
Show ongoing processes:&lt;br /&gt;
 SHOW PROCESSLIST;&lt;br /&gt;
 SHOW FULL PROCESSLIST;&lt;br /&gt;
&lt;br /&gt;
Kill stuck processes (using the id of wanted process):&lt;br /&gt;
 KILL 8494378;&lt;br /&gt;
&lt;br /&gt;
Even it says e.g. &amp;lt;code&amp;gt;Query OK, 0 rows affected (0.00 sec)&amp;lt;/code&amp;gt;, the process was quite sure killed. Check if the process have disappeared:&lt;br /&gt;
 SHOW PROCESSLIST;&lt;br /&gt;
&lt;br /&gt;
=== Kill Multiple Stuck Processes ===&lt;br /&gt;
&lt;br /&gt;
MySQL doesn't have a query to kill multiple processes and you have to do it one by one. There's still couple handy ways to do that.&lt;br /&gt;
&lt;br /&gt;
'''From MySQL Server Command Line'''&lt;br /&gt;
&lt;br /&gt;
* Prepare a wanted sql query, e.g.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT * FROM information_schema.processlist&lt;br /&gt;
WHERE USER = 'drupal' AND DB = 'drupal6' AND TIME &amp;gt; 200;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Option 1''': When you have all the processes as results which you want to terminate, execute following query, copy and clean the output and execute it.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT CONCAT('KILL ', ID, ';') FROM information_schema.processlist&lt;br /&gt;
WHERE USER = 'drupal' AND DB = 'drupal6' AND TIME &amp;gt; 200;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Option 2''': When you have all the processes as results which you want to terminate, execute following query and save kill statements to a file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SELECT CONCAT('KILL ', ID, ';') FROM information_schema.processlist&lt;br /&gt;
WHERE USER = 'drupal' AND DB = 'drupal6' AND TIME &amp;gt; 200 INTO OUTFILE '/tmp/sql-kill-stuck.txt';&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Execute commands from the created file&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SOURCE /tmp/sql-kill-stuck.txt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''From PHP-Script'''&lt;br /&gt;
&lt;br /&gt;
* Following is only an example, it's good to narrow the result set with WHERE statement so you don't kill e.g. possible replication threads.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$result = mysql_query(&amp;quot;SHOW FULL PROCESSLIST&amp;quot;);&lt;br /&gt;
while ($row=mysql_fetch_array($result)) {&lt;br /&gt;
  $process_id=$row[&amp;quot;Id&amp;quot;];&lt;br /&gt;
  if ($row[&amp;quot;Time&amp;quot;] &amp;gt; 200 ) {&lt;br /&gt;
    $sql=&amp;quot;KILL $process_id&amp;quot;;&lt;br /&gt;
    mysql_query($sql);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== MySQL Server Administration ==&lt;br /&gt;
&lt;br /&gt;
=== MySQL Server Configuration File ===&lt;br /&gt;
&lt;br /&gt;
You can find it by typing:&lt;br /&gt;
 find -name my.cnf&lt;br /&gt;
&lt;br /&gt;
It can locate e.g. in:&lt;br /&gt;
 /etc/mysql/my.cnf&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Enable MySQL Server Slow Query Log ====&lt;br /&gt;
&lt;br /&gt;
MySQL has a feature that allows you to log slow running queries to a file. To enable you just need to add some lines to your my.cnf file, and restart. To log the queries taking longer than two seconds to the specified log file, add the following (or uncomment lines if exists):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
log-slow-queries = /var/log/mysql/mysql-slow.log&lt;br /&gt;
long_query_time = 2&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Backup Database ===&lt;br /&gt;
&lt;br /&gt;
* [[Mysqldump |Backup database using mysqldump tool]]&lt;br /&gt;
* [[SQL#Backup_database_using_phpMyAdmin_web_ui |Backup database using phpMyAdmin web ui ]]&lt;br /&gt;
&lt;br /&gt;
=== Restore Database ===&lt;br /&gt;
&lt;br /&gt;
* [[SQL#Restore_Database]]&lt;br /&gt;
&lt;br /&gt;
== MySQL Server Logs ==&lt;br /&gt;
&lt;br /&gt;
Located e.g. in /var/www/drupal/ (files: mysql.log, mysql-slow.log)&lt;br /&gt;
* http://dev.mysql.com/doc/refman/5.1/en/server-logs.html&lt;br /&gt;
&lt;br /&gt;
== MySQL Server Tips ==&lt;br /&gt;
&lt;br /&gt;
=== Check MySQL Server Version ===&lt;br /&gt;
&lt;br /&gt;
 mysql --version&lt;br /&gt;
 // prints e.g. mysql  Ver 14.14 Distrib 5.1.37, for debian-linux-gnu (i486) using  EditLine wrapper&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== If MySQL Server is stuck and website using it is down ===&lt;br /&gt;
&lt;br /&gt;
* Click Server/Palvelin --&amp;gt; Processes/Prosessit&lt;br /&gt;
* Choose Kill/Lopeta for processes which are stuck&lt;br /&gt;
* (You can see processes also from (but can't kill them): Check ongoing queries/locks from processlist (Database: information_schema - Table: PROCESSLIST) e.g. with phpMyAdmin)&lt;br /&gt;
* If there's a lot of locked queries for certain table (e.g. phpbb_sessions) you could try to change table type e.g. from MyISAM to InnoDB&lt;br /&gt;
* If there's a lot of queries which are increasing, you can stop your webserver to prevent generating more queries&lt;br /&gt;
* Restart MySQL server if there's something wrong with the queries&lt;br /&gt;
&lt;br /&gt;
==== Kill MySQL Processes ====&lt;br /&gt;
&lt;br /&gt;
Besides phpMyAdmin, you can kill processes by typing:&lt;br /&gt;
 KILL thread_id&lt;br /&gt;
&lt;br /&gt;
* Check: [[MySQL_Server#Kill_Stuck_Processes]]&lt;br /&gt;
* More information from: http://dev.mysql.com/doc/refman/5.1/en/kill.html&lt;br /&gt;
&lt;br /&gt;
=== MyISAM vs. InnoDB ===&lt;br /&gt;
&lt;br /&gt;
Claims for different database engines. Claims aren't surely facts.&lt;br /&gt;
&lt;br /&gt;
==== MyISAM ====&lt;br /&gt;
&lt;br /&gt;
'''Pros'''&lt;br /&gt;
* Is faster for applications like phpbb&lt;br /&gt;
* Uses simpler structure thus takes less space and has better performance with simple queries&lt;br /&gt;
* Much faster for large text based primary keys&lt;br /&gt;
* You can use mysqlhotcopy which is faster than mysqldump&lt;br /&gt;
* MyISAM supports FULL-TEXT indexes while InnoDB does not&lt;br /&gt;
&lt;br /&gt;
'''Cons'''&lt;br /&gt;
* Supports only table locking&lt;br /&gt;
* No support for transactions&lt;br /&gt;
* No data integrity (e.g. relationship constraints) check, responsibility is left e.g. for database administrators and application developers.&lt;br /&gt;
&lt;br /&gt;
==== InnoDB ====&lt;br /&gt;
&lt;br /&gt;
'''Pros'''&lt;br /&gt;
* You can use inno hot backup, which don't lock the database during backup (writes ahead log). InnoDB Hot Backup has been renamed to MySQL Enterprise Backup, which is included as part of the MySQL Enterprise Edition.&lt;br /&gt;
* Supports row locking&lt;br /&gt;
* Give better performance results in inserting and updating data records&lt;br /&gt;
* Uses clustered indexes to reduce IO operations for PK access&lt;br /&gt;
* Has transactions while MyISAM does not&lt;br /&gt;
* Has better crash recovery&lt;br /&gt;
* (InnoDB is newer while MyISAM is older)&lt;br /&gt;
&lt;br /&gt;
'''Cons'''&lt;br /&gt;
* No FULL-TEXT support&lt;br /&gt;
* Consumes more system resources such as RAM. As a matter of fact, it is recommended by many that InnoDB engine be turned off if there’s no substantial need for it after installation of MySQL.&lt;br /&gt;
&lt;br /&gt;
==== Conclusions ====&lt;br /&gt;
&lt;br /&gt;
* If your project is small and doesn't have any issues with DB leave MyISAM&lt;br /&gt;
* If you have write-heavy load (like community site, where users add many content items) choose InnoDB&lt;br /&gt;
&lt;br /&gt;
==== Change Table Engine From MyISAM to InnoDB And Vice Versa  ====&lt;br /&gt;
&lt;br /&gt;
To change a MyISAM table to an InnoDB table:&lt;br /&gt;
 ALTER TABLE table_name ENGINE = InnoDB;&lt;br /&gt;
&lt;br /&gt;
To convert an InnoDB table to a MyISAM table:&lt;br /&gt;
 ALTER TABLE table_name ENGINE = MyISAM;&lt;br /&gt;
&lt;br /&gt;
* Tip: When converting from MyISAM to InnoDB you can speed up the transformation. Before converting the table, adjust order so that the primary key column is in order:&lt;br /&gt;
 ALTER TABLE tablename ORDER BY 'primary_key_column';&lt;br /&gt;
&lt;br /&gt;
* This will pre-arrange the table so that it can be converted quickly without a lot of re-arranging required in MySQL. Then, simply change the table engine:&lt;br /&gt;
 ALTER TABLE tablename ENGINE = INNODB;&lt;br /&gt;
&lt;br /&gt;
== MySQL Tips ==&lt;br /&gt;
&lt;br /&gt;
=== Select inside update query ===&lt;br /&gt;
&lt;br /&gt;
If you get following error message:&lt;br /&gt;
 #1093 - You can't specify target table 'gsmvalidation' for update in FROM clause&lt;br /&gt;
&lt;br /&gt;
When executing following query:&lt;br /&gt;
 UPDATE `gsmvalidation` SET confirmedtime = (SELECT NOW()) WHERE id = (SELECT id FROM `gsmvalidation` WHERE uid = 1 ORDER BY `codesended` DESC LIMIT 1)&lt;br /&gt;
&lt;br /&gt;
The reason is that in MySQL, you can't modify the same table which you use in the SELECT part. You have to make another subquery and give alias for table name.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
 UPDATE `gsmvalidation` SET confirmedtime = (SELECT NOW())&lt;br /&gt;
 WHERE id = (SELECT id FROM (SELECT id,uid,codesended from `gsmvalidation`) AS temp WHERE uid = 1 ORDER BY `codesended` DESC LIMIT 1)&lt;br /&gt;
&lt;br /&gt;
=== MySQL server has gone away error ===&lt;br /&gt;
&lt;br /&gt;
If you get the following error while restoring a big database:&lt;br /&gt;
 ERROR 2006 (HY000) at line ##: MySQL server has gone away&lt;br /&gt;
&lt;br /&gt;
..make sure that the value &amp;lt;code&amp;gt;max_allowed_packet&amp;lt;/code&amp;gt; is big enough in /etc/my.cnf:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[mysqld]&lt;br /&gt;
max_allowed_packet=64M&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart MySQL server to apply changes. If you can't find the mysql config file, check [[Config_files | Config files page]]&lt;br /&gt;
&lt;br /&gt;
=== After Restoring Mysql Database Phpmyadmin Won't Show The Tables ===&lt;br /&gt;
&lt;br /&gt;
* Problem: I exported a production database and created a development database from the backup.  Now when I try to check the contents of the database from phpmyadmin, there's no tables in it. I can see the tables with &amp;lt;code&amp;gt;SHOW TABLES;&amp;lt;/code&amp;gt; command and from mysql command line but not from phpmyadmin.&lt;br /&gt;
&lt;br /&gt;
* Possible reason: The imported database has VIEW(S) defined by a user that don't exist in the new computer's mysql users.&lt;br /&gt;
&lt;br /&gt;
* Solution: Create a missing user or drop the view(s) and create them again with an existing user.&lt;br /&gt;
&lt;br /&gt;
* Case: Exporting and importing Drupal 6 database with Ubercart module&lt;br /&gt;
&lt;br /&gt;
Drupal 6 database includes 3 views when Uber Cart module is installed:&lt;br /&gt;
dr_uc_order_products_pair_vw, dr_uc_order_products_qty_vw, dr_uc_order_products_user_vw&lt;br /&gt;
&lt;br /&gt;
Check the information and creation script of the specific view&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
SHOW CREATE VIEW dr_uc_order_products_pair_vw&lt;br /&gt;
Results:&lt;br /&gt;
View: dr_uc_order_products_pair_vw&lt;br /&gt;
Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`drupal`@`www.p... &lt;br /&gt;
character_set_client: utf8&lt;br /&gt;
collation_connection: utf8_general_ci&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To get the full &amp;quot;Create view&amp;quot; code, click &amp;quot;Print view (with full texts)&amp;quot;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE ALGORITHM=UNDEFINED DEFINER=`drupal`@`www.yoursite.com` SQL SECURITY DEFINER VIEW `dr_uc_order_products_pair_vw` AS select `op1`.`nid` AS `nid`,`op2`.`nid` AS `pair_nid`,sum(`op2`.`qty`) AS `pair_sum_qty`,count(`op2`.`nid`) AS `order_count` from (`dr_uc_order_products` `op1` join `dr_uc_order_products` `op2`) where ((`op1`.`order_id` = `op2`.`order_id`) and (`op1`.`nid` &amp;lt;&amp;gt; `op2`.`nid`)) group by `op1`.`nid`,`op2`.`nid` order by `op1`.`nid`,count(`op2`.`nid`) desc,sum(`op2`.`qty`) desc&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you try to check the contents of the view:&lt;br /&gt;
 SELECT * FROM dr_uc_order_products_pair_vw&lt;br /&gt;
You'll get an error message:&lt;br /&gt;
 #1449 - The user specified as a definer ('drupal'@'www.yoursite.com') does not exist&lt;br /&gt;
&lt;br /&gt;
Now you can drop the views causing problem and recreate those with the right users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DROP VIEW dr_uc_order_products_pair_vw;&lt;br /&gt;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `dr_uc_order_products_pair_vw` AS select `op1`.`nid` AS `nid`,`op2`.`nid` AS `pair_nid`,sum(`op2`.`qty`) AS `pair_sum_qty`,count(`op2`.`nid`) AS `order_count` from (`dr_uc_order_products` `op1` join `dr_uc_order_products` `op2`) where ((`op1`.`order_id` = `op2`.`order_id`) and (`op1`.`nid` &amp;lt;&amp;gt; `op2`.`nid`)) group by `op1`.`nid`,`op2`.`nid` order by `op1`.`nid`,count(`op2`.`nid`) desc,sum(`op2`.`qty`) desc;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Views ==&lt;br /&gt;
&lt;br /&gt;
=== List Views ===&lt;br /&gt;
&lt;br /&gt;
Phpmyadmin shows different icon (eye) for views in table listing compared to normal tables.&lt;br /&gt;
You can get a list of all views in specific database with a sql query&lt;br /&gt;
 SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW';&lt;br /&gt;
&lt;br /&gt;
=== Check Views ===&lt;br /&gt;
&lt;br /&gt;
Shows the properties of a view and it's creation statement&lt;br /&gt;
 SHOW CREATE VIEW test_view&lt;br /&gt;
&lt;br /&gt;
=== Create Views ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `test_view` AS select `test-table`.`id` AS `id`,`test-table`.`age` AS `age` from `test-table` 	&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
..or from phpmyadmin, execute a sql query for wanted result set and click &amp;quot;Create View&amp;quot; link from bottom section of the page.&lt;br /&gt;
&lt;br /&gt;
=== Delete Views ===&lt;br /&gt;
&lt;br /&gt;
 DROP VIEW test_view&lt;br /&gt;
&lt;br /&gt;
=== Replace Views ===&lt;br /&gt;
&lt;br /&gt;
When creating a new view from phpmyadmin you can specify an existing name and check the &amp;quot;OR REPLACE&amp;quot; box.&lt;br /&gt;
&lt;br /&gt;
== Stored Procedures and Functions ==&lt;br /&gt;
&lt;br /&gt;
Since MySQL version 5.0 there have been a support for stored procedures, triggers and events. Stored procedures are saved in mysql database's proc table.&lt;br /&gt;
* http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspx&lt;br /&gt;
&lt;br /&gt;
=== Create a Stored Procedure ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER //&lt;br /&gt;
CREATE PROCEDURE GetAllArticles()&lt;br /&gt;
  BEGIN&lt;br /&gt;
  SELECT * FROM articles;&lt;br /&gt;
  END //&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Call the Stored Procedure ===&lt;br /&gt;
&lt;br /&gt;
 CALL DatabaseName.StroredPrecedureName();&lt;br /&gt;
&lt;br /&gt;
=== Alter a Stored Procedure ===&lt;br /&gt;
&lt;br /&gt;
Note! With the ALTER PROCEDURE Statement you can change only the characteristics and if you want to change in statement list then you have to DROP the procedure and CREATE again.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ALTER {PROCEDURE | FUNCTION} {proc_name | func_name} [characteristic ...]&lt;br /&gt;
  characteristic: SQL SECURITY {DEFINER | INVOKER}| COMMENT 'string'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Drop a Stored Procedure ===&lt;br /&gt;
&lt;br /&gt;
 DROP PROCEDURE IF EXISTS exampleSproc;&lt;br /&gt;
&lt;br /&gt;
=== Variables in Sprocs ===&lt;br /&gt;
&lt;br /&gt;
* Save count of articles into a variable and print it&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER //&lt;br /&gt;
CREATE PROCEDURE HowMany()&lt;br /&gt;
  BEGIN&lt;br /&gt;
  DECLARE articlecount INT DEFAULT 0;&lt;br /&gt;
  SELECT COUNT(*) INTO articlecount FROM articles;&lt;br /&gt;
  SELECT articlecount;&lt;br /&gt;
  END //&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER //&lt;br /&gt;
CREATE PROCEDURE HowMany()&lt;br /&gt;
  BEGIN&lt;br /&gt;
  DECLARE articlecount INT DEFAULT 0;&lt;br /&gt;
  SET articlecount = 33;&lt;br /&gt;
  SELECT CONCAT('Article count: ',articlecount) AS 'End Result';&lt;br /&gt;
  END //&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Parameters in Sprocs ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER $$&lt;br /&gt;
CREATE PROCEDURE testdatabase.ShowArticles(IN emails VARCHAR(255))&lt;br /&gt;
  BEGIN&lt;br /&gt;
  SELECT * FROM users WHERE email IN (emails);&lt;br /&gt;
  END $$&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* http://www.mysqltutorial.org/stored-procedures-parameters.aspx&lt;br /&gt;
&lt;br /&gt;
=== Misc Sprocs ===&lt;br /&gt;
&lt;br /&gt;
==== Remove Emails Sproc ====&lt;br /&gt;
&lt;br /&gt;
Stored procedure which removes wanted email addresses from newsletter tables&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DELIMITER //&lt;br /&gt;
DROP PROCEDURE IF EXISTS drupal6.removeSubscribers//&lt;br /&gt;
CREATE PROCEDURE drupal6.removeSubscribers(IN emailsToRemove VARCHAR(2000))&lt;br /&gt;
  BEGIN&lt;br /&gt;
   SELECT REPLACE(emailsToRemove,' ','') INTO emailsToRemove;&lt;br /&gt;
   SELECT REPLACE(emailsToRemove,',','\',\'') INTO emailsToRemove;&lt;br /&gt;
   SELECT CONCAT('\'', emailsToRemove, '\'') INTO emailsToRemove;&lt;br /&gt;
   SET @sql1 = CONCAT('DELETE FROM simplenews_snid_tid WHERE snid IN (SELECT snid FROM simplenews_subscriptions WHERE mail IN (', emailsToRemove, ')) LIMIT 200');&lt;br /&gt;
   SET @sql2 = CONCAT('DELETE FROM simplenews_subscriptions WHERE mail IN (', emailsToRemove, ') LIMIT 200');&lt;br /&gt;
   PREPARE stmt1 FROM @sql1;&lt;br /&gt;
   PREPARE stmt2 FROM @sql2;&lt;br /&gt;
   EXECUTE stmt1;&lt;br /&gt;
   EXECUTE stmt2;&lt;br /&gt;
   SELECT CONCAT('Email addresses removed: ',ROW_COUNT()) AS 'Affected Rows';&lt;br /&gt;
   DEALLOCATE PREPARE stmt1;&lt;br /&gt;
   DEALLOCATE PREPARE stmt2;&lt;br /&gt;
   #SELECT @sql1;&lt;br /&gt;
  END //&lt;br /&gt;
DELIMITER ;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example call:&lt;br /&gt;
 CALL drupal6.removeSubscribers('email1@yahoo.com,email2@hotmail.com, email3@google.com');&lt;br /&gt;
&lt;br /&gt;
== MySQL Datatypes ==&lt;br /&gt;
&lt;br /&gt;
=== Text Types ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CHAR( )	A fixed section from 0 to 255 characters long.&lt;br /&gt;
VARCHAR( )	A variable section from 0 to 255 characters long, e.g. VARCHAR(20)&lt;br /&gt;
TINYTEXT	A string with a maximum length of 255 characters.&lt;br /&gt;
TEXT		A string with a maximum length of 65535 characters.&lt;br /&gt;
BLOB		A string with a maximum length of 65535 characters.&lt;br /&gt;
MEDIUMTEXT	A string with a maximum length of 16777215 characters.&lt;br /&gt;
MEDIUMBLOB	A string with a maximum length of 16777215 characters.&lt;br /&gt;
LONGTEXT	A string with a maximum length of 4294967295 characters.&lt;br /&gt;
LONGBLOB	A string with a maximum length of 4294967295 characters.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Number Types ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TINYINT( )	-128 to 127 normal&lt;br /&gt;
		0 to 255 UNSIGNED.&lt;br /&gt;
TINYINT(1)	Boolean. 0 is FALSE and others TRUE.&lt;br /&gt;
SMALLINT( )	-32768 to 32767 normal&lt;br /&gt;
		0 to 65535 UNSIGNED.&lt;br /&gt;
MEDIUMINT( )	-8388608 to 8388607 normal&lt;br /&gt;
		0 to 16777215 UNSIGNED.&lt;br /&gt;
INT( )		-2147483648 to 2147483647 normal&lt;br /&gt;
		0 to 4294967295 UNSIGNED.&lt;br /&gt;
BIGINT( )	-9223372036854775808 to 9223372036854775807 normal&lt;br /&gt;
		0 to 18446744073709551615 UNSIGNED.&lt;br /&gt;
FLOAT		A small number with a floating decimal point.&lt;br /&gt;
DOUBLE( , )	A large number with a floating decimal point.&lt;br /&gt;
DECIMAL( , )	A DOUBLE stored as a string , allowing for a fixed decimal point.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Serial ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;SERIAL&amp;lt;/code&amp;gt; is an alias for &amp;lt;code&amp;gt;BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE&amp;lt;/code&amp;gt;. Good option e.g. for first ID-column.&lt;br /&gt;
&lt;br /&gt;
=== Date Types ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DATE		YYYY-MM-DD&lt;br /&gt;
DATETIME	YYYY-MM-DD HH:MM:SS&lt;br /&gt;
TIMESTAMP	e.g. YYYYMMDDHHMMSS (basicly same as datetime)&lt;br /&gt;
TIME		HH:MM:SS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Mysqldump&amp;diff=19</id>
		<title>Mysqldump</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Mysqldump&amp;diff=19"/>
		<updated>2019-09-08T14:38:55Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;Note! By default mysqldump uses &amp;lt;code&amp;gt;--lock-tables&amp;lt;/code&amp;gt; parameter when making a backup. That possibly prevents your website from working. * You may want to use &amp;lt;code&amp;gt;--skip...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Note! By default mysqldump uses &amp;lt;code&amp;gt;--lock-tables&amp;lt;/code&amp;gt; parameter when making a backup. That possibly prevents your website from working.&lt;br /&gt;
* You may want to use &amp;lt;code&amp;gt;--skip-lock-tables&amp;lt;/code&amp;gt; but that may cause inconsistency in the backup.&lt;br /&gt;
* You can also change all tables from MyISAM to InnoDB and use hotcopy or option &amp;lt;code&amp;gt;--single-transaction&amp;lt;/code&amp;gt;??? (haven't tested)&lt;br /&gt;
* If you are doing a backup on the server and your tables all are MyISAM tables, consider using the [http://dev.mysql.com/doc/refman/5.0/en/mysqlhotcopy.html mysqlhotcopy] instead because it can accomplish faster backups and faster restores.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Backup Whole Database ==&lt;br /&gt;
&lt;br /&gt;
Connect to the database server e.g. using SSH connection and execute following row:&lt;br /&gt;
 mysqldump -u root -p drupal6 &amp;gt; drupal6_db_bu_20100625.sql&lt;br /&gt;
&lt;br /&gt;
You can also ask mysqldump to add a drop table command before every create command by using the option --add-drop-table (this is probably the default option already). This option is useful if you would like to create a backup file which can rewrite an existing database without having to delete the older database manually first.&lt;br /&gt;
&lt;br /&gt;
 mysqldump --add-drop-table -u root -p drupal6 &amp;gt; drupal6_db_bu_20100625.sql&lt;br /&gt;
 or&lt;br /&gt;
 mysqldump --add-drop-table -p drupal6 --user=root &amp;gt; /root/Desktop/drupal6_20100912.sql&lt;br /&gt;
&lt;br /&gt;
== Backup And Compress Database ==&lt;br /&gt;
&lt;br /&gt;
 mysqldump -u root -p drupal6 | gzip &amp;gt; drupal6_db_bu_20100625.sql.gz&lt;br /&gt;
&lt;br /&gt;
== Backup Only Specified Tables ==&lt;br /&gt;
&lt;br /&gt;
Backup only &amp;quot;users&amp;quot; and &amp;quot;system&amp;quot; tables from the &amp;quot;drupal6&amp;quot; database:&lt;br /&gt;
&lt;br /&gt;
 mysqldump -u root -p drupal6 users system &amp;gt; drupal6_db_2_tables_bu_20100625.sql&lt;br /&gt;
&lt;br /&gt;
Useful command to check what tables exists in specified database:&lt;br /&gt;
 mysql -u root -p -e 'USE Drupal7; SHOW TABLES;'&lt;br /&gt;
&lt;br /&gt;
Backup and choose tables from text file. Tables have to be on the same line and separated by spaces:&lt;br /&gt;
 mysqldump -u root -p drupal6 `cat phpbb_tables_onsamerow.txt` &amp;gt; phpbb-tables-bu-20111019.sql&lt;br /&gt;
&lt;br /&gt;
=== Case: Backup All PhpBB Forum Tables ===&lt;br /&gt;
&lt;br /&gt;
* Get phpbbforum tables:&lt;br /&gt;
 mysql -u admin -p -h 123.23.1.1 -e 'USE drupal6; SHOW TABLES;' | grep 'phpbb_' &amp;gt; phpbb-tables.txt&lt;br /&gt;
&lt;br /&gt;
* Convert line breaks into spaces in phpbb-tables.txt file&lt;br /&gt;
 echo $(cat phpbb-tables.txt) &amp;gt; phpbb-tables-samerow.txt&lt;br /&gt;
&lt;br /&gt;
* Copy/backup table structure and data from source db:&lt;br /&gt;
 mysqldump -u admin -p -h 123.23.1.1 drupal6 `cat phpbb-tables-samerow.txt` &amp;gt; phpbb-tables-bu-20111020.sql&lt;br /&gt;
&lt;br /&gt;
* Restore data into a target database:&lt;br /&gt;
 mysql -u admin -p -h 123.23.1.1 drupal7 &amp;lt; phpbb-tables-bu-20111020.sql&lt;br /&gt;
&lt;br /&gt;
*Follow the progress:&lt;br /&gt;
 SHOW TABLE STATUS LIKE 'phpbb_%'&lt;br /&gt;
&lt;br /&gt;
== Backup a Remote Database ==&lt;br /&gt;
&lt;br /&gt;
 mysqldump -h xxx.xxx.xxx.xxx -u username -p database_name &amp;gt; backup_file_name_20100628.sql&lt;br /&gt;
&lt;br /&gt;
Use gzip to compress the remote database backup&lt;br /&gt;
 mysqldump -h xxx.xxx.xxx.xxx -u username -p database_name | gzip &amp;gt; backup_file_name_20100628.sql.gz&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If you get for example following error message: &amp;lt;code&amp;gt;mysqldump: Got error: 1130: Host 'xxx.xx.xxx.x' is not allowed to connect to this MySQL server when trying to connect&amp;lt;/code&amp;gt;&lt;br /&gt;
* Specified hostname or ipaddress could be wrong&lt;br /&gt;
* Check databases mysql.users table. Check the host column and user rights for the user you tried to login&lt;br /&gt;
&lt;br /&gt;
== Backup ALL Databases ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysqldump -u root -p -A &amp;gt; mysqlserver-all-db-20111016.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Backup Multiple Databases ==&lt;br /&gt;
&lt;br /&gt;
To backup specific databases, e.g. all drupal dbs:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
mysqldump -u root -p --databases drupal5 drupal6 drupal7 &amp;gt; all-drupal-db-20111016.sql&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Useful command to check what databases exists:&lt;br /&gt;
 mysql -u root -p -e 'SHOW DATABASES;'&lt;br /&gt;
&lt;br /&gt;
Check what tables mysqldump file includes:&lt;br /&gt;
 grep 'Database:' all-drupal-db-20111016.sql&lt;br /&gt;
&lt;br /&gt;
== MySQLDump Tips ==&lt;br /&gt;
&lt;br /&gt;
=== If MySQLDump Tool Is Not Found ===&lt;br /&gt;
&lt;br /&gt;
If you get a message: &amp;quot;mysqldump: command not found&amp;quot; try&lt;br /&gt;
 locate mysqldump&lt;br /&gt;
&lt;br /&gt;
If you find the mysql dump&lt;br /&gt;
add /usr/local/mysql-5.0.51a-linux-i686/bin/ to your users path&lt;br /&gt;
or copy the file to your /usr/bin folder, e.g.&lt;br /&gt;
 cp -a /usr/local/mysql-5.0.51a-linux-i686/bin/mysqldump /usr/bin&lt;br /&gt;
&lt;br /&gt;
If you don't have it in your computer install it by typing:&lt;br /&gt;
 sudo apt-get install mysql-client  (the most suitable version will be installed)&lt;br /&gt;
 sudo apt-get install mysql-client-5.0&lt;br /&gt;
 sudo apt-get install mysql-client-core-5.5&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Talk:Main_Page&amp;diff=18</id>
		<title>Talk:Main Page</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Talk:Main_Page&amp;diff=18"/>
		<updated>2019-09-07T23:12:43Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;Please join for general discussion about this website.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please join for general discussion about this website.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=KnowledgeNerd:Privacy_policy&amp;diff=17</id>
		<title>KnowledgeNerd:Privacy policy</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=KnowledgeNerd:Privacy_policy&amp;diff=17"/>
		<updated>2019-09-07T23:07:23Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;We use Google Analytics to track anonymous visits.&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;We use Google Analytics to track anonymous visits.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=KnowledgeNerd:About&amp;diff=16</id>
		<title>KnowledgeNerd:About</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=KnowledgeNerd:About&amp;diff=16"/>
		<updated>2019-09-07T23:02:41Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;The purpose of this website is to provide useful information related to servers, coding, web development etc. It's kind of an online notebook for a full stack developer with a...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The purpose of this website is to provide useful information related to servers, coding, web development etc. It's kind of an online notebook for a full stack developer with a bad memory (like me) :D I hope others find it useful too. Some of the tips might have been partly copied from other sources. If I haven't remembered to provide the source or link to the original webpage and you feel it would be appropriate in that specific case, please contact me.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=KnowledgeNerd:General_disclaimer&amp;diff=15</id>
		<title>KnowledgeNerd:General disclaimer</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=KnowledgeNerd:General_disclaimer&amp;diff=15"/>
		<updated>2019-09-07T23:02:07Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;KnowledgeNerd.net doesn't take any responsibility regarding the tips and commands provided here. Even though the tips have been tested and found working, the consequences migh...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;KnowledgeNerd.net doesn't take any responsibility regarding the tips and commands provided here. Even though the tips have been tested and found working, the consequences might be different in other use cases and context.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=14</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=14"/>
		<updated>2019-09-07T22:04:22Z</updated>

		<summary type="html">&lt;p&gt;Creator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to KnowledgeNerd.net! The purpose of this website is to provide useful information related to servers, coding, web development etc. It's kind of an online notebook for a full stack developer with a bad memory (like me) :D I hope others find it useful too. Some of the tips might have been partly copied from other sources. If I haven't remembered to provide the source or link to the original webpage and you feel it would be appropriate in that specific case, please contact me.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
[[Linux_commands|Linux commands]]&lt;br /&gt;
&lt;br /&gt;
[[Special:AllPages| See all Pages]]&lt;br /&gt;
&lt;br /&gt;
[[Special:Categories|See all Categories]]&lt;br /&gt;
&lt;br /&gt;
[https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Disclaimer: This site doesn't take any responsibility regarding the tips and commands provided here. Even though the tips have been tested and found working, the consequences might be different in other use cases and context.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=13</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=13"/>
		<updated>2019-09-07T22:03:45Z</updated>

		<summary type="html">&lt;p&gt;Creator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to KnowledgeNerd.net! The purpose of this website is to provide useful information related to servers, coding, web development etc. It's kind of an online notebook for a full stack developer with a bad memory (like me) :D I hope others find it useful too. Some of the tips might have been partly copied from other sources. If I haven't remembered to provide the source or link to the original webpage and you feel it would be appropriate in that specific case, please contact me.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
[[Linux_commands|Linux commands]]&lt;br /&gt;
&lt;br /&gt;
[[Special:AllPages| See all Pages]]&lt;br /&gt;
&lt;br /&gt;
[[Special:Categories|See all Categories]]&lt;br /&gt;
&lt;br /&gt;
[https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Disclaimer: This site doesn't take any responsibility regarding the tips and commands provided here. Even though the tips have been tested and found working, the consequence might be different in other use cases and context.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=12</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=12"/>
		<updated>2019-09-07T22:00:17Z</updated>

		<summary type="html">&lt;p&gt;Creator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Welcome to KnowledgeNerd.net! The purpose of this website is to provide useful information related to servers, coding, web development etc. It's kind of an online notebook for a full stack developer with a bad memory (like me) :D I hope others find it useful too. Some of the tips might have been partly copied from other sources. If I haven't remembered to provide the source or link to the original webpage and you feel it would be appropriate in that specific case, please notify me.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
[[Linux_commands|Linux commands]]&lt;br /&gt;
&lt;br /&gt;
[[Special:AllPages| See all Pages]]&lt;br /&gt;
&lt;br /&gt;
[[Special:Categories|See all Categories]]&lt;br /&gt;
&lt;br /&gt;
[https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Disclaimer: This site doesn't take any responsibility regarding the tips and commands provided here. Even though the tips have been tested and found working, the consequence might be different in other use cases and context.&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=11</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Main_Page&amp;diff=11"/>
		<updated>2019-09-07T21:37:09Z</updated>

		<summary type="html">&lt;p&gt;Creator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Links ==&lt;br /&gt;
&lt;br /&gt;
[[Linux_commands|Linux commands]]&lt;br /&gt;
&lt;br /&gt;
[[Special:AllPages| See all Pages]]&lt;br /&gt;
&lt;br /&gt;
[[Special:Categories|See all Categories]]&lt;br /&gt;
&lt;br /&gt;
[https://www.mediawiki.org/wiki/Special:MyLanguage/Help:Contents User's Guide]&lt;br /&gt;
&lt;br /&gt;
== Getting started ==&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Configuration_settings Configuration settings list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [https://lists.wikimedia.org/mailman/listinfo/mediawiki-announce MediaWiki release mailing list]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation#Translation_resources Localise MediaWiki for your language]&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:Combating_spam Learn how to combat spam on your wiki]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=10</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=10"/>
		<updated>2019-09-07T21:34:33Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Kill Processes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing files and directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, finding and searching inside files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List files in archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X specific permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration related commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating system restart / reboot / shut down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server related commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network related commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network interface commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=9</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=9"/>
		<updated>2019-09-07T21:33:09Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Operating system restart / reboot / shut Down */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing files and directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, finding and searching inside files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List files in archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X specific permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration related commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating system restart / reboot / shut down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server related commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network related commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network interface commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=8</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=8"/>
		<updated>2019-09-07T21:32:39Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Date and Time */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing files and directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, finding and searching inside files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List files in archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X specific permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration related commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating system restart / reboot / shut Down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server related commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network related commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network interface commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=7</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=7"/>
		<updated>2019-09-07T21:32:15Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* List Files In Archives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing files and directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, finding and searching inside files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List files in archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X specific permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and Time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration related commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating system restart / reboot / shut Down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server related commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network related commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network interface commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=6</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=6"/>
		<updated>2019-09-07T21:31:53Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Listing, Finding and Searching Inside Files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing files and directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, finding and searching inside files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List Files In Archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X specific permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and Time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration related commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating system restart / reboot / shut Down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server related commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network related commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network interface commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=5</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=5"/>
		<updated>2019-09-07T21:31:24Z</updated>

		<summary type="html">&lt;p&gt;Creator: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing files and directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, Finding and Searching Inside Files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List Files In Archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X specific permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and Time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration related commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating system restart / reboot / shut Down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server related commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network related commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network interface commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=4</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=4"/>
		<updated>2019-09-07T21:28:53Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Symbolic links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting Help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing Files And Directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and Rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing Files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic Links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, Finding and Searching Inside Files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List Files In Archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X Specific Permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and Time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job Managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration Related Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating System Restart / Reboot / Shut Down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process Handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server Related Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network Related Commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network Interface Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=3</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=3"/>
		<updated>2019-09-07T21:28:45Z</updated>

		<summary type="html">&lt;p&gt;Creator: /* Comparing files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting Help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing Files And Directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and Rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing Files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, Finding and Searching Inside Files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List Files In Archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X Specific Permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and Time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job Managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration Related Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating System Restart / Reboot / Shut Down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process Handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server Related Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network Related Commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network Interface Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
	<entry>
		<id>https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=2</id>
		<title>Linux commands</title>
		<link rel="alternate" type="text/html" href="https://knowledgenerd.net/index.php?title=Linux_commands&amp;diff=2"/>
		<updated>2019-09-07T21:27:48Z</updated>

		<summary type="html">&lt;p&gt;Creator: Created page with &amp;quot;See also: Linux_tips  * Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.  == Basic commands ==  === Getting Help ===  &amp;lt;pre&amp;gt; print mysqldump m...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also: [[Linux_tips]]&lt;br /&gt;
&lt;br /&gt;
* Note! Use &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; if you need administer rights to execute the task.&lt;br /&gt;
&lt;br /&gt;
== Basic commands ==&lt;br /&gt;
&lt;br /&gt;
=== Getting Help ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print mysqldump man page (manual) ........ $man mysqldump&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump -?&lt;br /&gt;
print mysqldump help file on the screen .. $mysqldump --help&lt;br /&gt;
search text from mysqldump help file ..... $mysqldump --help | grep 'textToSearch'&lt;br /&gt;
write mysqldump help output into a file .. $mysqldump --help &amp;gt; mysqldumphelp.txt&lt;br /&gt;
checking tar-program version ............. $tar --version&lt;br /&gt;
searching &amp;quot;version&amp;quot; text from binaries ... $strings /usr/bin/tar | grep -i 'version'&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Navigation ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
change directory ........................... $cd [directory_name]&lt;br /&gt;
parent directory ........................... $cd ..&lt;br /&gt;
your profile's home directory .............. $cd ~&lt;br /&gt;
your profile's desktop directory ........... $cd ~/Desktop&lt;br /&gt;
root directory ............................. $cd /&lt;br /&gt;
show current absolute path / directory ..... $pwd (e.g. /Users/exampleuser/Desktop)&lt;br /&gt;
show physical current working directory .... $pwd -P (all symbolic links resolved)&lt;br /&gt;
move to the start of the line .............. $CTRL+a&lt;br /&gt;
move to the end of the line ................ $CTRL+e&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Managing Files And Directories ===&lt;br /&gt;
&lt;br /&gt;
==== Copy ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
copy dir contents (when in target dir) ..... $cp -r /etc/examplefolder/* ./&lt;br /&gt;
copy dir contents preserving ownership ..... $cp -pr /etc/examplefolder/* ./ (when in target dir. by default -p preserves at least attributes: rwx-rights, ownership, mode and timestamps)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $yes n | cp -r -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. -i switch asks &amp;quot;do you wan't to overwrite&amp;quot; and piped &amp;quot;yes n&amp;quot; command answers automatically &amp;quot;no&amp;quot; to every question)&lt;br /&gt;
copy dir contents (don't overwrite) ........ $cp -r -n /etc/examplefolder/* ./ (Note! when in target dir. -n, --no-clobber : do not overwrite an existing files. Note: the option isn't available in all linux version's cp tools!)&lt;br /&gt;
COPY, DON'T OVERWRITE, PRESERVE RIGHTS ..... $yes n | cp -pr -i /etc/examplefolder/* ./ 2&amp;gt;/dev/null (when in target dir. 2&amp;gt;/dev/null hides messages.)&lt;br /&gt;
copy file .................................. $cp php.ini-dist /usr/local/lib/php.ini&lt;br /&gt;
copy multiple files ........................ $cp .htaccess robots.txt /var/www/drupal-6.17/&lt;br /&gt;
copy all files starting test ............... $cp test* /var/www/&lt;br /&gt;
copy directory (when in source dir) ........ $cp -r examplefolder /var/www/&lt;br /&gt;
copy directory (when in target dir) ........ $cp -r /etc/examplefolder ./&lt;br /&gt;
copy only if source files are newer ........ $cp -r -u /etc/examplefolder/* ./&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Delete ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
delete/remove file ......................... $rm foo.txt&lt;br /&gt;
delete/remove files ........................ $rm foo.txt foo2.txt&lt;br /&gt;
delete all files from current directory .... $rm *&lt;br /&gt;
delete all files with prompt option ........ $rm -i *  (asks remove file-xx.foo y/n with every file)&lt;br /&gt;
delete all except files starting f ......... $rm [!f]*&lt;br /&gt;
delete all except specific file ............ $rm $(ls * | grep -v example_file)&lt;br /&gt;
delete all except files foo1 &amp;amp; foo2 ........ $rm $(ls | grep -v 'index.htm' | grep -v 'data_hooks.php')&lt;br /&gt;
delete empty directory ..................... $rmdir foo&lt;br /&gt;
delete nested empty directories ............ $rmdir foo1/foo2/foo3 (same as $rmdir foo1/foo2/foo3 foo1/foo2 foo1)&lt;br /&gt;
delete directory which has content ......... $rm &amp;lt;nowiki&amp;gt;-rf&amp;lt;/nowiki&amp;gt; foo (remove a directory with no prompts)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Move and Rename ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
move a directory ........................... $mv targetdirectory/ /destination/parent/&lt;br /&gt;
move all content of a directory ............ $mv /var/www/drupal/* /var/www/drupal_old (this doesn't move hidden files e.g. .htaccess from top folder: drupal)&lt;br /&gt;
move hidden and other files to parent dir .. $mv * .[^.]* ..  (note: .[^.]* means all files starting with a dot, having other character something else than a dot, followed by other arbitrary characters)&lt;br /&gt;
move file with same name ................... $mv phpBB3.tar.bz2 /var/www/&lt;br /&gt;
move and rename file ....................... $mv phpBB3.tar.bz2 /var/www/phpBB3_bu.tar.bz2&lt;br /&gt;
rename file (or folder) .................... $mv foo.txt foo_old.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Other ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a directory ......................... $mkdir foo&lt;br /&gt;
sets the current time/date for file ........ $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists ... $touch newfile.txt&lt;br /&gt;
protect a file from deleting it ............ $chattr +i foo.txt (might require sudo. +i is to set the immutable bit to prevent even root from erasing or changing the contents of a file)&lt;br /&gt;
protect a dir recursively from deleting .... $chattr -R +i foo (might require sudo in front of the command)&lt;br /&gt;
remove write protection from file .......... $chattr -i foo.txt&lt;br /&gt;
remove write protection from dir rec ....... $chattr -R -i foo/&lt;br /&gt;
hide dir or file (only from GUI view) ...... $chflags hidden foodir / chflags hidden foo.txt (works in BSD &amp;amp; OS X, but don't provide security. Rather use password-protected/encrypted disk images)&lt;br /&gt;
hide dir or file ........................... $mv foodir .foodir / mv foo.txt .foo.txt (files and directories starting with dots &amp;quot;.&amp;quot; are hidden and you have to use &amp;quot;ls -a&amp;quot; to see them)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Comparing files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compare file contents with ............... $diff file1 file2&lt;br /&gt;
compare directory contents ............... $diff folder1 folder2&lt;br /&gt;
recursively compare any content (=subds) . $diff -r folder1 folder2&lt;br /&gt;
rec compare and print results in file .... $diff -r drupal6/modules_orig/ drupal6/modules/ &amp;gt; system_module_diffs.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[diff | More info about diff]]&lt;br /&gt;
* [[Windows#Diff_Tool_In_Windows | Diff Tool In Windows]]&lt;br /&gt;
&lt;br /&gt;
=== Symbolic links ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a symbolic link &amp;quot;drupal.php&amp;quot; ...... $ln -s /var/www/drupal6/index.php drupal.php&lt;br /&gt;
create a symbolic link &amp;quot;/logs&amp;quot; ........... $ln -s /var/log /logs&lt;br /&gt;
remove a symbolic link (only the link) ... $rm /logs&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Listing, Finding and Searching Inside Files ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files ................................. $ls&lt;br /&gt;
list php files in current dir .............. $ls *.php&lt;br /&gt;
list php files in specific dir ............. $ls examplefolder/*.php  or  $find system/ -name '*.php'&lt;br /&gt;
list files (+hidden+permissions)............ $ls -la&lt;br /&gt;
list files order by size desc .............. $ls -lh -S&lt;br /&gt;
list files order by size asc ............... $ls -lh -S -r&lt;br /&gt;
list files order by modified date desc ..... $ls -lTt (l = show details, T = show complete date/time information, t = sort by modified date, newest first)&lt;br /&gt;
list files order by modified date asc ...... $ls -lTtr (r = reverse = oldest files first)&lt;br /&gt;
show files modified date (year,month,time) . $ls -lT (output e.g. -rw-r--r--@  1 theUser  staff  125954 Mar 19 19:29:22 2012 foo.txt)&lt;br /&gt;
list directories/folders only .............. $ls -d */&lt;br /&gt;
list folders only (+hidden+permissions) .... $ls -la -d */&lt;br /&gt;
&lt;br /&gt;
find file from root ........................ $find / -name httpd&lt;br /&gt;
find file foo.php starting from curr dir ... $find . -name foo.php&lt;br /&gt;
list also file(s) info, e.g. size, mod ..... $find . -name foo.php -ls&lt;br /&gt;
find file or folder containing foo* ........ $find -name foo*&lt;br /&gt;
find file containing *html* ................ $find -name *html*.*&lt;br /&gt;
find all files with .rej extension ......... $find -name *.rej (starting from the current directory. use quotes &amp;quot;*.rej&amp;quot; or go one dir up if you get following message: &amp;quot;find: paths must precede expression: ...&amp;quot;&lt;br /&gt;
find *.rej from /foo/diffs &amp;amp; subdirs ....... $find /foo/diffs/ -name *.rej (you probably can't be in the same dir when making the search)&lt;br /&gt;
paths must precede expression: viewforum.php.rej&amp;quot;)&lt;br /&gt;
show all folder ............................ $find . -type d&lt;br /&gt;
find file which is in /etc dir ............. $find /etc -name apache2.conf&lt;br /&gt;
&lt;br /&gt;
search text from file, show line# .......... $grep 'exampletext' -n /foo/bar.txt&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -n --directories=recurse folder/*&lt;br /&gt;
from all files and sub directories ......... $grep 'exampletext' -r /var/www/html/*&lt;br /&gt;
from this &amp;amp; subdirs, only filenames ........ $grep 'exampletext' -r -l *&lt;br /&gt;
from this &amp;amp; subdirs, ignore case ........... $grep 'ExAmPlEtExT' -r -i *&lt;br /&gt;
exclude directory from search .............. $grep 'exampletext' * -rl --exclude-dir=cache&lt;br /&gt;
exclude multiple directories from search ... $grep -r 'exampletext' * --exclude-dir=forum --exclude-dir=cache --exclude-dir=files&lt;br /&gt;
exclude files from search .................. $grep 'exampletext' -rl --exclude=*.{png,jpg} *&lt;br /&gt;
search recursive and ignore binary files ... $grep 'exampletext' -r -I *&lt;br /&gt;
to search e.g. '-A' use escape character ... $grep '\-A' /foo/bar.txt&lt;br /&gt;
&lt;br /&gt;
find specific programs files ............... $locate mysqldump&lt;br /&gt;
locate patch tool .......................... $whereis patch&lt;br /&gt;
locate patch, prints e.g. /usr/bin/patch ... $which patch&lt;br /&gt;
find files modified during xx days ......... $find . -mtime -40 | less (exit less: q or Q or :q or :Q or ZZ)&lt;br /&gt;
tree view (apt-get install tree) ........... $tree&lt;br /&gt;
tree view of only folders .................. $tree -d&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Showing file content on screen ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print all file contents on screen ........ $cat index.html&lt;br /&gt;
show file content ........................ $more index.html (exit: q)&lt;br /&gt;
show file content ........................ $less index.html (exit: q, go to the end of file: shift + G)&lt;br /&gt;
show first 10 lines of the file .......... $head index.html&lt;br /&gt;
show first 50 lines of the file .......... $head -50 index.html&lt;br /&gt;
show last 10 lines of the file ........... $tail index.html&lt;br /&gt;
show last 50 lines of the file ........... $tail -50 index.html&lt;br /&gt;
search all .txt files and unite contents . $find /foo/bar/ -name *.txt -exec cat {} &amp;gt; texts.txt \; (copies all the contents of .txt files to texts.txt)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Packing and unpacking ===&lt;br /&gt;
&lt;br /&gt;
==== Compress ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf d6_bu.tar.gz drupal6/ (archive contains drupal6/ folder. c = create, z = compress archive with gzip, f = filename)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -czf ~/Backups/d6_bu-$(date +%Y-%m-%d-%H.%M.%S).tar.gz drupal6/  (creates a file like d6_bu-2014-01-24-18.05.16.tar.gz)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -c --gzip -f /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress all in cur dir to .tar.gz file .. $tar -czf /home/foo/d6_bu.tar.gz * (no parent directories/path in archive, only dirs inside the current dir. remember to specify the target folder when uncompressing the archive)&lt;br /&gt;
compress folder to .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz drupal6/* (archive contains drupal6/ folder)&lt;br /&gt;
BAD example for .tar.gz file ............. $tar -c --gzip -f d6_bu.tar.gz /Users/john/Sites/drupal6/ (all files in the archive have a path /Users/john/Sites/drupal6/ when uncompressed starting from the current directory where you uncompressed it)&lt;br /&gt;
BETTER example for .tar.gz file .......... $tar -c --gzip -f d6_bu.tar.gz -C /Users/john/Sites/ drupal6/ (-C changes the directory first to /Users/john/Sites/ and then compresses drupal6/ dir)&lt;br /&gt;
exclude dirs when compressing ............ $tar -czf drupal-6.tar.gz --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files'  drupal-6/&lt;br /&gt;
exclude dirs after change dir ............ $tar -czf drupal-6.tar.gz -C '/Users/john/websites/' --exclude 'drupal-6/resources' --exclude 'drupal-6/forum/files' drupal-6/&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip filename.foo (it REPLACES your original file with a compressed version: filename.foo.gz)&lt;br /&gt;
compress files with gzip (.gz) ........... $gzip -k filename.foo (it creates compressed version: filename.foo.gz and keeps your original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
compress folder with gzip ................ $make a .tar file first and then gzip or use -r to make multiple .gz files&lt;br /&gt;
make a .tar file of folder contents ...... $tar -cvvf d6_bu.tar /var/www/drupal6&lt;br /&gt;
compress to .tar.bz2 file ................ $tar -c --bzip2 -f d6_bu.tar.bz2 drupal6/&lt;br /&gt;
compress .zip file ....................... $zip files.zip *&lt;br /&gt;
compress specific files to .zip file ..... $zip files.zip file1 file2 file3&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Unpack ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzf filename.tar.gz (if same files exists in unpacking destination those will be OVERWRITTEN)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvkf filename.tar.gz (k = do not overwrite existing files. --keep-newer-files option do not overwrite existing files that are newer than the versions appearing in the archive being extracted.)&lt;br /&gt;
unpack .tar.gz archive ................... $tar -xzvf filename.tar.gz (x = extract, z = gzip, v = verbosely list files processed, f = use archive file)&lt;br /&gt;
unpack .tar.gz to specific dir ........... $tar -xzvf drupal-6.17.tar.gz -C /var/www/ (C = change to directory DIR, the directory have to exist or otherwise you'll get an error message)&lt;br /&gt;
unpack .tar files ........................ $tar xvf filename.tar&lt;br /&gt;
unpack .gz files ......................... $gunzip filename.foo.gz (it REPLACES your original file: filename.foo.gz with an uncompressed version: filename.foo)&lt;br /&gt;
unpack .gz files keeping original file ... $gunzip -k filename.foo.gz (keeps original file also. works only in gzip versions since June 2013.)&lt;br /&gt;
unpack bzip2 archive ..................... $sudo tar xfj phpBB-3.0.6.tar.bz2&lt;br /&gt;
unpack .zip files ........................ $unzip filename.zip&lt;br /&gt;
unpack .zip files to specific folder ..... $unzip filename.zip -d /var/www/&lt;br /&gt;
unpack .zip (do not make directories) .... $unzip -j filename.zip&lt;br /&gt;
unpack lzipped-file (.lz) ................ $lzip -d node_revisions.sql.lz (note! the .lz file is removed if the operation is successful!)&lt;br /&gt;
unpack .lz file, keeping orig file also .. $lzip -d --keep node_revisions.sql.lz&lt;br /&gt;
unpack stripping the 1st dir level ....... $tar -xzvf /path/to/file.tar.gz --strip 1  (if the archive contains dir structure &amp;quot;parent/children/[files]&amp;quot; it will be unarchived as &amp;quot;children/[files]&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== List Files In Archives ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
list files in .tar.gz archive ............ $tar -tzf backup.tar.gz (t = list files, z= filter through gzip, f = use archive file)&lt;br /&gt;
list files in .gz archive ................ $gunzip -l filename.gz&lt;br /&gt;
list files in .zip archive ............... $unzip -l filename.zip&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Checking disc, file and folder sizes and file count ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
check the size of mounted sections (KB).... $df&lt;br /&gt;
check the size of mounted sections (MB&amp;amp;GB). $df -h&lt;br /&gt;
check the size of specific directory ...... $du -hs /var/www/drupal/&lt;br /&gt;
check the size of directories and files ... $du -hs /var/www/drupal/*  (lists size of the files individually)&lt;br /&gt;
check the size of dir's subdirs ........... $du -h /var/www/drupal/    (shows a total size)&lt;br /&gt;
check the size of dir's files ............. $ls -lh /var/www/drupal/&lt;br /&gt;
show all files order by size desc ......... $ls -lh -S&lt;br /&gt;
show all files order by size asc .......... $ls -lh -S -r&lt;br /&gt;
check the number of files in directory .... $ls -l drupal6 | wc -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Config and build from source code ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
e.g. Apache web server:&lt;br /&gt;
navigate to the right folder ............. $cd httpd-2_x_xx&lt;br /&gt;
configure ................................ $./configure --enable-so [other options]&lt;br /&gt;
make/build ............................... $make&lt;br /&gt;
install Apache ........................... $make install&lt;br /&gt;
&lt;br /&gt;
If install fails you can try to build it again:&lt;br /&gt;
clean old build/configuration ............ $clean make&lt;br /&gt;
list available flags ..................... $./configure --help&lt;br /&gt;
..and then configure + make/build + install&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== File and folder permissions &amp;amp; ownership ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
read &amp;amp; write for current usr ............. $chmod 644 filename.ext&lt;br /&gt;
read &amp;amp; write for web server .............. $chmod 666 filename.ext&lt;br /&gt;
change folder rights recursively ......... $chmod 750 -R /var/www/drupal&lt;br /&gt;
change owner of a file ................... $chown root filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root.www-data filename.ext&lt;br /&gt;
change owner and group of a file ......... $chown root:www-data filename.ext&lt;br /&gt;
change owner &amp;amp; group of a dir&amp;amp;files rec .. $chown root:www-data folder/ -R&lt;br /&gt;
change o &amp;amp; g of all files in current dir . $chown www-data:www-data *&lt;br /&gt;
change only a owner group ................ $chown :www-data config.php&lt;br /&gt;
change only a owner group ................ $chgrp www-data config.php&lt;br /&gt;
change owner group recursively (fil&amp;amp;dir) . $chgrp -R www-data examplefolder&lt;br /&gt;
remove write perm from current group ..... $chmod g-w examplefolder&lt;br /&gt;
add execute perm for file owner (rec) .... $chmod u+x -R examplefolder&lt;br /&gt;
add write access to others group (002) ... $chmod o+w drupal-7/sites/default/settings.php&lt;br /&gt;
change all root right to theuser rec ..... $chown -R --from=root:root theuser:theuser * (starting from current dir, change all file ownership which are owned by root to theuser)&lt;br /&gt;
&lt;br /&gt;
e.g. files folder permissions&lt;br /&gt;
chmod 754 files&lt;br /&gt;
1. number = u = user/owner&lt;br /&gt;
2. number = g = group&lt;br /&gt;
3. number = o/a = others group / anonymous users&lt;br /&gt;
&lt;br /&gt;
ls -la&lt;br /&gt;
drwxr-xr-- 2 1080 www-data 4096 2010-06-13 10:12 files&lt;br /&gt;
&lt;br /&gt;
d = type: directory/folder&lt;br /&gt;
r = read = 4&lt;br /&gt;
w = write = 2&lt;br /&gt;
x = execute = 1&lt;br /&gt;
- = no permission = 0&lt;br /&gt;
&lt;br /&gt;
permission numbers are calculated from binaries e.g. full access 7 = 4+2+1 = rwx&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== OS X Specific Permissions ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
other permission examples:&lt;br /&gt;
-rw-r--r--@&lt;br /&gt;
&amp;quot;@&amp;quot; symbol appearing to the right of the permission tables (OS X specific) means the file has additional attributes which you can see by typing: xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;)&lt;br /&gt;
&lt;br /&gt;
list all files and their attributes ...... $ls -la@&lt;br /&gt;
&lt;br /&gt;
xattr&lt;br /&gt;
list all attributes in current directory . $xattr *&lt;br /&gt;
list additional file attributes .......... $xattr foo.txt --&amp;gt; com.apple.quarantine&lt;br /&gt;
list detailed additional file attributes . $xattr -l foo.txt --&amp;gt; com.apple.quarantine: 0001;5264fbed;Firefox;&lt;br /&gt;
delete one extended attribute ............ $xattr -d com.apple.quarantine foo.txt&lt;br /&gt;
remove all extended attributes ........... $xattr -c foo.txt&lt;br /&gt;
&lt;br /&gt;
-rw-r--r--+&lt;br /&gt;
This indicates the file has an ACL, short for Access Control List, which is used to give fine grained control over file permissions (OS X specific), beyond what is available with the regular unix permission tables.&lt;br /&gt;
Typing the following will show these additional permissions for files in a directory: ls -le&lt;br /&gt;
&lt;br /&gt;
drwxr-sr-x&lt;br /&gt;
s = &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
add a new user ........................... $adduser exampleuser&lt;br /&gt;
delete a user account and related files .. $userdel exampleuser&lt;br /&gt;
logout user .............................. $skill -KILL -u exampleuser&lt;br /&gt;
list all users and their home folders .... $cat /etc/passwd&lt;br /&gt;
show all users which has /home directory . $cat /etc/passwd |grep &amp;quot;/home&amp;quot; |cut -d: -f1&lt;br /&gt;
change user's home directory ............. $usermod -d /exampledir/subdir exampleuser&lt;br /&gt;
change password for current users ........ $passwd&lt;br /&gt;
change password for specific users ....... $passwd exampleuser&lt;br /&gt;
change password for group ................ $passwd -g examplegroup&lt;br /&gt;
enable Ubuntu root account ............... $sudo passwd root&lt;br /&gt;
change user .............................. $su exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Group management ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
create a new group ....................... $groupadd examplegroup&lt;br /&gt;
delete group ............................. $groupdel examplegroup&lt;br /&gt;
show all groups .......................... $less /etc/group&lt;br /&gt;
show the current user's groups ........... $groups&lt;br /&gt;
show groups of a specific user ........... $groups exampleuser&lt;br /&gt;
List all members of a group .............. grep 'examplegroup' /etc/group&lt;br /&gt;
List all members of a group .............. members examplegroup (apt install members)&lt;br /&gt;
List all members of a group .............. lid -g examplegroup (apt install libuser)&lt;br /&gt;
add user to a new group (keep old grps) .. $usermod -a -G examplegroup exampleuser&lt;br /&gt;
add user to a new group (keep old grps) .. $adduser exampleuser examplegroup&lt;br /&gt;
add user to multiple groups .............. $usermod -a -G group1,group2,group3 exampleuser&lt;br /&gt;
add group to multiple users .............. $gpasswd -M user1,user2,user3 examplegroup (Note: This will remove unlisted users from the group!)&lt;br /&gt;
add group to multiple users .............. $for user in user1 user2 user3; do sudo usermod -a -G examplegroup &amp;quot;$user&amp;quot;; done&lt;br /&gt;
remove user's group2 (is in group1,2,3) .. $usermod -G group1,group3 exampleuser&lt;br /&gt;
force a new primary group for user ....... $usermod -g examplegroup exampleuser&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== X server (desktop / graphical ui) ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
gnome desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/gdm stop&lt;br /&gt;
start the X server ....................... $sudo /etc/init.d/gdm start&lt;br /&gt;
restart the X server ..................... $sudo /etc/init.d/gdm restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
kde desktop&lt;br /&gt;
close the X server ....................... $sudo /etc/init.d/kdm stop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Date and Time ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
view the current date and time ........... $date&lt;br /&gt;
set date time to 28.6.2010 13:45:55 ...... $date 062813452010.55&lt;br /&gt;
change current time zone (recommended) ... $dpkg-reconfigure tzdata&lt;br /&gt;
change current time zone (deprecated) .... $tzconfig&lt;br /&gt;
change current time zone ................. $tzselect&lt;br /&gt;
sets the current time/date for file ...... $settime myfile.txt&lt;br /&gt;
create or change accessed time if exists . $touch newfile.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Sync your clock with NTP servers (Network Time Protocol) ====&lt;br /&gt;
&lt;br /&gt;
http://codeghar.wordpress.com/2007/12/06/manage-time-in-ubuntu-through-command-line/&lt;br /&gt;
&lt;br /&gt;
=== Job Managing ===&lt;br /&gt;
&lt;br /&gt;
Job and task handling tips&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show ongoing jobs/tasks/programs ......... $jobs&lt;br /&gt;
cancel/terminate job ..................... ctrl+c&lt;br /&gt;
stop/pause job ........................... ctrl+z&lt;br /&gt;
bring the most recently backgrounded or&lt;br /&gt;
stopped job to the foreground ............ $fg&lt;br /&gt;
move stopped job to bg based on job id ... $bg 3&lt;br /&gt;
run as a background task (use '&amp;amp;') ....... $drush search-index &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Note!''' If a task was started and is running in the foreground, it is still possible to move it to the background without cancelling it:&lt;br /&gt;
# ctrl-z, this will suspend the current foreground job (task).&lt;br /&gt;
# Enter the job control command 'bg'&lt;br /&gt;
# Tap the 'Enter' key&lt;br /&gt;
The job is now running in the background&lt;br /&gt;
&lt;br /&gt;
== Administration Related Commands ==&lt;br /&gt;
&lt;br /&gt;
=== Operating System Restart / Reboot / Shut Down ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
restart your system ...................... $shutdown -r now&lt;br /&gt;
bring down the system immediately ........ $shutdown now&lt;br /&gt;
bring down and power off the system ...... $shutdown -P now&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* More info: http://www.computerhope.com/unix/ushutdow.htm&lt;br /&gt;
&lt;br /&gt;
=== crontab ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
edit current user's crontab .............. $crontab -e&lt;br /&gt;
edit theuser user's crontab .............. $crontab -u theuser -e&lt;br /&gt;
list current user's crontab .............. $crontab -l&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[Crontab|Crontab tips]]&lt;br /&gt;
&lt;br /&gt;
=== Process Handling ===&lt;br /&gt;
&lt;br /&gt;
==== Show Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
display all running processes ............ $ps -A (ps stands for &amp;quot;process status&amp;quot;)&lt;br /&gt;
display all running processes ............ $ps -e&lt;br /&gt;
display all running processes ............ $ps aux | less  (-a all w/ tty except session leaders, -u by effective user ID (supports names), x processes w/o controlling ttys)&lt;br /&gt;
display all 'apache' processes ........... $ps aux | grep apache&lt;br /&gt;
display ps command help .................. $ps --help&lt;br /&gt;
display all 'firefox' process ids ........ $pgrep firefox&lt;br /&gt;
display all 'firefox' process ids ........ $pidof firefox&lt;br /&gt;
show exampleuser's all processes ......... $ps -u exampleuser&lt;br /&gt;
show running processes as a tree ......... $pstree&lt;br /&gt;
live-status of current top CPU processes . $top (q = quit, h = help)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Kill Processes ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
terminate process with id 3486 ........... $kill 3486&lt;br /&gt;
kill process 3486 (with &amp;quot;force&amp;quot;) ......... $kill -9 3486&lt;br /&gt;
kill all firefox processes (not unix!) ... $killall -9 firefox (DO NOT USE killall command on UNIX system as it's Linux only command)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Server Related Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show process info, e.g. cpu-time &amp;amp; mem ... $top (q = quit, h = help)&lt;br /&gt;
restart apache web server ................ $/etc/init.d/httpd restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Network Related Commands ==&lt;br /&gt;
&lt;br /&gt;
* http://www.comptechdoc.org/os/linux/commands/linux_crnetman.html&lt;br /&gt;
&lt;br /&gt;
=== Network Interface Commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
show network interfaces .................. $ifconfig&lt;br /&gt;
show eth0 interface ...................... $ifconfig eth0&lt;br /&gt;
shut down eth0 interface, releases ip .... $ifconfig eth0 down&lt;br /&gt;
enables the eth0 interface, renews ip .... $ifconfig eth0 up&lt;br /&gt;
restart the network using the values&lt;br /&gt;
in /etc/network/interfaces ............... $/etc/init.d/networking restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SSH ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open ssh connection ...................... $ssh exampleuser@iporhost.name&lt;br /&gt;
open ssh connection with debug info ...... $ssh -v exampleuser@iporhost.name&lt;br /&gt;
open ssh connection using custom port .... $ssh exampleuser@123.3.2.1 -p123&lt;br /&gt;
force ssh to use specific private key .... $ssh -i ~/.ssh/id_rsa_foo user@exampleserver.com&lt;br /&gt;
specify private key, port and user ....... $ssh -i /vm/rackspaceclone/puphpet/files/dot/ssh/root_id_rsa -p 2222 root@127.0.0.1&lt;br /&gt;
close (the most recent) connection ....... $exit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* [[SSH | More about SSH]]&lt;br /&gt;
&lt;br /&gt;
If you get an error message during idle session the service have probably timeouted: ''Write Failed: broken pipe''.&lt;br /&gt;
Edit (or create) &amp;lt;code&amp;gt;/etc/ssh/ssh_config&amp;lt;/code&amp;gt; for Linux and &amp;lt;code&amp;gt;~/.ssh/config&amp;lt;/code&amp;gt; for mac and add the first line. If that don't help you can try the others as well.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ServerAliveInterval 120&lt;br /&gt;
ClientAliveInterval 120&lt;br /&gt;
TCPKeepAlive yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== screen ===&lt;br /&gt;
&lt;br /&gt;
SSH sessions may break due to numerous and possibly unavoidable reasons.&lt;br /&gt;
&lt;br /&gt;
A useful utility which can be used to mitigate problems caused by this is called screen. Screen is a powerful utility that allows you to control multiple terminals which will stay alive independently of the ssh session. For example, if you run '''&amp;lt;code&amp;gt;screen&amp;lt;/code&amp;gt;''' in an ssh session you will see a new terminal open and you can use that to run jobs. Lets say your ssh session dies in the process. Running '''&amp;lt;code&amp;gt;screen -d&amp;lt;/code&amp;gt;''' then '''&amp;lt;code&amp;gt;screen -r&amp;lt;/code&amp;gt;''' will reopen the last session and you will be able to continue from there. &lt;br /&gt;
* [http://www.delorie.com/gnu/docs/screen/screen_toc.html Screen User's Manual]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Start a screen session ...................... $screen&lt;br /&gt;
Start a screen session ...................... $ctrl-a c&lt;br /&gt;
End a screen session ........................ $exit&lt;br /&gt;
End a specific screen session, e.g. 1234 .... $screen -X -S 1234 quit (sends a quit command for specified session)&lt;br /&gt;
Get the list of current screen sessions ..... $screen -list / screen -ls&lt;br /&gt;
check opened screens and process tree ....... $ps auxfw&lt;br /&gt;
If you have multiple screens open go next ... $ctrl-a space / ctrl-a n / ctrl-a ctrl-n&lt;br /&gt;
Go to the previous active screen ............ $ctrl-a p / ctrl-a ctrl-p&lt;br /&gt;
Detach/disconnect screen from your terminal . $screen -d&lt;br /&gt;
Reattach a session .......................... $screen -r&lt;br /&gt;
Open screen with a specific title ........... $screen -t thescreenname&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message: &amp;lt;code&amp;gt;-bash: screen: command not found&amp;lt;/code&amp;gt;, install screen first.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
yum install screen&lt;br /&gt;
or&lt;br /&gt;
apt-get install screen&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you get following message:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
There are several suitable screens on:&lt;br /&gt;
	64917.ttys002.Johns-MacBook	(Detached)&lt;br /&gt;
	64960.ttys001.Johns-MacBook	(Detached)&lt;br /&gt;
Type &amp;quot;screen [-d] -r [pid.]tty.host&amp;quot; to resume one of them.&lt;br /&gt;
&lt;br /&gt;
Reattach a specific session (pid) ........... $screen -r 64917&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== SFTP ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
open sftp connection ..................... $sftp exampleuser@123.123.123.123&lt;br /&gt;
show sftp commands once connected ........ sftp&amp;gt; help&lt;br /&gt;
download file to local computer .......... sftp&amp;gt; get /home/user/file1.ext&lt;br /&gt;
list folders and files on sftp server .... sftp&amp;gt; ls&lt;br /&gt;
list folders and files on local computer . sftp&amp;gt; lls&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
See commands also from: http://linux.about.com/od/commands/l/blcmdl1_sftp.htm&lt;br /&gt;
&lt;br /&gt;
=== SCP ===&lt;br /&gt;
&lt;br /&gt;
* '''scp''' stands for secure cp (copy), which means that you can copy files across an ssh connection that will be encrypted, and therefore secured.&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the local host dir&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:foobar.txt /some/local/directory&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from a remote host to the current dir in local host using port 22&lt;br /&gt;
 $ scp -P 22 exampleuser@iporhostname.com:foobar.txt .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host&lt;br /&gt;
 $ scp foobar.txt exampleuser@iporhostname.com:/some/remote/directory &lt;br /&gt;
&lt;br /&gt;
Copy the directory &amp;quot;foo&amp;quot; from the local host to a remote host's directory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r foo exampleuser@iporhostname.com:/some/remote/directory/bar &lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; to a local host's current directory&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/* .&lt;br /&gt;
&lt;br /&gt;
Copy all the files and sub directories from the remote host's directory &amp;quot;foo&amp;quot; starting with &amp;quot;a&amp;quot; letter to a local host's parent directory's subdirectory &amp;quot;bar&amp;quot;&lt;br /&gt;
 $ scp -r exampleuser@iporhostname.com:/some/remote/directory/foo/a* ../bar/&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from remote host &amp;quot;host1.com&amp;quot; to remote host &amp;quot;host2.com&amp;quot;&lt;br /&gt;
 $ scp username@host1.com:/some/remote/directory/foobar.txt \&lt;br /&gt;
 username@host2.com:/some/remote/directory/ &lt;br /&gt;
&lt;br /&gt;
Copying the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the local host to your home directory on the remote host&lt;br /&gt;
 $ scp foo.txt bar.txt exampleuser@iporhostname.com:~ &lt;br /&gt;
&lt;br /&gt;
Copy the files &amp;quot;foo.txt&amp;quot; and &amp;quot;bar.txt&amp;quot; from the remote host to current local directory&lt;br /&gt;
 $ scp exampleuser@iporhostname.com:&amp;quot;/dir1/foo.txt /dir2/bar.txt&amp;quot; .&lt;br /&gt;
&lt;br /&gt;
Copy the file &amp;quot;foobar.txt&amp;quot; from the local host to a remote host using port 2264&lt;br /&gt;
 $ scp -P 2264 foobar.txt exampleuser@iporhostname.com:/some/remote/directory&lt;br /&gt;
&lt;br /&gt;
Copy file from remote server using port 341 to local users home folder's /Sites/bu subdirectory&lt;br /&gt;
 $ scp -P 341 exampleuser@65.39.183.128:/home/exampleuser/drupal6_bu_20130130.sql.gz ~/Sites/bu&lt;br /&gt;
&lt;br /&gt;
=== Different commands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
download a file using wget ............... $wget http://ftp.drupal.org/files/projects/panels-6.x-3.9.tar.gz&lt;br /&gt;
download multiple files at the same time . $wget http://foo.org/file1.txt http://foo.org/file2.txt http://foo.org/file3.txt&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Linux administration ==&lt;br /&gt;
&lt;br /&gt;
=== Installing packages ===&lt;br /&gt;
&lt;br /&gt;
[[Apt-get]]&lt;br /&gt;
&lt;br /&gt;
=== Updating system ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux commands]]&lt;/div&gt;</summary>
		<author><name>Creator</name></author>
		
	</entry>
</feed>