Вы находитесь на странице: 1из 13

Linux Command Line Reference

5/9/2012 Md. Azaj Ikbal (RHCSA, RHCE) E-mail: azaj.ikbal@gmail.com

To start-up with the Linux first someone needs to know about the basic Linux commands. These commands are common in most common Linux distributions. If you know these basic Linux commands, it will be easy for you to get further in your goal to achieve a Red Hat Certification. To be a system administrator you need to know how to manage the server using command line, because you will hardly allowed using GUI. Because most of the system administration tasks are managed remotely using the secure shell also known as SSH. So use the command line as much as possible.

The color code of the files is as follows:


Blue: Directory file White: Normal file Green: Executable file Yellow: Device file Magenta: Picture file Cyan: link file Red: Compressed file

Linux File (Types)


- = Normal file (Hypen) d=directory l =Link file b=Block device file c=Character device file s= Socket File p=Pipe File . = Hidden Files starting with a dot (.) are a hidden file. Basic Linux Commands and there explanation is given below: at - Execute commands at a later time [root@rhel6 ~]# at -f myscript.sh 2:50 friday arp - Manipulate the system ARP cache [root@rhel6 ~]# arp bc - An arbitrary precision calculator language [root@rhel6 ~]# bc bzip2 - A file compression utility. [root@rhel6 ~]# bzip2 file2 cal - Displays a calendar [root@rhel6 ~]# cal 2012 cat - Concatenate and print files Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved. Page 2

[root@fileserver ~]# cat /etc/passwd cd - With no option will changes to the home directory. cd / - Will change to the root (/) directory cd .. - Will change one level up in the directory tree. cd - Will back to previous directory [root@rhel6 [root@rhel6 [root@rhel6 [root@rhel6 ~]# ~]# ~]# ~]# cd cd / cd cd ..

chage - Change user password expiry information [root@rhel6 ~]# chage -E "2012-06-31" robi chgrp - Change group ownership [root@fileserver ~]# chgrep sales file2 chkconfig - updates and queries runlevel information for system services [root@rhel6 ~]# chkconfig vsftpd on chmod - Change file access permissions [root@rhel6 ~]# chmod 740 file10 chown - Change file owner and group [root@rhel6 ~]# chown robi file11 clear - Clear the terminal screen [root@rhel6 ~]# clear cp - Copy files and directories [root@rhel6 ~]# cp /etc/passwd /home/robi crontab - Set schedule periodic background work [root@rhel6 ~]# crontab -e cut - Print selected parts of lines [root@rhel6 ~]# cut -d : -f 1 /etc/passwd date - Print or set the system date and time [root@rhel6 ~]# date [root@rhel6 ~]# date -s "2 JUN 2012 18:00:00" debugfs - Ext2/ext3/ext4 file system debugger [root@rhel6 ~]# debugfs -w /dev/sda2 df - Report file system (Linux) disk space usage

Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved.

Page 3

[root@rhel6 ~]# df -HT diff - Find differences between two files [root@rhel6 ~]# diff file1 file2 dig - DNS lookup utility [root@rhel6 ~]# dig ns1.cslitbd.com dir - List directory contents [root@rhel6 ~]# dir linux1 dmesg - Print or control the kernel ring buffer [root@rhel6 ~]# dmesg | less [root@rhel6 ~]# dmesg | grep hd dnsdomainname - Show the system's DNS domain name [root@rhel6 ~]# dnsdomainname du - Estimate file space usage [root@rhel6 ~]# du -ch filename e2label - Change the label on an ext2/ext3/ext4 filesystem [root@rhel6 ~]#e2label /dev/sda11 mylinux echo - Display a line of text [root@rhel6 ~]# echo cslit training edquota - Edit user quotas [root@rhel6 ~]# edquota robi eject - Open and closed removable media [root@rhel6 ~]# eject [root@rhel6 ~]# eject -t fdisk - Partition table manipulator for Linux [root@rhel6 ~]# fdisk -l find - Search for files in a directory hierarchy [root@rhel6 ~]# find [where to find] - name [what to find] finger - User information lookup program [root@rhel6 ~]# finger rani free - Free allocated memory [root@rhel6 ~]# free -m

