Difference between revisions of "Linux"

Jump to navigation Jump to search
894 bytes removed ,  09:44, 7 June 2012
Reorganised page content and formatting
m (→‎SCP: Typo)
(Reorganised page content and formatting)
Line 1: Line 1:
== Commands ==
== Commands ==
 
=== System ===
For use in the service console
{|class="vwikitable"
 
{|cellpadding="2" cellspacing="0" border="1"
|-
|-
|<code> ls -l </code>                    || List directory contents (<code>-l</code> long format) - [http://communities.vmware.com/message/678302#678302 Colour codes]
! Syntax                                  !! Action / Description
|-
|-
|<code> pwd </code>                       || Present working directory
|<code> shutdown -r now </code>           || Restart / reboot system, use <code>-h</code> to shutdown/halt.  If command not available use <code>init</code>
|-
|-
|<code> cp <src> <dest> </code>           || Copy a file
|<code> init <level> </code>             || Level 0 - Halt system, level 6 - Reboot system
|-
|-
|<code> ln -s <src> <dest> </code>       || Create a symbolic link to a file
|<code> uname -a </code>                 || Running OS info
|-
|-
|<code> rm –i <file> </code>             || Remove (delete) file (<code>-i</code> prompts before remove)
|<code> arp -n </code>                   || IP -> MAC arp table
|-
|-
|<code> rm –d -r -f <folder> </code>     || Remove (delete) folder and contents '''without prompting'''
|<code> ifconfig </code>                 || Interface config (Unix equiv of Windows' ipconfig)
|-
|-
|<code> find <folder> -mtime +14 -exec rm {} \; </code>     || Remove (delete) files in folder older than 14 days
|<code> ps fx <nowiki>|</nowiki> grep <proc> </code>       || Find running process info
|-
|-
|<code> more <file> </code>               || Views a file (read only), <code>q</code> to exit, <code>+line</code> to start from line
|<code> ps -aux </code>                   || Running process info
|-
|-
|<code> find /path/ -iname "*FILENAME*" </code> || Find file with ''*filename*'' in ''path''
|<code> kill <pid> </code>               || Kill a process
|-
|-
|<code> watch -d "ls -lt *.vmdk ;date" </code> || Watch modifications occurring to files matching ''*.vmdk''
|<code> top </code>                       || Task Manager (ish)
|-
|-
|<code> diff <file1> <file2> </code>     || Difference between two files
|<code> free -m </code>                   || Free memory
|}
 
=== File System and File Operations ===
{|class="vwikitable"
|-
|-
|<code> grep <find> <file> </code>        || Find all occurrences of ''find'' in ''file''
! Syntax                                  !! Action / Description
|-
|-
|<code> tail <file> </code>               || Displays the last 10 lines of a file, <code>-f</code> follows any updates (eg to monitor a log file)
|<code> ls -l </code>                     || List directory contents (<code>-l</code> long format) - [http://communities.vmware.com/message/678302#678302 Colour codes]
|-
|-
|<code> init <level> </code>             || Level 0 - Halt system, level 6 - Reboot system
|<code> df -h </code>                     || Disk space summary
|-
|-
|<code> df -h </code>                    || Disk space summary
|<code> df -i </code>                    || Disk inodes summary
|-
|-
|<code> du -sh </code>                    || Directory space usage summary
|<code> du -sh </code>                    || Directory space usage summary
|-
|-
|<code> chmod +x <file> </code>          || Add execute permission to a file
|<code> du -ma / | sort -nr | head -n 20 </code>  || Find 20 largest files/directories
|-
|<code> pwd </code>                      || Present working directory
|-
|<code> cp <src> <dest> </code>          || Copy a file (see also <code>[[#SCP|scp]]</code>)
|-
|-
|<code> uname -a </code>                 || Running OS info
|<code> ln -s <src> <dest> </code>       || Create a symbolic link to a file
|-
|-
|<code> arp -n </code>                   || IP -> MAC arp table
|<code> rm –i <file> </code>             || Remove (delete) file (<code>-i</code> prompts before remove)
|-
|-
|<code> ifconfig </code>                 || Interface config (Unix equiv of Windows' ipconfig)
|<code> rm –d -r -f <folder> </code>     || Remove (delete) folder and contents '''without prompting'''
|-
|-
|<code> ps fx <nowiki>|</nowiki> grep <proc> </code>       || Find running process info
|<code> find /path/ -iname "*FILENAME*" </code> || Find file with ''*filename*'' in ''path''
|-
|-
|<code> ps -aux </code>                   || Running process info
|<code> find <folder> -mtime +14 -exec rm {} \; </code>     || Remove (delete) files in folder older than 14 days
|-
|-
|<code> kill <pid> </code>               || Kill a process
|<code> chmod +x <file> </code>           || Add execute permission to a file
|-
|-
|<code> lsof <folder> </code>            || List open files
|<code> lsof <folder> </code>            || List open files
|-
|-
|<code> top </code>                       || Task Manager (ish)
|<code> tar czf file.tgz folder </code>   || Tar contents of folder to file
|}
 
=== File Contents (Inspection and Manipulation) ===
{|class="vwikitable"
|-
! Syntax                                  !! Action / Description
|-
|<code> more <file> </code>              || Views a file (read only), <code>q</code> to exit, <code>+line</code> to start from line
|-
|<code> less <file> </code>              || Views a file (read only), like <code> more </code>, but with increased functionality
|-
|<code> watch -d "ls -lt *.vmdk ;date" </code> || Watch modifications occurring to files matching ''*.vmdk''
|-
|<code> diff <file1> <file2> </code>      || Difference between two files
|-
|-
|<code> free -m </code>                   || Free memory
|<code> grep <find> <file> </code>       || Find all occurrences of ''find'' in ''file''
|-
|-
|<code> tar czf file.tgz folder </code>   || Tar contents of folder to file
|<code> tail <file> </code>               || Displays the last 10 lines of a file, <code>-f</code> follows any updates (eg to monitor a log file)
|}
|}


Line 76: Line 96:


== VI Editor ==
== VI Editor ==
 
VI is a bit of a pain to use, go slowly, and use [Esc] regularly to get out of the current mode after each operation.
VI is a bit of a pain to use, go slowly, and use [Esc] regularly to get out of the current mode after each operation  


Crib sheet for VI mode commands...
Crib sheet for VI mode commands...
 
{|class="vwikitable"
{|cellpadding="2" cellspacing="0" border="1"
! Command                              !! Purpose
|-
|-
|<code> i </code>                      || Insert characters
|<code> i </code>                      || Insert characters
Line 109: Line 128:
|<code>:undo </code>                    || Undo last action
|<code>:undo </code>                    || Undo last action
|}
|}
== VIM Editor ==
VIm = Vi Improved, the commands are the same, but theres extra features
* [http://www.vim.org/docs.php VIM website]
* [http://vimdoc.sourceforge.net/htmldoc/usr_toc.html VIM on line manual]
=== Installation ===
#  Login to the ESX console using your user account and create a new directory (within <code> /home/user </code>
#* <code> mkdir vim </code>
# Logon to the VCS machine (UKLONVCP1) and copy across the installation files, stored under the Software_Reposity directory (substitute user and ESXserver appropriately).
#* <code> pscp C:\Software_Repository\vim-7.1.tar.bz2 user@ESXserver:/home/user/vim  </code>
# Back on the ESX console become root, change into the directory where vim is
# Extract the package
#* <code>  bunzip2 -c vim-7.1.tar.bz2 | tar -xf - </code>
# Move into the vim71 folder
# Run configure
#* <code> ./configure </code>
# Compile the package
#* <code> make </code>
# Install the package
#* <code> make install </code>
=== Useful Commands ===
{|cellpadding="2" cellspacing="0" border="1"
|-
|<code> :syntax enable </code>                    || Turns on syntax formatting
|-
|<code> vim one.sh two.sh three.sh </code>        || Opens up three files for editing
|-
|<code> :wnext </code>                            || Writes changes to existing file and moves to next file(omit w not to write)
|-
|<code> :wprevious </code>                        || Writes changes to existing file and moves to previous file (omit w not to write)
|-
|<code> v </code>                                || Toggle visual mode (so you can select text), use y/p to yank/paste selected text
|-
|[http://vimdoc.sourceforge.net/htmldoc/usr_07.html#07.5 VIM manual section 7.5] || Copy text between files
|}


== Unix User accounts ==
== Unix User accounts ==
* '''Create Account''' - Use <code> useradd <user> </code> to add a new user account with the default policy settings
* '''Create Account''' - Use <code> useradd <user> </code> to add a new user account with the default policy settings
* '''Modify Password''' - Use <code> passwd <user> </code> to change password for ''user''.  To breach minimum complexity rules you must be logged in at the console (in the DC not remotely)
* '''Modify Password''' - Use <code> passwd <user> </code> to change password for ''user''.  To breach minimum complexity rules you must be logged in at the console (in the DC not remotely)
* '''Modify Expiry''' - To disable the password expiry policy for a account that already exists use <code> chage -M 99999 <user> </code>, to disable for all future account (ie modify the default policy) use <code> esxcfg-auth --passmaxdays=99999 </code>
* '''Modify Expiry''' - To disable the password expiry policy for a account that already exists use <code> chage -M 99999 <user> </code>, to disable for all future account (ie modify the default policy) use <code> esxcfg-auth --passmaxdays=99999 </code>
[[Category:Ubuntu]]

Navigation menu