JPHHLASH

Linux Commands

Home
header files
Linux Commands
access windows partition from linux
startup
compiling from source code
how to run C/C++ programs in linux
some useful shell scripts
environment variables
fork and exec
Using apache
php in linux
read/write in linux

Here I'll put a list of some common Linux console commands.

List of some commands used in Linux



If you want to get more information about any of the following command, use man page or info pages as

Syntax:
man {command-name}

Example:
$ man cat



Syntax:
info {command-name}

Example: $ info date



Even some command like mv, ls give command help on command line by typing command as follows

Syntax:
{command-name} --help

Example:
$ mv --help
$ ls --help | more

To see help or options related with ls command; here you can get screen-by-screen help, since help of ls command is quite big that can't fit on single screen.

NOTE that following commands are for new users or for Beginners only. The purpose is if you use this command you will be more familiar with your shell and secondly, you need some of these command in your Shell script.



cat

To display text file.

Syntax

cat {file name}

Examples

$cat foo

cfdisk*

To create/modify/delete partition table interactively.

Syntax

cfdisk

cd

To change current directory.

Syntax

cd {directory name}

Options

- (minus) Change to previous directory location.

Examples

$ cd /usr/local/apache

$ pwd
/usr/local/apache

$ cd /var/log
$ pwd
/var/log

$ cd –
$ pwd

/usr/local/apache

$ cd (Change to home directory)

NOTE: Linux’s $OLDPWD variable holds your last directory setting, if you type $ cd $OLDPWD, it is same as $ cd -. What happen if you type $ cd – as soon as you login into Linux?

chfn

Change the finger information of user.

Syntax

chfn [user-name]

Examples

$ chfn vivek

$ chfn # change the currently log on users finger information

chgrp

Change the group owner of a file.

Syntax

chgrp {group name} {file/directory name}

Options

-R Recursively change group owner of files/directory

Examples

chgrp oracle /usr/database
chgrp msc /home/cstudents

chmod

Change the file/directory permission directory.

Syntax

chmod permission-options file/directory name.

Options

(a)permission-options -
rwx rwx rwx

| | |

1 2 3
1 – owner

2 – group

3 – others

For r,w,x octal value is 4,2,1 respectively.
So if you want to give r,w,x permission to owner, for group r,x, and for w,x to others. Then,

rwx rwx rwx

421 401 021

For owner add this number as 4+2+1 = 7

For group add this number as 4+0+1 = 5

For others add this number as 0+2+1 = 3

So command will be $ chmod 753 filename

Examples

$chmod 755 first.sh



(b)permission-options -



chmod {u|g|o|a} {+|-} {r|w|x} {filename}

u - User who owns the file
g - Group file owner
o - User classified as other
a - All other system user


+ Set permission
- Remove permission


r - Read permission
w - Write permission
x - Execute permission
Examples

$ chmod u+x,g+wx,o+x myscript



Above command set permission for file called 'myscript' as User (Person who creates that file or directory) has execute permission (u+x) Group of file owner can write to this file as well as execute this file (g+wx) Others can only execute file but can not modify it, Since we have not given w (write permission) to them. (o+x).

chown

Change the owner of file/directory.

Syntax

chown {username}[.group-name] {file/directory-name}

Options

-R Recursively change group owner of files/directory

Examples

$chown vivek.users *.jsp

All files ending with .jsp are now owned by user vivek of the group users.

clear

Clear the screen.

Syntax

clear

cp

To Copy files.

Syntax

cp {source} {destination}

Options

-f force the cp to copy files even if file exist (overwrite the files).

-i Ask y/n confirmation before coping each file.

Examples

