| bzip2|bunzip2 | These commands compress and decompress files. The recommended and default extension is .bz2. The compression is slower that with gzip, but the files are considerably smaller. Decompression is fast. |
| cd | Change directories.
cd /home/user Change to the directory /home/user (the home directory for a user with the user name user).
cd .. Go up one level from the current directory. |
| Cd | Go to home directory |
| chattr | Change special attribute of a directory, or a file. Immutable attribute is set with parameter "-i". |
| chgrp | Changes the owner group of a directory, or a file. Optionally this command works recursively with parameter "-R". Examples for "chown" apply here, but without the "root." part, as only the group is changed here. |
| chmod | This command is the main command for changing file modes (permission). Like chown, it can do things recursively with parameter "-R". If you use ls -l you get a list of directories and files with there permission d rwx r-x r-x
The first character states if it is a directory (d) or a file (-) The next characters are split in groups of 3 characters and stand (in this order) for: owner group everyone You can add the sum of rights: 4= read 2= write 1= execute 5 will be read and execute Changes file permission. We can use either letters or numeric equivalency when setting permissions. We set permission for 3 principals, the user, the group and others (ugo). If you are from a Windows background then don’t confuse “o” with owner. #chmod u+rx,g+r,o+r file.txt Note that using + or – indicates we are adding to or removing from existing permission. If we wish to reset the permission we use “=” to explicitly set the object permissions. #chmod u=rx,g=r,o=r file.txt yields r-xr—-r-- Sometimes you will see a chmod using “a” to specify all (user, group & other), so we could quickly set read permissions by #chmod a-wx,a+r file.txt yields r—-r-—r-- A more common way to set permission is using chmod is using numeric equivalent values (4,2,1 for r,w,x) and permutations thereof. chmod 777 windows2k.vmx set perms to rwxrwxrwx chmod 754 windows2k.vmx set perms to rwxr-xr-- (default) Watch for chmod commands with 4 digits, e.g. chmod 0754. This refers to additional attributes chmod -R 0775 /vmfs /data chmod u=rwx,g=rwx,o=r /vmfs/freebsd462/* chmod g+rwx /vmfs/vm007/* chmod -R u+rwx,g=r,o-rwx /var/log/* chmod u=rw,g=rw,o=r /etc/modules.conf chmod 664 /etc/modules.conf chmod u=rw,g=rw /vmfs/*/*.dsk (It appears, that this example works rather nicely. Note, that those VMs which are powered-on, have their .dsk files locked. ) Change mode (permissions) for a specified file, group of files or directory.
chmod 755 *.vmx Set permissions on all files in the current directory that end with .vmx to be -rwxr-xr-x.
chmod 660 nvram Set permissions on the file nvram in the current directory to be -rw-rw----. |
| chown | Changes the owner user and optionally owner group of a directory, or a file. Optionally this command works recursively with parameter "-R". The assignment parameter is of type "user.group", or just "user". Some examples are given below: chown -R helpdesk.vmadmins /vmfs /data Recursively change the user-owner, and the group-owner of specified files/directories to userid.groupid. chown helpdesk.vmadmins /vmfs/local/* chown -R root /data/vmware chown root.vmadmins /etc/modules.conf |
| cp | cp oldfile newfile Make a copy of the file oldfile in the current directory. The copy is named newfile |
| dd | With this 'disk dump' command you can create ISO images and floppy images. You can also use it to create imagefiles of partitions and whole disks. Below are some example commands: dd if=/dev/cdrom of=/local/suse90pro-dvd1.iso bs=2048 dd if=/dev/cdrom of=/local/w2003srv.iso bs=2048 The above two examples create an ISO image of a CD/DVD. You can safely ignore the error message usually shown at the end of the media. dd if=/dev/fd0 of=/local/bootfloppy1.img bs=1440k This command creates a floppy image quickly. You can also use the freeware Emt4win utility for Windows download to create floppy images dd if=/dev/fd0 of=/local/bootfloppy2.img bs=512 This might be a bit slower version of the above example. This tool can be used to create an additional swap file. For example, if we did not allocate a big enough swap partition for the service console during ESX installation, we can create one now in a file of 64MB. dd if=/dev/zero of=/swapfile bs=1M count=64 If we did add a swap file, we would need to make sure it is started when ESX starts. Therefore, an entry in /etc/fstab would be needed as this file describes the local and remote file systems to mount at boot. The total amount of service console swap space is the sum of the swap partition and any swap files that are active. See also:
mkswap, swapon, swapoff |
| df -h | Print disk partitions (with human readable switch) Filesystem Size Used Avail Use% Mounted on /dev/sda2 4.3G 644M 3.4G 16% / /dev/sda1 45M 12M 31M 28% /boot /dev/sda5 2.7G 33M 2.5G 2% /home none 93M 0 93M 0% /dev/shm /dev/sda6 1007M 113M 843M 12% /var /dev/sda8 125G 33M 118G 1% /vmimages |
| du | Display usage in kilobytes for contents of the current directory or for a specified file or directory.
du /bin Show how much disk space is used by the /bin directory. |
| fdisk | Command line disk partitioning program in Linux. It is powerful and has a very simple user interface. Please note, that ext2, and ext3 both use the same partition ID. fdisk /dev/sdb On command line, starts fdisk against second available SCSI disk. "sda" is the first SCSI disk, "sdc" is the third SCSI disk etc. VMware ESX Server is installed on /dev/sda, and the external storage is /dev/sdb, and maybe some others too. p Fdisk subcommand, prints the current partition table on current disk. d Fdisk subcommand, deletes an existing partition. Enter the partition number to delete. It is recommended to printout the current partition table before deleting anything. n Fdisk subcommand, creates a new partition. Select partition type (primary, extended, or logical). Almost always you should use the default starting cylinder. For size, enter "+NNNNNm", where NNNNN is the size in megabytes. t Fdisk subcommand, change partition type (id). By default fdisk creates ext2/esx3 type partitions. We might also want sometime to use id "fb", the vmfs type, or some other type. w Fdisk subcommand, writes the current partition table to disk. If you don't get any errors, you don't have to reboot. If you get errors at this point, the new partition table is used only after next system boot. |
| find | Find files by name or many of the other attributes. Another very powerful command. Below are some example commands: Examples: find –mmin -30 files modified in last 30 minutes find –mtime 1 files modified in last 24 hours find –size +10000 files in excess of 10,000 bytes find –mount –size +10000 -ls files on non-remote file system find –name “hosts” -ls file called hosts find /vmfs -type f -iname *.dsk find /data -type f -iname *.vmx find / -type f -iname *.bak find . -type d -name sbin find / -type f -name * find -name '*.vmx' -print -exec chown User2 {} \; Find all files in this directory and all subdirectories that end with .vmx, display the names of all files that are found on the screen and, for each file (indicated by the curly braces — {}), change its owner to User2. The -print option is not necessary, but it is handy to track the progress of the find command. If you do not use -print, the find command is silent except for error messages from find or from chown.
–mount used to ensure it doesn't traverse to remote file systems -size obvious -mtime modified in the last n*24 -mmin modified in the last n minutes -ls use output format as if ls were used -name name the file you are looking for (you just don’t know where it is!) |
| grep | Search for a string from standard input or from a file. This is a powerful command. |
| gzip|gunzip | These commands compress and decompress files. The recommended and default extension is .gz. The compression is quite fast, and files are quite small. Decompression is fast. |
| lsof | List open files Pipe the results into grep to check for open ports lsof |grep IPv4.\*LISTEN |
| ll | Same as ls –al |
| ls | LiSt files in a directory. -R makes it recursive, and -l shows more information on each item. ls -lh Long format human readable ls -a (List files in a directory including hidden, also known as dot files due to their prefix files.) ls -dl */ (List directories in long format (does not display files). Could add as a shell alias, say lsd.) |
| mkdir | Makes a directory. mkdir /data Creates directory /data for the VM configs. |
| mke2fs | This command formats a partition for ext2, or ext3 filesystem. mke2fs -j /dev/sdb1 Formats /dev/sdb1 using ext3 filesystem. mke2fs /dev/sdb1 Formats /dev/sdb1 using ext2 filesystem. |
| mount|umount | These commands manually mount/umount CDs, floppies, local partitions, and remote directories to a selected local directory. The local (empty) directory must exist before the mount can succeed. Example mound command would be "mount /dev/sdb5 /data". Permanent mounting is done by editing the /etc/fstab file. mount Shows all the active mounts. mount -a Remounts everything specified in /etc/fstab file. This is probably the very mount command you will be entering. mount /dev/cdrom This command does the default mounting of a CD to the default mountpoint. In Service Console the CD is mounted to /mnt/cdrom directory. mount /mnt/floppy Mounts a normal 1440KB floppy (/dev/fd0) to the specified directory. mount -t iso9660 -o loop /local/w2005srv.iso /mnt/isocd Mount a CD/DVD ISO image file to the specified directory. This is very useful for testing and other purposes. The mountpoint directory must exist (mkdir /mnt/isocd) before mounting. umount /mnt/cdrom Unmount anything mounted to the specified mountpoint. If nothing is mounted, the command does nothing. |
| mv | Moves and/or renames files and/or directories. |
| nano | Edit a file with a bit easier UI that vi. nano -w /etc/fstab This is probably the very first file editing command you want/need. "-w" turns word-wrapping off, so you can more easily edit longer lines than about 74 characters. nano /etc/inittab nano /etc/bashrc |
| rm | Removes files and/or directories. |
| scp | scp secure copy Copies files between linux hosts -r Recursively copy entire directories. -v Verbose mode. Setup SSH Key authentication between linux (ESX) servers will enable copy without Password request instructions scp Fikename remoteserver-name:/remoted-destinationdirectory |
| showmount | showmount lists all the clients that have remotely mounted a filesystem from host.-d list directories that have been remotely mounted by clients
-a print all remote mounts in the format
hostname:directory
where hostname is the name of the client and directory is the root of the filesystem that has been mounted
-e print the list of exported filesystems |
| stat | Show statistics of a file. This is the most comprehensive directory entry examiner. |
| tar | Tape ARchive, a command which combines many files into one for backup purposes. Below are some example commands: tar -cvjf /local/servcons.tar.bz2 --exclude /proc --exclude /local --exclude /vmfs --exclude /data / Create a bzip2'ed tar backup file the whole Service Console. Smaller, slower backup. tar -cvzf /local/servcons.tar.gz --exclude /proc --exclude /local --exclude /vmfs --exclude /data / Create a gzipped tar backup file the whole Service Console. Faster, bigger backup. tar -cf /local/vm-configs.tar /data Create a tar backup file of all files in and under /data directory. tar -xvzf /local/vm007-config.tar.gz Extract gzipped tar backup file to current directory. tar -xvjf /local/vm007-config.tar.bz2 -C /tmp Extract gzipped tar backup file to /tmp directory. find / -type f -iname vm007* | tar -cjvf /local/vm007-backup.tar.bz2 - Find all files starting as 'vm007', and create a compressed backup tar file of them. |
| vdf | Displays free space for all mounted file systems. vdf is an ESX Server-customized version of the df command. Use vdf in place of the df command. vdf works with all the standard df options. The listing also shows the total space, amount of space used and percentage of space used for each file system. vdf -h (with human readable switch) |