Here i am going to explain the regular process of basic linux commands used in Corporate companies
To print working directory :pwd To change directory:cd To list files and contents of directories :ls To list files/direc in long format : ls –l To list the hidden files/direc : ls –a To view text files : lesstext_file To know what kind of a file it is : file name_of_file
To Copy files and directories :cp file1 filenew To move or rename the files/directories : mvfile1filenew To remove the file/directories :rm file To make directory : mkdir
Working with commands:
Display Information about command type: typecommand(ls,cp..etc) To locate the command : which command (ls…etc) To display the reference page: help –mcommand(cd..etc) To display on-line command interface : man ls
I/O Redirection :
To redirect standard output to a file: “ > “( ls>file_list.txt ) To redirect standard output to a file: “ < ”(sort <file_list.txt > sorted_file.txt) With pipeline the output of one command is fed into input of another :
ls –l | less
rpm –qa| grep –i filename :Rpm –qalistfor all rpm files installed on system andGrep Accwebitfind any containing the string “accweb” and output them.
sort : Sorts standard input then outputs the sorted result on standard output.
grep : Examines each line of data it receives from standard input and outputs every line that contains a specified pattern of characters.
tail : Outputs the last few lines of its input. (Ex : tail –f logs.txt)
to change the permissions of folders/files : ChmodXXX filename Temporarily become super user : su & sudo Change file ownership of user :chownuser filename Change file ownership of group : chgrpgroup filename Change file ownership of user & group : chownuser:group filename
To know the process running: psor jobs to know the processes running on system: Psaux to find process with user:Ps–uname of User to kill the process: Kill -9process name
-2 interrupt signal
-15 termination signal
Matches any characters:* Matches ant single character:? All filenames:* All filenames that begin with the character "g" :g* All filenames that begin with the character "b" and end with the characters ".txt" : b*.txt
to edit the configuration/txtfile (command line): vi/vim gedit is the editor supplied(GUI): gedit
Searchfile by name: Find -name "query" Search file by type: Find-typetype_descriptor_query
Type decriptor :
F -regular file
I -symbolic link
Search:locate filename We can uselocate/grep for searching :
grep"codes"install.log: searh for word/string/linein a file(grep –n ,display with line number, grep –I it search for case sensitive )
grep -i"codes"(Search string)/root/install.log (path of file)
[root@localhost ~]# grep "codes" install.log
Remote Administration :
Can use ssh with a full hostname to connect to a remote machine : ssh hostname Connect to a remote system with your current username :ssh username@hostname Allows you to copy files from one computer/server to another computer/server : scp
To know which user is logged : whoami To know who recentlylogged : users
history : for monitoring commands executed by user. Service :forstart/stop/restart/status (Service httpd start,service red5 stop,…etc) Top : to monitor system activities df - to know disk file space on machine (df –hsize in GB,df –msizein MB ) fdisk –l- todisplay with partitions Netstat : give information about network connections (nestat –tcpdisplay all tcp connections) Mount – for mounting formatted partitions
Basic Network Commands :
Netstat :to look up the various active connections within a computer Traceroute : to know the number hop it travelled to reach destination. Nslookup:It is use for DNS quiery. Dig : It is use for DNS quiery.It display full info. Ifconfig:It is very useful in determining what could be wrong with a network.to know IP address. Ifup:enable interface Ifdown : disable interface. Ping :PING is used to check for a response from another computer on the network. Ping-c:Host address
What command used to check Disk Space ?
1 Command to know disk space:df 2 Command to know size in GB:df -h 3 Command to know size in MB: df -m
How to change the Ownership of file/Group?
ls -lart tmpfile -rw-r--r-- 1 himanshu family 0 2012-05-22 20:03 tmpfile
Before using command :
Command to change Ownership of file:chownroottmpfile
Command to change Ownership of group : chgrpfriends tmpfile