fsck - Check and repair a Linux file system [root@rhel6 ~]# fsck.ext4 /dev/sda11 Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved. Page 4

ftp - Internet file transfer program [root@rhel6 ~]# ftp 192.168.11.254 gawk - The GNU version of the awk text processing utility. [root@rhel6 ~]# ps aux > processes [root@rhel6 ~]# gawk '{print $1$2$3$4}' processes gpasswd - Administer the /etc/group file [root@rhel6 ~]# gpasswd -M rani,robi,sumon sales

grep - Print lines matching a pattern [root@rhel6 ~]# cat /etc/passwd | grep robi groupadd - Create a new group [root@rhel6 ~]# groupadd sales groupdel - Delete a group [root@rhel6 ~]# groupdel groupmod - Modify a group [root@rhel6 ~]# groupmod -n airtel warid gunzip, gzip - Compress or expand files [root@rhel6 ~]# gunzip file.tar.gz [root@rhel6 ~]# gzip file.gz halt - Stop the system [root@rhel6 ~]# halt head - Output the first 10 line of file [root@rhel6 ~]# head /etc/passwd host - DNS lookup utility [root@rhel6 ~]# host ns1.cslitbd.com hostname - Show or set the system's host name [root@rhel6 ~]# hostname [root@rhel6 ~]# hostname gateway history - Show and delete all command history [root@rhel6 ~]# history [root@rhel6 ~]# histoy -c id - Print user identity [root@rhel6 ~]# id robi ifconfig - View and configure a network interface [root@server ~]# ifconfig Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved. Page 5 sales

[root@server ~]# ifconfig eth0 [root@server ~]# ifconfig eth0 192.168.11.254 255.255.255.0 up [root@server ~]# ifconfig eth0 192.168.11.254 255.255.255.0 down info - A stand alone TTY based reader for GNU texinfo documentation. [root@server ~]# info passwd init, telinit - Process control initialization [root@server ~]# init 6 [root@server ~]# telinit 5 iptables - Tools for managing Linux kernel packet filtering capabilities. [root@server ~]# iptables -L [root@server ~]# ifconfig -F [root@server ~]# service iptables restart kill - Terminate a process killall kill processes by name [root@server ~]# killall -9 firefox [root@server ~]# kill -9 firefox last - Show listing of last logged in users [root@rhel6 ~]# last lastb - Show listing of last logged in users [root@rhel6 ~]# lastb lastlog - Reports the most recent login of all users or of a given user [root@rhel6 ~]# lastlog less - Opposite of more [root@rhel6 ~]# cat /etc/passwd | less link - Link to a file [root@rhel6 ~]# link -s file1 /linux/file2 [root@rhel6 ~]# link -s file10 /linux/file20 ln - Make links between files [root@rhel6 ~]# ln -s file1 /linux/file2 [root@rhel6 ~]# ln file10 /linux/file20 lpq - Show printer queue status [root@rhel6 ~]# lpq lpr - Print files [root@rhel6 ~]# lpr lprm - Cancel print jobs [root@rhel6 ~]# lprm

Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved.

Page 6

lpstat - Print cups status information [root@rhel6 ~]# lpstat locate - Find files by name [root@rhel6 ~]# locate passwd ls - List directory contents [root@server [root@server [root@server [root@server ~]# ~]# ~]# ~]# ls ls -l ls -la ls -lih

lspci - List all PCI devices [root@rhel6 ~]# lspci lsmod - Program to show the status of modules in the Linux Kernel [root@rhel6 ~]# lsmod | less lsusb - List USB devices [root@rhel6 ~]# lsusb m4 - The GNU macro processor. [root@rhel6 ~]# m4 sendmail.mc > /etc/sendmail.cf mail - Send and receive mail [root@rhel6 ~]# mailq mailq - Print the mail queue [root@rhel6 ~]# mail - "Hello" boss@cslitbd.com make - GNU make utility to maintain groups of programs [root@rhel6 [root@rhel6 [root@rhel6 [root@rhel6 [root@rhel6 ~]# make menuconfig ~]#make gconfig ~]# make ~]# make modules ~]# make modules_install

