Thursday, August 25, 2011

LINUX BASIC COMMANDS

LINUX BASIC COMMANDS

#clear clears the screen
#date displays date and time
#cal displays calendar of current month
#cal 1980 displays calendar of year 1980
#cal 5 2020 displays calendar of 5th month of the year 2020.
#hostname to display the host or machine name
#hostname Nascent changes the host name to Nascent from the current one
#domainname to display the current domain name or FQDN
#domainname nas.com changes the domain name to nas.com

The hostname , domain name & network information resides in the following file:
/etc/sysconfig/network

X-Window Mode:-

#startx to enter Linux graphical mode from a text mode.
#init 5 also used to enter graphical mode from a text mode.

Cntrl+Alt+Backspace to quit from x-window mode.

Shut down from LINUX:-

#logout is the command used to logout from a user session
#reboot is the command used to restart or reboot
#init 6 also helps to restart or reboot the system.
#init 0 is the command used to shut down the system.
#halt ,
#poweroff can also be used to shut down the system.

ctrl+d to logout from a user session
ctrl+c interrupts a currently running process and quit from it.
ctrl+w helps to remove word by word
ctrl+u helps to remove a line

#whoami displays the name of currently logged in user.
#who am i displays effective userid (if using ‘su’ cmnd).

#who displays information of all users who have currently logged in.
#finger displays the full information of a user
#users displays all users who have currently logged in
#groups displays all groups
#w displays the information about the users currently logged in along with their processes
#pwd shows the present working directory
#echo $PATH displays the current path of that user.
#uptime tells how long the system has been on
#last show listing of last logged in users.
#dmesg helps to view all boot time messages.
#ps list running processes
#ls displays the directory contents

#ls -l displays files with their attributes. Eg: --rw-r-
#ls -a shows all files including hidden files
#ls -al shows all files along with hidden files and the attributes of each file
#ls -i displays files and its nodes
#ls -sh to display size of a file in human readable form like KB, MB etc.
#ls | more displays directory contents page wise.
#ls a* displays all files starting with ‘a’
#lp to print linux documents
#uname print system information
#uname –a print all information
#uname –m prints all machine information
#uname –r prints kernel release version
#uname –s prints kernel name
#uname –o prints the name of the OS

#Whereis cmnd locate the binary, source, man page files.
#info cmnd displays the information/help of the command given.
| more to display page by page. Eg: -ls | more
| sort to display in alphabetical order. Eg: - ls |more | sort

Directory and File Manipulation: -
#touch filename creates null or zero content files.
#cat > filename creates a new file
#cat filename displays the content of that file.
#cat f1 >f2 creates a copy of the file f1 as f2.
#cat >> f4 helps to append a line to the end of a created file.

#mv helps to rename or move location of files/directories.
#mv f3 f5 renames f3 to f5
#mv f4 /etc/ moves the file from current location to given location.


#rm f4 deletes a file named f4.
#mkdir directoryname creates a new directory.
#mv d1 d2 changes directory name from d1 to d2
#cd d3 used to change to directory d3.
#cd .. used to change to previous directory.
#cd / used to change to root directory.
#rmdir dirname to delete an empty directory
#rm –r dirname to delete a directory which is not empty and also needs confirmation.
#rm –rf dirname to delete a directory forcefully with out asking for confirmation.
#cp f1 f2 used to copy file f1 to f2
#cp –R dirname copies a dir along with all its contents(subdirectories)
#less filename to display file content page wise.
#head –2 filename displays the first 2 lines of the file specified.
#tail –5 filename displays the last 5 lines of the mentioned file.
#diff f1 f3 displays the difference between the files f1 and f3.
#cmp f1 f3 compares the 2 files f1 and f3.
#wc –l filename displays the no: of lines in the particular file.
#wc –c filename displays the no: of characters in specified file.
#df –m displays all Linux partitions with memory size in MB.
#fdisk command used for disk management

File Attributes

LINK
Links can be classified into 2 types, they are Soft link and Hard link.

#ln filename link-name used to create Hard link
Here the inode value is same for both file and link. Here even if the source is gone, the link will still exist. Hard link cannot be created for a directory.

#ln –s file/dir_name link-name used to create Soft Link
Here the inode value is different for file and link. Here if the source is gone, the link not work.


Search a File from Command Mode: -
#find directory –name filename
Eg:- #find /etc –name god to search a file named god in the directory /etc.
#grep ‘string’ filename search a particular string/text in the given file.
Eg:- #grep ‘default’ /etc/inittab to search a string named default in this file.
#ls | grep ‘string’ to search all files/dir starting with the given string
Eg:- #ls | grep ‘init’ to search all files starting with init
#whatis lists directory contents
#locate item to be searched to search that particular item
Eg: -locate binaries search for binaries.

No comments: