Top Linux Commands | Linux Interview | Production Support Interview - Interview Help - Top Interview Questions

Latest

Interview Help - Top Interview Questions

Top Interview Questions and Tips for a good Interview

Thursday, August 13, 2020

Top Linux Commands | Linux Interview | Production Support Interview

Linux commands:


ls     -------------  to list the files in a directory

ls –l  --------------  long list

ls –lrthaS

l----------- long list

r—--------sort in reverse order

t-----------sort by time

h---------- view size in human readable format

a---------- to list/view hidden files

S----------- sort by size 



cd ---------------- change directory

cd .. (goes one directory backward)

cd / (goes to root directory)

cd (goes to home directory)



Alias Converts complex commands into simpler one.


cat   -----------The 'cat' command is the most universal and powerful tool. It is considered to be one of the most frequently used commands. It can be used to display the content of a file, copy content from one file to another, concatenate the contents of multiple files, display the line number, display $ at the end of the line, etc.

Option Function

cat > [fileName] To create a file.

cat [oldfile] > [newfile] To copy content from older to new file.

cat [file1 file2 and so on] > [new file name] To concatenate contents of multiple files into one.

cat -n/cat -b [fileName] To display line numbers.

cat -e [fileName] To display $ character at the end of each line.

cat [fileName] <<EOF Used as page end marker.


Clear Clears the terminal.


comm Compares two streams or files.


cp Copies file content from one file to other file.


date Displays current date.


df Checks the disk space in system.


Echo Prints the typed word on terminal.


Chmod Changes permission for a file or directory.


find Finds files for a particular search.


grep Filters lines of text containing a certain string.


gzip / gunzip Compresses a file / Decompress a gzip file.


head Displays first ten lines of a file.


The 'head -n' option displays specified number of lines.

The 'head -c' command counts the number of bytes of a file.

tail Displays last ten lines of a file.


tee Puts stdin on stdout and then into a file.


The 'tee' command is similar to 'cat' command with only one difference. It puts stdin on stdout and also put them into a file.

Syntax:

cat or tac <fileName> | tee <newFile> 



History Displays older commands from shell command history.


less Displays file content according to the width of the terminal.


less <file name>  


more Displays one output screen at a time.



mkdir Creates directory.

Syntax:

mkdir <dirname>  

Example: mkdir abc


mv Move directory or files or Renames directories or files if used within same directory


rm Removes a file.


rmdir Removes a directory.


su Allows a user to run as another user.


vi Opens vi editor to write a program.


Who Tells who is logged on the system.


Whoami Tells the name of the user.


who am i Displays the line pointing to your current session.


zcat / zmore Views the files compressed with gzip.


wc Counts words, lines and characters.


Syntax:

wc <fileName>     (Counts words, lines and characters)  

wc -l <fileName>      (Counts only lines)  

wc -w <fileName>      (Counts only words)  

wc -c <fileName>      (Counts only characters)  


Linux grep

The grep command filters the content of a file which makes our search easy.

grep with pipe

The 'grep' command is generally used with pipe (|).

Syntax:

command | grep <searchWord>  

Example:

cat marks.txt | grep 9  

 

grep without pipe

It can be used without pipe also.

Syntax:

grep <searchWord> <file name>  

Example:

grep 9 marks.txt  

 

grep options

grep -v: The 'grep -v' command displays lines not matching to the specified word.

Syntax:

grep -v <searchWord> <fileName>  

Example:

grep -v 9 marks.txt  


grep -i: The 'grep -i' command filters output in a case-insensitive way.

Syntax:

grep -i <searchWord> <fileName>  

Example:

grep -i red exm.txt  

grep -A/ grep -B/ grep -C

grep -A command is used to display the line after the result.

grep -B command is used to display the line before the result.

grep -C command is used to display the line after and line before the result.

You can use (A1, A2, A3.....)(B1, B2, B3....)(C1, C2, C3....) to display any number of lines.

Syntax:

grep -A<lineNumber> <searchWord> <fileName>  

grep -B<lineNumber> <searchWord> <fileName>  

grep -C<lineNumber> <searchWord> <fileName>  

Example:

grep -A1 yellow exm.txt  

grep -B1 yellow exm.txt  

grep -C1 yellow exm.txt  

 


No comments:

Post a Comment