Linux: Difference between revisions
Jump to navigation
Jump to search
m (→SCP: Typo) |
(Reorganised page content and formatting) |
||
Line 1: | Line 1: | ||
== Commands == | == Commands == | ||
=== System === | |||
{|class="vwikitable" | |||
{| | |||
|- | |- | ||
! Syntax !! Action / Description | |||
|- | |- | ||
|<code> | |<code> shutdown -r now </code> || Restart / reboot system, use <code>-h</code> to shutdown/halt. If command not available use <code>init</code> | ||
|- | |- | ||
|<code> | |<code> init <level> </code> || Level 0 - Halt system, level 6 - Reboot system | ||
|- | |- | ||
|<code> | |<code> uname -a </code> || Running OS info | ||
|- | |- | ||
|<code> | |<code> arp -n </code> || IP -> MAC arp table | ||
|- | |- | ||
|<code> | |<code> ifconfig </code> || Interface config (Unix equiv of Windows' ipconfig) | ||
|- | |- | ||
|<code> | |<code> ps fx <nowiki>|</nowiki> grep <proc> </code> || Find running process info | ||
|- | |- | ||
|<code> | |<code> ps -aux </code> || Running process info | ||
|- | |- | ||
|<code> | |<code> kill <pid> </code> || Kill a process | ||
|- | |- | ||
|<code> | |<code> top </code> || Task Manager (ish) | ||
|- | |- | ||
|<code> | |<code> free -m </code> || Free memory | ||
|} | |||
=== File System and File Operations === | |||
{|class="vwikitable" | |||
|- | |- | ||
! Syntax !! Action / Description | |||
|- | |- | ||
|<code> | |<code> ls -l </code> || List directory contents (<code>-l</code> long format) - [http://communities.vmware.com/message/678302#678302 Colour codes] | ||
|- | |- | ||
|<code> | |<code> df -h </code> || Disk space summary | ||
|- | |- | ||
|<code> df - | |<code> df -i </code> || Disk inodes summary | ||
|- | |- | ||
|<code> du -sh </code> || Directory space usage summary | |<code> du -sh </code> || Directory space usage summary | ||
|- | |- | ||
|<code> | |<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> | |<code> ln -s <src> <dest> </code> || Create a symbolic link to a file | ||
|- | |- | ||
|<code> | |<code> rm –i <file> </code> || Remove (delete) file (<code>-i</code> prompts before remove) | ||
|- | |- | ||
|<code> | |<code> rm –d -r -f <folder> </code> || Remove (delete) folder and contents '''without prompting''' | ||
|- | |- | ||
|<code> | |<code> find /path/ -iname "*FILENAME*" </code> || Find file with ''*filename*'' in ''path'' | ||
|- | |- | ||
|<code> | |<code> find <folder> -mtime +14 -exec rm {} \; </code> || Remove (delete) files in folder older than 14 days | ||
|- | |- | ||
|<code> | |<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> | |<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> | |<code> grep <find> <file> </code> || Find all occurrences of ''find'' in ''file'' | ||
|- | |- | ||
|<code> | |<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" | |||
{| | ! 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 | ||
|} | |} | ||
== 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]] |
Revision as of 09:44, 7 June 2012
Commands
System
Syntax | Action / Description |
---|---|
shutdown -r now |
Restart / reboot system, use -h to shutdown/halt. If command not available use init
|
init <level> |
Level 0 - Halt system, level 6 - Reboot system |
uname -a |
Running OS info |
arp -n |
IP -> MAC arp table |
ifconfig |
Interface config (Unix equiv of Windows' ipconfig) |
ps fx | grep <proc> |
Find running process info |
ps -aux |
Running process info |
kill <pid> |
Kill a process |
top |
Task Manager (ish) |
free -m |
Free memory |
File System and File Operations
Syntax | Action / Description |
---|---|
ls -l |
List directory contents (-l long format) - Colour codes
|
df -h |
Disk space summary |
df -i |
Disk inodes summary |
du -sh |
Directory space usage summary |
sort -nr | head -n 20 | Find 20 largest files/directories |
pwd |
Present working directory |
cp <src> <dest> |
Copy a file (see also scp )
|
ln -s <src> <dest> |
Create a symbolic link to a file |
rm –i <file> |
Remove (delete) file (-i prompts before remove)
|
rm –d -r -f <folder> |
Remove (delete) folder and contents without prompting |
find /path/ -iname "*FILENAME*" |
Find file with *filename* in path |
find <folder> -mtime +14 -exec rm {} \; |
Remove (delete) files in folder older than 14 days |
chmod +x <file> |
Add execute permission to a file |
lsof <folder> |
List open files |
tar czf file.tgz folder |
Tar contents of folder to file |
File Contents (Inspection and Manipulation)
Syntax | Action / Description |
---|---|
more <file> |
Views a file (read only), q to exit, +line to start from line
|
less <file> |
Views a file (read only), like more , but with increased functionality
|
watch -d "ls -lt *.vmdk ;date" |
Watch modifications occurring to files matching *.vmdk |
diff <file1> <file2> |
Difference between two files |
grep <find> <file> |
Find all occurrences of find in file |
tail <file> |
Displays the last 10 lines of a file, -f follows any updates (eg to monitor a log file)
|
SCP
In order to be able to copy files from one machine to the other...
scp user@server:/remote/server/path/file /local/server/path/
In order to be able to copy files within a script (and not get prompted for a user password, the public key of the machine running the script needs to be authorised on the remote server.
- On the local machine, be logged in as the same user as will be running the script
- Create public key on local machine (just hit return to accept default options)
ssh-keygen -t rsa
- Copy the public key for local machine user to the remote machine
- EG
scp /root/.ssh/id_rsa.pub server:/home/user/
- EG
- On the remote machine, check if the following file already exists
/root/.ssh/authorized_keys
- If so, append the contents of the copied key to the file
- If not, copy the file
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.
Crib sheet for VI mode commands...
Command | Purpose |
---|---|
i |
Insert characters |
x |
Delete character |
r |
Replace character |
cw |
Overwrite word (use any delimiter) |
o |
Insert line |
dd |
Delete current line |
<x>yy |
Yank (copy) next x lines (inclusive of current line, default x is 1)
|
p |
Paste yanked lines |
/<string> |
Search for next occurrence of string |
:g/<find>/s//<replace>/g |
Find and replace |
:wq |
Write (save) and Quit |
:q! |
Quit (don't save) |
:undo |
Undo last action |
Unix User accounts
- Create Account - Use
useradd <user>
to add a new user account with the default policy settings - Modify Password - Use
passwd <user>
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
chage -M 99999 <user>
, to disable for all future account (ie modify the default policy) useesxcfg-auth --passmaxdays=99999