$ cp -f /mnt/floppy/* /home/vivek

cmp
To use to compare files

Syntax

cmp {file1} {file2}

Examples

$ cmp myfile myfile.old

date*

Change or set current date and time.

Syntax

date [date or time string ]

Examples

$date # will show current date & time

$date --date=“2001-3-15“ # will set date to 2001-Mar-15

$date --date=“2001-3-15 11:59 AM” # date as well as time

df

Display the disk space used file system.

Syntax

df

Options

-m Displays information in MB.

-k Displays information in KB.

-h Displays information in easy-to-understand format.

diff

Display differences (Comparison between two files) in files.

Syntax

diff {file1} {file2}

dmesg

To display kernel log messages. (Which are shown when your system first time boot)

Syntax

dmesg

du

Displays the disk usage according to space used by file/directory.

Syntax

du [directory name]

Options

-a all files

-k Displays information in KB.

-h Displays information in easy-to-understand format.

-s Displays only total not details.

fdisk*

To create/ modify/ delete partition table.

Syntax

fdisk {device -name}

Options

This are command of fdisk, you have to use this command after fdisk program starts.

a Mark bootable partition.

d Delete partition.

m Help

n Create new partition.

p Print partition table on screen.

q Quit without saving changes.

t Changes the partition type ID (type)

w Quit and save changes to disk.

Examples

$fdisk /dev/hda

find

To Search files.

Syntax

find dirname -name files-to-find -print

Examples

$ find / -name *.c -print

finger

Get user information.

Syntax

finger [user-name]

Examples

$finger

$finger vivek

fsck*

To check the file system for errors, and if found repair it.

Syntax

fsck {device name}

Options

-f force to repair.

-y Assume “yes” for all questions.

Caution Do’t run fsck in multiuser mode, first run system in single mode then un mount file system and then run the fsck.

Examples

$ init 1 # go to single user mode or you can type linux single at

# LILO prompt while booting the system. Note that if your

# LILO is password protected, then you have to supply

# password for it.

$ umount /dev/hdx # replace x with your partition number for e.g

# umount /dev/hda1

$ fsck /dev/hda1

$ reboot

grep

To search text files for particular text.

Syntax

grep “patter-to-search” file-name

Examples

grep “Red Hat” /etc/*

gzip

To compress or decompress file.

Syntax

gzip file-nane

Options

-d decompress

-S suffix

Examples

$ gzip ltips

$ ls

$ gzip -d ltips

init*

Use to switch between different run-levels.

Syntax

init 0123456

Options
0 halt the system

1 Single-user mode

2 Multi-user without NFS

3 Full Multi-user (Default)

4 Unused
5 Start X windows
6 Reboot system

Examples
$ su -l

# init 6 # reboot
# init 1 # single user mode.

logout

To login out

Syntax

logout

last/lastlog*

To Display login, telnet and ftp log of your Linux Server.

less
To display file contains

Syntax

less filename

ln
Create a link.

Syntax

ln -s {file/directory} {file/directory}

Examples

$ln -s p longprogname

$ls -l

locate*

To quickly (securely also) search file.

Syntax

locate {file name}

Options

-R Recursively display the files & directory.

-l Long listing of files & directory.

Note

If you are running locate first time then run following command, which will create database file. (Run as root user)

$ su

password

#/etc/cron.daily/slocate.cron

Examples

$locate -l foo

ls
Shows list of files and dirs

Syntax

ls [file/dir name]

Options

-R Recursively display the files & directory.

-l Long listing of files & directory.

-a Show all files start with . (DOT) # for e.g.: .bash_profile

-N Name wise sorting.

Examples

$ ls

$ ls -lR / > alist &

$ ls –a

mail

Read or send the mail.

Syntax

mail {user-name}

Options
If you are reading mail use following command

d - Delete the mail.

q - Quit the mail program.

s - Save the mail to mailbox.
Examples

$ mail # read your mail

$ mail vivek

mount/umount*

Mount/unmount the file system. Useful to work with floppy,cdrom, other (DOS/Windows) partition etc.

Syntax

mount -t {file system type} { device name } {mount point}

Options

-t can be msdos or vfat

Examples

# must be root user

#To mount your Cd-Rom

# mount /dev/cdrom
# mount –t msdos /dev/fd0 /mnt/floppy

# cd /mnt/floppy

# ls

# mount # to see all mounted device

more
To view text file

Syntax

more {file name}

mv

To move the file(s)/directory.

Syntax

mv {source} {destination}

pr

To print file.

Syntax

pr {file-name}

Examples

$pr myfile

passwd

To change the password.

Syntax

passwd {username}

Options

-d Delete the password. (Use with very carefully)

Examples

$ passwd

ping

Network related command, to verify that network is connected and working properly.

Syntax

ping {host-name | IP Number}

Examples

$ping www.yahoo.com # if connectd to Internet

$ping 192.168.1.78

pwd

Print working directory.

Syntax

$ pwd

rpm*
Red Hat Linux Package Management program. Use this to install/ uninstall/ upgrade software under Linux (Red Hat Linux Ver. 6.x Only)

Syntax

rpm {option} {.rpm file}

Options

-i Install .rpm software.

-U Upgrade the software.

-e Delete the software.

-l List all files in .rpm software package

Examples

$ rpm -i demo.rpm

rm
Remove the files.

Syntax

rm {filename}

Options

-rf Remove all files/directory with subdirectories. (DOS’s – deltree)

Examples

$ rm foo

$ rm -rf /home/vivek/oldfiles

sort

To sort files.

Syntax

sort {file-name}

Options

-r Reverse normal order
-n Sort in numeric order
-nr Sort in reverse numeric order

Examples

$sort myfile

startx

Start X windows system.

Syntax

startx

Options

Press ctrl + alt + backspace to kill x windows.

shutdown*

Shutdown linux.

Syntax

shutdown

Options

-r Reboot Linux.

-h Halt or Shutdown

Example

$shutdown –h now

smbpasswd*

Samba password change.

Syntax

smbpasswd {username}

Examples

$smbpasswd rani

su*

Become super user if user name is not given, or change the user ID.

Syntax

su [username]

tar

Linux archive program.

Syntax

tar options {tar-file-name} {dir-name-to-archive}

Options

-c Create the file.

-f {filename} Name of archive file

-z Compress the file.

-x Extract the files from archive

Examples

# To create archive file of /home/vivek directory

$ tar -czf mybackup.tar.gz /hove/vivek

#If you want to extract file from above

$ tar -xf mybackup.tar.gz

testparm/testprns*

Test the /etc/smb.conf file for errors.

testparm – To test share setting.

testprns – To test printer setting.

Above will also display setting and error if any.
Syntax

testparm

testprns

top

To see process information in neat format.

Syntax

top

Options

? Get more information about top command.

touch

Create empty file or change/update time stamp of file.

Syntax

touch {filename}

Examples

$ touch /etc/dhcpd.leases #create file for dhcpd demon

$ touch /etc/modules # update time stamp of file

umask

Specify the permission for files when files are created for owner(u),group(g), and others(o).

Syntax

umask –S {u=xx,g=xx,o=xx}

Where xx can be (r)ead,(w)rite.

Or you can use 022 for read only file permission for others and 077 for read and write permission.

Examples

$umask -S u=rw,g=,o=

$umask 022

useradd/userdel*
Add/delete new user to your system

Syntax

useradd -g {group-name} {user-name-to-add}

userdel {user-name-to-delete}

Examples

#add rani user to system (must be root)

#adduser -g oracle rani

#passwd rani

#Delete the user kaju

#userdel kaju

w

Shows who logged on and what they are doing

Syntax

w

who am i

About your self.

Syntax

who am i

which

Show the location of file from which it is executed when you type the name.

Syntax

which {file name}

Examples

$ which gaim
/usr/bin/gaim


$ ls –l `which cc`

whatis

This command gives the brief summary of the command used.
eg
$ whatis gaim
Gaim (3pm) - Perl extension the Gaim instant messenger
gaim (rpm) - A Gtk+ based multiprotocol instant messaging client



xinit

Initializes X window without loading any windows manager.

Syntax

xinit

Examples

$ xinit

$ kde



* For this command you must be root or root equivalent user.
penguin.jpg

penguin.jpg

Tux , the Linux penguin

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`

 

Feedback, query, ideas? Email crenshaw_jo@yahoo.com.