Linux – wc

Linux wc command The Linux wc command is used to count the number of lines, words, and byte (character) in a file or input stream. Syntax: wc [OPITON] [FILE} Example: Use -l to count the number of lines in a file wc -l myfile.txt Use -w to count the number of words in a file wc -w myfile.txt Use -c to count the number of bytes in a file. You can use this to count character in a file wc -c myfile.txt Use wc with Piped Input You can also…

Read More

Linux – grep

Linux grep command The Linux grep command stands for “Global Regular Expression Print“. The grep command-line utility is used for searching content from files based on a pattern or regular expression. Synatx: grep “PATTERN” [FILE] Example: Search all users under /etc/passwd have the bash shell. grep “bash” /etc/passwd Grep command can also take the output of another command as input using pipes. For example: cat /etc/passwd | grep “bash” Case Sensitive Search Grep uses -i option to run a case-sensitive search. grep -i “SearchPattern” filename Search Recursively in Directory Tree…

Read More

Linux – cut

Linux cut command The Linux cut command is a text processing command. This command is used to extract the specific column from a file. You need to define the column number and column delimiter with command. Syntax: cut -d<delemeter> -f<field1,field2,…> filename -d This defines the deleter as coloumn seprator. Defaut column seprater is single space or tab. -f Specify fields (column numbers) to fetch. Example Grep all usernames with there home directory created on a Linux system. The /etc/passwd file contained all users on a Linux system with other details.…

Read More

Linux – cd

Linux cd command The cd command stands for “change directory”. This command is used to leave current directory and navigate to another directory on the system. Syntax: cd <Path to new dir> Change to a New Directory After login to the system, the user gets the home directory. Now you can navigate to another directory for example /home/rahul/Workspace where my present directory is /home/rahul cd Workspace Use pwd to check your present working directory. pwd /home/rahul/Workspace There are two ways to navigate between directories is the absolute path and relative…

Read More

Linux – tee

Linux tee command The Linux tee command is used to route output data to multiple outputs. Tee can display output on STDOUT as well ass write to file at a time. Example The following command will display list of files in current directory on screen as well as write in list.txt file. ls | tee list.txt Append Data to File The default tee overwrites the file content. You can use -a to append data to file. ls | tee –a list.txt Write data to Multiple File You can also write…

Read More

Linux – chattr

Linux chattr command The chattr command change file attributes on a Linux file system. It provides a higher level of security on files and directories. You can also use this security to prevent important files from accidental deletion. Syntax: chattr [ -RVf ] [ -v version ] [ mode ] files… You can add any attribute to file using + symbol or use – symbol to remove the attribute from the file. Make File/Directory immutable Use +i option with chattr on file to make file unchangeable, This will not allow…

Read More