15
Linux Basic Administration Commands i | Page Table of Contents Overview ....................................................................................................................................................... 1 Applies To...................................................................................................................................................... 1 Init Levels or Run levels................................................................................................................................. 1 Init Levels Table......................................................................................................................................... 1 chkconfig ....................................................................................................................................................... 1 chmod ........................................................................................................................................................... 2 chown............................................................................................................................................................ 2 crontab .......................................................................................................................................................... 3 df ................................................................................................................................................................... 3 du .................................................................................................................................................................. 3 free ................................................................................................................................................................ 4 fdisk ............................................................................................................................................................... 4 groupadd ....................................................................................................................................................... 5 groupdel ........................................................................................................................................................ 5 ifconfig .......................................................................................................................................................... 5 ifup ................................................................................................................................................................ 6 grep ............................................................................................................................................................... 6 find ................................................................................................................................................................ 7 kill .................................................................................................................................................................. 7 passwd .......................................................................................................................................................... 8 pidof .............................................................................................................................................................. 8 tail ................................................................................................................................................................. 8 tar .................................................................................................................................................................. 9 zip .................................................................................................................................................................. 9 unzip ............................................................................................................................................................ 10 gzip .............................................................................................................................................................. 10 gunzip .......................................................................................................................................................... 10 top ............................................................................................................................................................... 11 touch ........................................................................................................................................................... 11 useradd ....................................................................................................................................................... 12 userdel ........................................................................................................................................................ 12

Linux Basic Administration Commands Guide

Embed Size (px)

Citation preview

Page 1: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

i | P a g e

Table of Contents

Overview ....................................................................................................................................................... 1

Applies To ...................................................................................................................................................... 1

Init Levels or Run levels ................................................................................................................................. 1

Init Levels Table......................................................................................................................................... 1

chkconfig ....................................................................................................................................................... 1

chmod ........................................................................................................................................................... 2

chown ............................................................................................................................................................ 2

crontab .......................................................................................................................................................... 3

df ................................................................................................................................................................... 3

du .................................................................................................................................................................. 3

free ................................................................................................................................................................ 4

fdisk ............................................................................................................................................................... 4

groupadd ....................................................................................................................................................... 5

groupdel ........................................................................................................................................................ 5

ifconfig .......................................................................................................................................................... 5

ifup ................................................................................................................................................................ 6

grep ............................................................................................................................................................... 6

find ................................................................................................................................................................ 7

kill .................................................................................................................................................................. 7

passwd .......................................................................................................................................................... 8

pidof .............................................................................................................................................................. 8

tail ................................................................................................................................................................. 8

tar .................................................................................................................................................................. 9

zip .................................................................................................................................................................. 9

unzip ............................................................................................................................................................ 10

gzip .............................................................................................................................................................. 10

gunzip .......................................................................................................................................................... 10

top ............................................................................................................................................................... 11

touch ........................................................................................................................................................... 11

useradd ....................................................................................................................................................... 12

userdel ........................................................................................................................................................ 12

Page 2: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

ii | P a g e

mount .......................................................................................................................................................... 12

umount........................................................................................................................................................ 13

Page 3: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

1 | P a g e

Overview

In this guide you will be able to manage Linux system with basic administration task.

For additional and command usage information on the specific command(s); you can run “man <command>”.

Note: Not all the parameters are explained in this document.

Applies To

Linux flavours

Init Levels or Run levels

A run level is a state of init (initialization) and the whole system that defines what system services are operating. Run numbers identifies levels;

There is no consensus of how to use the user defined run levels (2 through 5).

Some system administrators use run levels to define which subsystems are working, e.g., whether X is running, whether the network is operational, and so on.

Others have all subsystems always running or start and stop them individually, without changing run levels, since run levels are too coarse for controlling their systems.

Depending on your administration needs, define the run level based on the below.

Init Levels Table

Run Level Operation (Purpose)

0 Halt System

1 Single-user mode (Recovery / special Administration)

2 By Default - Not used (user-definable)

3 By Default - Full (multi-user mode)

4 By Default - Not used (user-definable)

5 Full multi-user mode (with an X-based login screen)

6 Reboot

chkconfig

chkconfig is a basic system utility. It updates and queries run level information for system services, manages which service(s) will start or stop automatically in a specified run levels.

chkconfig: options

--add Add an new service

--del Delete an existing service

Page 4: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

2 | P a g e

--level numbers, 0- 6: Update init levels

--list List Services that are added

Syntax:

chkconfig --add <service Name>

Example:

chkconfig --add httpd

chkconfig --levels 345 httpd on

chmod

chmod changes the permissions for a file; permissions should include a letter designating who gets permissions (u for the user, g for the group, o for others, or a for all) followed by a + or - (to give or take away the permission) followed by the kind of permission (r for read access, w for write access, x for execute if the file is a program or script).