man - Format and display the on line manual pages [root@rhel6 ~]# man ifconfig mii-tool - View, manipulate media-independent interface status [root@rhel6 ~]# mii-tool eth0 mkdir - Make directories [root@rhel6 [root@rhel6 [root@rhel6 [root@rhel6 ~]# ~]# ~]# ~]# mkdir mkdir mkdir mkdir training /cslit/training/linux -p class11 class12 class13 /class{5,6,7,8} Page 7

Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved.

mkdosfs - Create an MS DOS file system under Linux [root@rhel6 ~]# mkdir /class{5,6,7,8} mke2fs - Create an ext2/ext3 file system [root@rhel6 ~]# mke2fs -j /dev/sda12 mkfs - Build a Linux file system [root@rhel6 ~]# mkfs.ext4 /dev/sda10 mkisofs - Creates an image of an ISO9660 filesystem. [root@rhel6 ~]# mkisofs -o image.iso -v -R /directory mkswap - Set up a Linux swap area [root@rhel6 ~]# mkswap /dev/sda11 modprobe - Add and remove modules from the Linux Kernel [root@rhel6 ~]# modprobe your-kernel-module more - File perusal filter for crt viewing [root@rhel6 ~]# cat /etc/passwd | more mount - Mount a file system [root@server [root@server [root@server [root@server ~]# ~]# ~]# ~]# mount mount mount mount /dev/dvd /mnt /dev/sdb1 /media -t vfat /dev/sda12 /software -t nfs 192.168.11.254:/share/rpm /myshare

mv - Move (rename) files [root@rhel6 ~]# mv file10 file20 netstat - Print network connections [root@rhel6 ~]# netstat -nplr newaliases - Rebuild the data base for the mail aliases file [root@rhel6 ~]# newaliases newgrp - Change to a new group nslookup - Query Internet name servers interactively [root@rhel6 ~]# nslookup ns1.cslitbd.com passwd - Update a users authentication tokens(s) [root@rhel6 ~]# passwd robi partprobe - Inform the OS of partition table changes [root@rhel6 ~]# partprobe /dev/sda ping - Send ICMP ECHO_REQUEST to network hosts

Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved.

Page 8

[root@rhel6 ~]# ping ns1.cslitbd.com [root@rhel6 ~]# ping 192.168.11.254 poweroff - Stop the system [root@rhel6 ~]# poweroff ps - Report a snapshot of the current processes [root@rhel6 ~]# ps -aux | more pstree - Display a tree of processes [root@rhel6 ~]# pstree pwd - Print name of current/working directory [root@rhel6 ~]# pwd quota - Display disk usage and limits [root@rhel6 ~]# quota quotacheck - Scan a filesystem for disk usage, create, check and repair [root@rhel6 ~]# quotacheck -avug quotaon - Turn filesystem quotas on and off [root@rhel6 ~]# quotaon /quota quotaoff - Turn filesystem quotas on and off [root@rhel6 ~]# quotaoff -auvg reboot - Reboot or enable or disable Ctrl-Alt-Del [root@rhel6 ~]# reboot renice - Alter priority of running processes [root@rhel6 ~]# renice 5 -p 13220 repquota - Summarize quotas for a filesystem [root@rhel6 ~]# repquota /quota [root@rhel6 ~]# repquota -g /quota reset - Terminal initialization [root@rhel6 ~]# reset resize2fs - File system resizer [root@rhel6 ~]# resize2fs /dev/sda1 6000M rm - Remove files or directories [root@rhel6 ~]# rm -r mydocument rmdir - Remove empty directories [root@rhel6 ~]# rmdir linuxdoc Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved. Page 9

