|
cat |
View filecontent Concatenate file from start to standard output (terminal screen by default). Usually takes filename as a parameter.
cat > file (Enter text at command line and then CTRL-D to write to file.) |
|
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. 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
Change to your user homedirectory |
|
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----.
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----
|
|
clear |
Equivalent of CLS command in MS-DOS and in Windows command prompt. |
|
cp |
cp oldfile newfile
Make a copy of the file oldfile in the current directory. The copy is named |
|
crontab -e |
Schedule -tasks
Use crontab -e to edit the file! How to change the default editor from vi to nano see
The crond service must be running.
To determine if the service is running, use the command /sbin/service crond status
To restart the srvice: service crond restart (this will load modifications)
Each line in the /etc/crontab file represents a task and has the format:
minute hour day month dayofweek command
Example:
42 4 1 * * root run-parts /etc/cron.monthly
minute - any integer from 0 to 59
hour - any integer from 0 to 23
day - any integer from 1 to 31 (must be a valid day if a month is specified)
month - any integer from 1 to 12 (or the short name of the month such as jan or feb)
dayofweek - any integer from 0 to 7, where 0 or 7 represents Sunday (or the short name of the week such as sun or mon)
command - the command to execute (the command can either be a command such as ls /proc >> /tmp/proc or the command to execute a custom script)
If a cron task needs to be executed on a schedule other than hourly, daily, weekly, or monthly,
it can be added to the /etc/cron.d directory. All files in this directory use the same syntax as /etc/crontab.
Refer to following example for examples.
# record the memory usage of the system every monday
# at 3:30AM in the file /tmp/meminfo
30 3 * * mon cat /proc/meminfo >> /tmp/meminfo
# run custom script the first day of every month at 4:10AM
10 4 1 * * /root/scripts/backup.sh
For any of the above values, an asterisk (*) can be used to specify all valid values. For example, an asterisk for the month value means execute the command every month within the constraints of the other values.
A hyphen (-) between integers specifies a range of integers. For example, 1-4 means the integers 1, 2, 3, and 4.
A list of values separated by commas (,) specifies a list. For example, 3, 4, 6, 8 indicates those four specific integers.
The forward slash (/) can be used to specify step values. The value of an integer can be skipped within a range by following the range with /<integer> . For example, 0-59/2 can be used to define every other minute in the minute field. Step values can also be used with an asterisk. For instance, the value */3 can be used in the month field to run the task every third month.
Any lines that begin with a hash mark (#) are comments and are not processed.
As shown in the /etc/crontab file, it uses the run-parts script to execute the scripts in the /etc/cron.hourly, /etc/cron.daily, /etc/cron.weekly, and /etc/cron.monthly directories on an hourly, daily, weekly, or monthly basis respectively. The files in these directories should be shell scripts.
Users other than root can configure cron tasks by using the crontab utility. All user-defined crontabs are stored in the /var/spool/cron directory and are executed using the usernames of the users that created them. To create a crontab as a user, login as that user and type the command crontab -e to edit the user's crontab using the editor specified by the VISUAL or EDITOR environment variable. The file uses the same format as /etc/crontab. When the changes to the crontab are saved, the crontab is stored according to username and written to the file /var/spool/cron/username.
The cron daemon checks the /etc/crontab file, the /etc/cron.d/ directory, and the /var/spool/cron directory every minute for any changes. If any changes are found, they are loaded into memory. Thus, the daemon does not need to be restarted if a crontab file is changed. |
|
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 |
The find utility is used much in the same way as many Windows people used the DIR command. If you know roughly what files you are looking for, then this is the tool. The ls tool simply lists, whereas the find tool will find according to one or more criteria, a common one being find files modified in the last day using the –mtime switch as shown in the table.
–mount used to ensure it doesn't traverse to remote file systems
-size obvious
-mtime -n modified in the last n*24
-mmin -n 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!)
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 -exec ls -al {} \; do ls on the files found
find -perm 666 find files with exactly rw-rw-rw-
find -perm +666 find files with at least rw-rw-rw
find -user ali find files owned by ali |
|
findnic |
The findnic command lets you send network traffic from a specified network adapter so you can observe the LEDs on the adapters and see which physical adapter is associated with that device name. The format of the command is
findnic <options> <nic-name> <local-ip> <remote-ip>
-f Do a flood ping.
-i <seconds> Send pings at specified interval.
Example:
findnic -f vmnic1 10.2.0.5 10.2.0.4
findnic ?i 3 vmnic1 10.0.0.1 192.168.1.10
The above command will send ICMP echo requests to 192.168.1.10 every 3 seconds.
The NIC allocated to the VMKernel does not have an IP address. We need to give an IP address temporary to this NIC, it is specified as the first IP parameter. The second IP is the ICMP destination
|
|
grep |
Search for a string from standard input or from a file. This is a powerful command.
ls /home -Rla | grep StringToSerach |
|
history | tail |
View Last 10 commands
History normally list your past commands, used with tail it will filter to show only the last 10 |
|
less |
Display the contents of a specified file one screen at a time. Use the arrow keys to move up and down through the file.
less myfile
Display the contents of the file myfile. |
|
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.)q
ls -clt List |
|
lsmode |
shows information about all loaded modules
Lists drivers loaded for the service console linux. Remember this command differs from the vmkload_mod utility which shows the modules loaded for the VMkernel.
Module Size Used by Tainted: PF
vmnixmod 177056 121
e1000 68456 0 (unused)
usb-uhci 21220 0 (unused)
usbcore 50112 1 [usb-uhci]
megaraid2 32928 6
The same information can be found by cat /proc/modules |
|
lspci |
List PCI devices
H1 uses direct HW access
-n shows PCI vendor and device codes
-t Print tree of PCI Devices -tv for verbose tree
-v verbose mode
-vv very verbose mode
-M never use.It might crash ESX Server
Also check the file /proc/ |
|
man |
Displays the manual page for a specified command. Press the spacebar to go to the next screen of text. Press q to exit from the display when you are finished.
man cat
Display the manual page for the command cat.
Exit wit q |
|
mkdir |
Makes a directory.
mkdir /data
Creates directory /data for the VM configs. |
|
modinfo |
Displays the option of a loaded module.
modinfo e1000 Will produce a list of possible setting on the Network adapter as flow control
With vmkload_mod -l you can list all loaded |
|
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.
Mount an ISO at the Service Console:
mkdir /mnt/isocd
mount -o loop -t iso9660 -r /vmimges/esx2.1.iso /mnt/isocd
Re-mount all VMFS partition
-t sets the type of file system in this case VMFS. Last two are the volume label and the mount point
mount ?t vmfs vmfs /vmfs |
|
more |
Display the contents of a specified file one screen at a time. Use the spacebar to move forward through the file a screen at a time; use the Enter key to move forward through the file one line at a time.
more myfile
Display the contents of the file myfile |
|
more | less |
These commands are almost the same, and usually act in a pipe. They are used for file pagination to terminal. Below are some example commands:
zcat /var/log/vmksummary.1.gz | less
more /etc/passwd |
|
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 |
|
netstat |
Shows currently active network connections |
|
passwd |
Changes the password for the userid entered as a parameter for the command. Only root can change the password for other users. They can only change their own password with command "passwd". Userids are disabled by default. They are activated by setting a password for them. An example command for root to set a password is the following command:
passwd johndoe |
|
pidof |
Finds the PID of a named process.
pidof vmware-ccagent |
|
ps -ef |
Show running processes in the service console.
ps -ef | grep MyVMName.vmx (finds the process of a runing VM)
ps ?A ps ?eaf
ps ?eaf |grep vmware-serverd
ps ?efw
The -f switch
is useful as the ?w? indicates wide format, so we can see the full directory path to the vmx file.
Another good option is the H option to show the process hierarchy in a similar way to pstree.
ps -eH
which might keep Solaris people happy as we don't have the ptree utility in Linux
|
| pwd |
Show the path to the present working directory. |
|
reboot |
Prints the manual page for a command or a configuration file entered as a parameter to this command. |
|
route |
Modify or print routingtable
route Prints routing table
route del ?net default Deletes the default gateway
route add ?net default gw 10.20.0.1 Adds a new default gateway |
|
rm |
This is the equivalent of the MS-DOS or Windows command DEL. In other words, this tool deletes files.
# rm testfile
rm: remove `testfile'? y
If you need to remove all the files in a directory then we could use recursion with the -r switch
# rm -r /olddata/
Be careful if using wildcards like * with this tool. |
|
rpm |
Red Hat Package Manager (automating software binaries and remembers what files are needed so the software will run properly
RPM tracks dependencies and will inform you if additional packages are needed.
There is a database of packages and what files they use. If you do an uninstall it will be checked if other packages will also use this files.
If you try to uninstall a package that other packages are still dependent upon, RPM informs you about it and refuses to do the uninstall.
Single files can not be retrieved, you can only install the whole package or nothing.
Install without output:
rpm -i packagename or rpm --install packagename
Install with verbose output:
rpm -ivh packagename
Update a package:
rpm -U packagename or rpm --update packagename
Get a list of all installed packages:
rpm -qa
Get the version of an installed package:
rpm -q package
Find out to whiche package a file belonges:
rpm -qf Filename
Display information about a package:
rpm -qi packagename
Show the files that will be installed:
rpm -qpl packagename
To initialize the RPM Database:
Careful do only initialize the database if it wasn't initialized before!!
rpm --initdb
Of course the database doesn't know anything about prior installed packages and in this cases you can install some packages without checking the dependency (for already installed packages. |
|
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
scp /vmimages/w2kadvsrv-sp4.iso root@esxinstructor2.education.vmw:/vmimages/ |
|
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 |
|
service |
RedHat-made tool for daemon (service) starting/stopping/restarting/status querying. Syntax is "service daemon name [start|stop|restart|status]". Alternate to this command, which works with all Linuces is to call the script directly, like /etc/init.d/httpd.vmware restart, /etc/init.d/xinetd restart, or /etc/init.d/sshd restart.
service --status-all
This lists all the service daemons and their status. We can find running services by looking for the running status
service --status-all |grep running
would produce an output similar to the following:
crond (pid 1423) is running
httpd (pid 1486 1482 1479) is running
syslogd (pid 1136) is running
sshd (pid 1208) is running
To avoid unnecessarily rebooting an ESX server after making certain configuration changes, we can frequently just restart the appropriate daemon. For example we could restart the Apache web server for the MUI with the command:
service httpd.vmware restart
and we can also check a named service running status with
service httpd.vmware status
Great way to do orderly restart of vmnix network configuration.
service network restart |
|
su |
Switch user. By default, this allows you to log in as the root user if you know the root user's password. You can also use the command to log in as any other user if you know the appropriate user name and password. Enter the command, then enter the password when prompted.
su User2
Log in as User2.
su - root
apply also the new users (root) environment |
|
tail -f |
Like "head", but start from the end of the file.
Practical command to follow what is happening with a log file is command like tail -f /var/log/messages.
tail -n shows n lines of a files |
|
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 |
|
top |
Shows the running processes in the service console and lists the top consumers of CPU time. |
|
vi |
Standard UNIX text editor. Ok, so it's not that friendly to use, but it's small, surprisingly powerful and gets the job done.
So, what commands do you need to know? These are the core commands to get editing.
i Changes to insert mode where you can edit the text
ESC Exits the current mode, e.g. out of insert mode back to view mode.
:wq Write the file and quit the editor
:q! Quit the editor without saving changes
SHIFT ZZ Quit the editor and save any changes made
These commands are just extra if you have the inclination to learn!
$ jumps to the end of the opened file
dd delete a line - if you precede this with a number e.g. 8dd, then it would delete 8 lines
%s/old/new/g substitute any occurrences of the world "old" with the world "new"
There are some great web sites which document the features of vi in superb depth, one of them is the staff site at University of Washington which helped me. Their site is at http://staff.washington.edu/rells/R110/
|
|
vdf -h |
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) |
|
vmware -v |
Display ESX Version Number
Should display information along this kind ?VMware ESX Server 3.0.1 build-32039 |
|
whiche |
shows the path to the executeable
#which nano
/usr/bin/nano |
|
& |
Run process in background by adding at the end of the command |