Linux: Difference between revisions
Jump to navigation
Jump to search
(Added "SCP") |
m (→SCP: Typo) |
||
Line 62: | Line 62: | ||
== SCP == | == SCP == | ||
In order to be able to copy files from one machine to the other... | In order to be able to copy files from one machine to the other... | ||
<code> scp user@server:/remote/server/path/file /local/server/path/ | <code> scp user@server:/remote/server/path/file /local/server/path/ </code> | ||
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. | 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. | ||
Line 74: | Line 74: | ||
# If so, append the contents of the copied key to the file | # If so, append the contents of the copied key to the file | ||
# If not, copy the file | # If not, copy the file | ||
== VI Editor == | == VI Editor == |
Revision as of 11:19, 19 April 2011
Commands
For use in the service console
ls -l |
List directory contents (-l long format) - Colour codes
|
pwd |
Present working directory |
cp <src> <dest> |
Copy a file |
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 <folder> -mtime +14 -exec rm {} \; |
Remove (delete) files in folder older than 14 days |
more <file> |
Views a file (read only), q to exit, +line to start from line
|
find /path/ -iname "*FILENAME*" |
Find file with *filename* in path |
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)
|
init <level> |
Level 0 - Halt system, level 6 - Reboot system |
df -h |
Disk space summary |
du -sh |
Directory space usage summary |
chmod +x <file> |
Add execute permission to a file |
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 |
lsof <folder> |
List open files |
top |
Task Manager (ish) |
free -m |
Free memory |
tar czf file.tgz folder |
Tar contents of folder to 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...
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 |
VIM Editor
VIm = Vi Improved, the commands are the same, but theres extra features
Installation
- Login to the ESX console using your user account and create a new directory (within
/home/user
mkdir vim
- Logon to the VCS machine (UKLONVCP1) and copy across the installation files, stored under the Software_Reposity directory (substitute user and ESXserver appropriately).
pscp C:\Software_Repository\vim-7.1.tar.bz2 user@ESXserver:/home/user/vim
- Back on the ESX console become root, change into the directory where vim is
- Extract the package
bunzip2 -c vim-7.1.tar.bz2 | tar -xf -
- Move into the vim71 folder
- Run configure
./configure
- Compile the package
make
- Install the package
make install
Useful Commands
:syntax enable |
Turns on syntax formatting |
vim one.sh two.sh three.sh |
Opens up three files for editing |
:wnext |
Writes changes to existing file and moves to next file(omit w not to write) |
:wprevious |
Writes changes to existing file and moves to previous file (omit w not to write) |
v |
Toggle visual mode (so you can select text), use y/p to yank/paste selected text |
VIM manual section 7.5 | Copy text between files |
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