In this Post, We will discuss most frequently asked UNIX Commands Interview Questions.
Table of Contents
Common Commands:
- Pwd – Present working directory.
- clear – clear the screen.
- ls – listing of the files.
- ls -l – Listing of the files with numbers.
Folder Commands:
- mkdir dirName – To create the directory
- mkdir -v dirName – To create the directory with verbose message.
- ./.. — two folder back.
- mv oldDirName newDirName —- Rename the file
- rmdir -v DirName – removing file.
Working with directory:
mkdir Hello{1..10} – it will create 10 folder Hello1, Hello2……Hello10
rmdir Hello* — Remove folder which start from Hello name.
Create File using Commands:
touch filename – Create a blank file
cat > filename [Press Enter] —– Enter data inside the file.
data…. [Enter]
Press Ctrl+C
Check the details: – ls -l
Display files in folder: – Use of ls command)
- ls -l
- ls -la – also show hidden file.
- ls -lat – Files showing in sorted order of creation. [l for listing order, a for all and t for sorted in time.]
- ls -t – Display in sorted order of time.
- ls -latr – display in reverse order of time.
UNIX Commands Interview Questions of CAT command: –
- cat Filename – Display content of the file.
- cat -n filename – display content of file with line number.
- cat old filename > new Filename – where u want to copy content of old file. [This will delete the previous data of new file in which u want to copy content]
- cat oldfilename >> new file name – copy data in append
- cat file1 file2 > file3 – merge multiple file data into new a file.
- tac filename – show reverse order of content in file.
View Content of File: –
- Display few lines from the top of the file (default 10) – head file name
- Control lines what you line want to print – head 20 fileName
- Display bottom lines – tail filename
Search Data in File – Grep (Global regular expression parser) Command
grep “Content” filename
Search data in more than one file: –
Grep “Content” fileName1 fileName2
Search data in all files: –
Grep “Content” *.*
Search data by ignoring case: –
grep -I Content *
Use of Cat Commands:
Creating the new file
Display content of the file
Concatenating more than one file
Appending data to the existing file
Use of cp Command:
Copy contents from a file to another file(source to destination)
Use of mv Command:
Renaming a file(changing name of the file)
Renaming a directory
Moves files from one directory to another directory
Use of rm Command :
Delete/remove a file or directory (only if directory is empty).
Must Read:
WebServices Interview Questions