To List The Files/directory
To List The Files/directory
ls ltr This will give the list in reverse order of time. That time the file/directory creation time. The recent created file will come at last. 3. ls a will give the list of hidden files. To open any File: 1. cat <filename> : This command throws the content of file to the output screen. This command never change the content of file. 2. more <filename> : more is a command to view (but not modify) the contents of a text file one screen at a time (terminal pager). 3. vi <filename> : This command opens the file on vi editor where we can view/modify the content of file. To quit the editor mode we write :q! -this will undo the changes in file if we made any and close the editior. :wq! -this will write the change in file if we made any and close the editior. :w! this will only write the changes in file but doesnt close the editor. 4. view <filename> : This command also opens the file on vi editor where we can not modify the content of file. To search and replace the content of file: Suppose there is a file temp.txt and there are following fields in file1,RAM,AGRA,283105 2,SHAYAM,JAUNPUR,221222 3,SHEELA,KANPUR,2111222
Or we can writesed 's/RAM/SEETA'/g temp.txt Output :1,SEETA,AGRA,283105 2,SHAYAM,JAUNPUR,221222 3,SHEELA,KANPUR,2111222 But above sed command never replace the original content of file with new word SEETA. It only throws the output to the screen. If we want to replace the original file also with new replaced word. Then we need to write 3. sed -i 's/RAM/SEETA'/g temp.txt -i will replace the original file. To Delete any word from file: sed '/yourword/d' yourfile To delete all instances of the word "yourword": sed 's/yourword//g' yourfile
To delete two words from a file simultaneously: sed -e 's/firstword//g' -e 's/secondword//g' yourfile if we want to delete AGRA and KANPUR from file temp.txt then we will write: sed -e 's/AGRA//g' -e 's/KANPUR//g' temp.txt Output:1,RAM,,283105 2,SHAYAM,JAUNPUR,221222 3,SHEELA,,2111222 -e is used to pass multiple expression in a single sed command.
AWK COMMAND The AWK utility is a data extraction and filter tool that can be apply at any files/variables. Syntax: awk condition { action } Examples: If we want to print only Names from temp.txt file, then we will write:
awk -F',' '{ print $2 }' temp.txt Output: RAM SHAYAM SHEELA -F use for field separator. Here our file is comma separated so we write F, after the awk (There is a space between awk and F). The action tag start when we write something inside { } here we print the second column of the file(name). $2 denote the second column in the file. If we want to print all fields but saperated with PIPE(|) from temp.txt file, then we will write: awk -F',' '{ print $1"|"$2"|"$3"|"$4 }' temp.txt Output:1|RAM|AGRA|283105 2|SHAYAM|JAUNPUR|221222 3|SHEELA|KANPUR|2111222 If we want to print the no of columns in temp.txt file, then we will write awk -F',' '{ print NF }' temp.txt Output :4 4 4 Above Output means that there are four column in each row. If we want to print the no of Rows in temp.txt file, then we will write awk -F',' '{ print NR }' temp.txt | tail -1 Output :3 Or we can write: cat temp.txt | wc l Output :3 Sort , head , tail , rm , rmdir , mkdir , ls -R , ps ef , nohup , sh , if else , while , for , echo Echo echo Kuldeep will print kuldeep Variable access and creation VAR1=Kuldeep Will assign kuldeep in VAR1 Echo $VAR1 will print kuldeep fro VAR1
Head If u want to print fisrt few record from a file Head -100 file1 Will print first 100 record from file1 Tail Tail -100 file1 Will print last 100 record from file1 Rm Rm filename Will remove a file from current dirctory ( removed file name will be filename) Rm f Rm f filname1 Will remove forcefully file filename1 Rm rf Rm rf dir1 Will remove dir1 directory along with all child files and directory Rmdir Rmdir dir1 Will remove empty directory dir1 Mkdir Mkdir dir1 Will create a new directiory in current path with name dir1 Mkdir p Mkdir p kuleep/himanshu/ashutosh Will create the complete directory structure Ls R Will recursively list all file and files from subdirectiory Ps ef Will list all the process with process id and parent process id from all the user running in the server Sh Used to execute the script Sh scriptname.sh Will execute script scriptname.sh in foreground Sh scriptname.sh & Will execute scriptname in background
Sh x scriptname Will run the script in debug mode and will show all the command s executing Nohup Nohup sh scriptname & Will run the script scriptname in background and this script will be running even u close the session Kill Kill <process_id> Will kill process with pid proccess_id CTRL + C Will kill current foregound process or script Jobs Will show all the background process running from that session only Pwd -==== will print current directory path cd change directory cd .. for changing directiory to parent directory cd ~ to change directiory to home directiory cd to change directory to previous directory like < alt + tab > alias
soft name of any command for e. alias mcdr1.2='cd /streams/home/kn084196 will create a alisas mcdr1.2 so if u execute mcdr1.2 then it will execute cd /streams/home/kn084196