chmod: options

-f Silent Mode

-R Recursive

4 or “r” Read Privilege(s)

2 or “w” Write Privilege(s)

1 or “x” Execute Privilege(s)

Syntax:

chmod +x <FileName>

chmod -w <FileName>

Example:

chmod +x run.sh

chmod -x run.sh

chown

chown changes the user and/or group ownership of each given file as specified by the first non-option argument, changes the ownership of one or more files to new owner.

chown: options

-f Silent Mode

-h Including symbolic links

-R Recursive

Syntax:

chown -fhR <UserID>:<GroupID> <FileName>

Page 5: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

3 | P a g e

Example:

chown -fh jboss:jboss run.sh

crontab

A short name for file /var/lib/crontab, which contains a list of Linux commands to be performed at specific times. A system administrator can use crontab as an automatic timer to trigger the initiation of important jobs.

To view, install, or uninstall your current crontab file.

crontab: options

-e Edit crontab entry of existing logged in user

-l List crontab entry of existing logged in user

-r Delete all the entries in crontab file

Syntax:

crontab <option>

Example:

crontab -e

crontab -l

df

df reports the amount of disk space used by the specified files, and by each directory in the hierarchies rooted at the specified files.

df: options

-k block size will be 1K size

-h Human readable

Syntax:

df <option> <Partition>

Example:

df -kh

du

Print disk usage (as the number of 1 KB blocks used by each named directory and its subdirectories; default is the current directory).

du: options

Page 6: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

4 | P a g e

-k block size will be 1K size

-h Human readable

-b Bytes

-c Calculate or sum

Syntax:

du -<Option> <FileName>

Example:

du -kh

free

Display statistics about memory usage: total free, used, physical, swap, shared, and buffers used by the kernel.

free: options

-b Memory usage in Bytes

-k Block size will be 1K size

-m Memory usage in Megabytes

-g Memory usage in Gigabytes

Syntax:

free -<option>

Example:

free -km

fdisk

Is a menu driven program for creation and manipulation of partition tables.

fdisk: options

-l Listing of existing drive partitions.

-s Listing of existing drive partitions size.

-v fdisk version number.

Syntax:

fdisk -<option>

Example:

fdisk -l

Page 7: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

5 | P a g e

groupadd

Create new group of accounts for the system.

-g Assign Group ID

-f Add to group forcefully

Syntax:

groupadd -<option> <GroupName>

Example:

groupadd -g 500 oracle

groupdel

Remove group from system account files

Syntax:

groupdel <GroupName>

Example:

groupdel oracle

ifconfig

Assign an address to a network interface and/or configure network interface parameters.

ifconfig: option

-a Display all the interface details

-v Verbose mode interface details

up Activate specified interface

down Shutdown the specified interface

Syntax:

ifconfig -<option> <Network Interface>

Example:

ifconfig -a

ifconfig eth0

ifconfig eth0 up

ifconfig eth0 down

Page 8: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

6 | P a g e

ifup

Enable network interface

ifup: option

-a Bring up all the interfaces that are defined in /etc/network interfaces

-f Force configuration of the interface

--no-scripts Don’t run any scripts under /etc/network/if-*.d/

Syntax:

ifup <Interface Name>

Example:

ifup eth0

ifup -a

ifdown

Disable network interface

ifdown: option

-a Bring down all the interfaces that are defined in /etc/network interfaces

-f Force configuration of the interface

--no-scripts Don’t run any scripts under /etc/network/if-*.d/

Syntax:

ifdown <Interface Name>

Example:

ifdown eth0

ifdown -a

grep

grep searches the named input FILEs (or standard input if no files are named, or the file name - is given) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.

grep: option

-c Count matching lines

-r Recursive search

-l Displays count that doesn’t match the search criteria

Page 9: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

7 | P a g e

Syntax:

grep <search string> <File Name>

Example:

grep vcp.muthukrishna /etc/password

grep -r "SearchString" /var/www/

grep -cw "SearchString" SearchFile.txt

grep -cvw "Search" SearchFile.txt