route - Manipulate the IP routing table [root@rhel6 ~]# route -n rpm - RPM Package Manager [root@server ~]# rpm -qa | grep vsftpd [root@server ~]# rpm -ivh vsftpd.2.0.10-5.el5.i386.rpm rsync - A program for synchronizing files over a network. [root@rhel6 ~]# scp /home/ikbal/data.txt nazrul@server:/home/mydoc scp - Secure copy (remote file copy program) [root@rhel6 ~]# rsync -avz ikbal@192.168.11.10:/home/rpm /root/backup sed - A GNU stream text editor [root@rhel6 ~]# sed 's/\([^:]*\).*/\1/' /etc/passwd setquota - Set disk quotas [root@rhel6 ~]# setquota -g quotagrp 5 100 6 10 -a /dev/loop0 sftp - Secure file transfer program [root@rhel6 ~]# sftp nazrul@cslitbd.com showmount - Show mount information for an NFS server [root@rhel6 ~]# showmount -e 192.168.11.12 shutdown - Bring the system down [root@rhel6 [root@rhel6 [root@rhel6 [root@rhel6 [root@rhel6 ~]# ~]# ~]# ~]# ~]# shutdown shutdown shutdown shutdown shutdown r now h now r 20:00 h 20.00 c

ssh - OpenSSH SSH client [root@rhel6 ~]# ssh 192.168.11.254 [root@rhel6 ~]# ssh -p 2212 192.16811.254 [root@rhel6 ~]# ssh -P 2212 robi@192.168.11.254 su - Run a shell with substitute user and group IDs [root@rhel6 ~]# su [root@rhel6 ~]# su - ikbal sudo - Execute a command as another user [robin@rhel6 ~]$ sudo mount /dev/sda3 /mnt swapoff - Start/stop swapping to file/device [root@rhel6 ~]# swapoff -a swapon - Enable/disable devices and files for paging and swapping

Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved.

Page 10

[root@rhel6 ~]# swapon /dev/sdc1 tail - Output the last part of files [root@rhel6 ~]# tail n 5 /etc/passwd tar - The GNU version of the tar archiving utility [root@rhel6 ~]# tar filename.tar filename

tcpdump - Dump traffic on a network [root@rhel6 ~]# tcpdump -i eth1 telnet - User interface to the TELNET protocol [root@rhel6 ~]# telnet 192.168.11.254 top - Display Linux tasks [root@rhel6 ~]# top touch - Change file timestamps [root@rhel6 ~]# touch fil1 [root@rhel6 ~]# touch /linux/lesson{1,2,3} traceroute - Traces the route packets over an IPv4/IPv6 network [root@rhel6 ~]# traceroute www.cslitbd.com tty - Print the file name of the terminal [root@rhel6 ~]# tty tune2fs - Adjust tunable filesystem parameters [root@rhel6 ~]# tune2fs -L usbstroage /dev/sdb2 umount - Unmount file systems [root@rhel6 ~]# umount /dev/sdb1 [root@rhel6 ~]# umount /mnt uname - Print system information uname - r -Linux kernel information [root@rhel6 ~]# uname [root@rhel6 ~]# uname -r uptime - Tell how long the system has been running [root@rhel6 ~]# uptime useradd - Create a new user or update default new user information [root@rhel6 ~]# useradd robi [root@rhel6 ~]# useradd -G samba rani userdel - Delete a user account and related files [root@rhel6 ~]# userdel robi Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved. Page 11

[root@rhel6 ~]# userdel -r rani usermod - Modify a user account [root@rhel6 ~]# usermod -G media joy users - Print the user names of users currently logged in to the current host [root@rhel6 ~]# users Vi/vim - Linux text editor [root@rhel6 ~]# vi oldfile [root@rhel6 ~]# vim newfile vmstat - Report virtual memory statistics [root@file ~]# vmstat -S M w - Show who is logged on and what they are doing [root@file ~]# w wc - Word, line, and byte or character count [root@file ~]# wc file11 wget - A utility for retrieving files using the HTTP or FTP protocols. [root@file ~]# wget http://www.cslitbd.com/tutorial_pdf/Linux/NAT.pdf whatis - Search the whatis database for complete words [root@file ~]# whatis useradd whereis - Locate the binary, source, and manual page files for a command [root@file ~]# whereis bash which - Shows the full path of (shell) commands [root@file ~]# which adduser who - Show who is logged on [root@file ~]# who whoami - Print effective userid [root@file ~]# whoami yum - Yellowdog Updater Modified [root@file ~]# yum install samba* -y [root@file ~]# yum remove samba*

The End
Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved. Page 12

Prepared by: Md. Azaj Ikbal(RHCE). All rights are reserved.

Page 13

Вам также может понравиться