grep -l " SearchString" /www/*

find

Find locates files. Within each directory tree specified by the given paths, it evaluates the given expression from left to right, according to the rules of precedence.

find: option

-print Prints the results

-name Find string

Syntax:

Find <SearchPath> -<option>

Example:

find . -name "java" -print

find . -name "Java" -H -print

kill

Send a signal to terminate one or more process IDs.

kill: option

-9 Kills process

-l Lists all possible process IDs

Syntax:

kill -<option> <Process ID>

Example:

kill –a gcc

Page 10: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

8 | P a g e

kill -9 13445

kill -l 1234

passwd

Change / update the password of a user or logged in user.

passwd: option

-S Status of the password set

-d Deletes set password, passwordless user

Syntax:

passwd -<option> <UserName>

Example:

passwd vcp.muthukrishna

password -S vcp.muthukrishna

password -d vcp.muthukrishna

pidof

Display the process IDs of the listed program or program.

pidof: option

-s Single shot - this instructs the program to only return one pid

Syntax:

pidof -<option> Process ID

Example:

pidof -s gdm-binary

pidof pickup

tail

Print the last 10 lines of each named file

tail: option

-f Real time file print on console

-n Number of lies to print

Syntax:

Page 11: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

9 | P a g e

tail -<option> <FileName>

Example:

tail -f server.log

tail –n20

tar

Copy files to or restore files from an archive medium

tar: option

-c Create an archive file

-v Verbose mode enable

-x Extract an archive file

-z Extract gunzip, gzip

-t List the files in the archive

Syntax:

tar -<option> <TarFileName>

Example:

tar -cf ArchiveFileName.tar file1 fileN

tar -cf ArchiveFileName.tar Directory/

tar -czf ArchiveFileName.tar Directory/

tar -tvf ArchiveFileName.tar

tar -xvf httpd.tar

tar -zxvf httpd.tar.gz

zip

Create a compression file.

zip: option

-R Recursive

-v Verbose mode enable

-u Update existing compression file

Syntax:

zip -R <ZipFileName> <Include FileNames>

Example:

Page 12: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

10 | P a g e

zip -R ZipFileName.zip *.*

zip -u ZipFileName.zip AddFileName.txt

unzip

Explodes / Extracts a compression file.

zip: option

-d Folder location where the file should be exploded

-t Test archive file

-v Verbose mode enable

Syntax:

unzip -<option> <ZipFileName>

Example:

unzip -d /usr/local/Destination_Directory ZipFileName.zip

gzip

Compress a gzip file (Compression utility like zip).

gzip: option

-v Verbose mode enable

-r Recursive

Syntax:

gzip -<option> <gzipFileName>

Example:

gzip GzipFileName.gz *.*

gzip -f GzipFileName.gz *.*

gzip TarFile.tar

gunzip

Explodes / extracts a compressed gzip file.

guzip: option

-v Verbose mode enable

-r Recursive

Page 13: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

11 | P a g e

Syntax:

guzip -<option> <gzipFileName>

Example:

gunzip GunzipFileName.gz

gunzip -R GunzipFileName.gz

top

Provide information (frequently refreshed) about the most CPU-intensive processes currently running.

top: option

-u Show top info for a user

-p Show top info for a PID

-d Set delay (refresh)

Syntax:

top -<option>

Example:

top -u jboss

top -p10078

touch

Update the access time and modification time (and dates) to the current time and date.

touch: option

-c No create, if file doesn’t exists

-a Change access time only

Syntax:

top -<option> <FileName>

Example:

touch FileName.txt

touch -c FileName.ear

Page 14: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

12 | P a g e

useradd

Create new user accounts or update default account information.

useradd: option

-g group id of a the user

-d Location of home directory for user

-f Inactive user

-s Set Shell for the user

-k Skeleton directory

Syntax:

useradd -<option> <UserName>

Example:

useradd -g 500 jboss

useradd -s /bin/bash -g 500 jboss

useradd -s /bin/bash -g 500 jboss -d /usr/local/jboss

userdel

Delete all entries for user in system account files

userdel: option

-r Remove home directory and files of the user

-f Force Remove

Syntax:

userdel -<option> <UserName>

Example:

userdel -r jboss

userdel -f jboss

mount

Mounts a device on a location.

mount: option

-t Type of filesystem to be mounted

-a Mount all filesystem listed in /etc/fstab

Page 15: Linux Basic Administration Commands Guide

Linux Basic Administration Commands

13 | P a g e

-l List mounts label

-n unmounts without writing to /etc/fstab

-v Verbose

Syntax:

mount -<option> <Device> <Mount point>

Example:

mount -t ext3 /dev/hdc1 /mnt/Linux2

mount -t iso9660 -o ro /dev/cdrom /mnt/cdrom

mount /dev/cdrom/ /mnt/cdrom

mount -o loop disk1.iso /mnt/isoDisk

Note: /mnt/cdrom and /mnt/Linux2 should be already existing directory. Never mount on existing file system. You will lose the existing mount locations, you’ve to explicitly reboot to see the mount points again.

umount

Unmount’s a device that is mounted

mount: option

-n unmounts without writing to /etc/fstab

-v Verbose

-f Force Unmount

Syntax:

umount -<option> <Mount point>

Example:

umount /mnt/Linux2

umount /mnt/cdrom