Unix Commands
Unix Commands
Unix Commands
Eg : mkdir dir1
Lets say you want to create more than one directory instead of invoking mkdir multiple(three) times-
like.
Eg :
mkdir dir2
mkdir dir2/dir3
mkdir dir2/dir3/dir4
3. cd : Change Directory
Eg : cd dir2
date +%d/%m/%y
All data in Unix is organized into files. All files are organized into directories. These directories are
organized into a tree-like structure called the filesystem.
Eg :
ls -a ist all files including hidden file starting with '.' (Hidden Files)
ls -lrt
We use * to match 0 or more characters, a question mark (?) matches with a single character.
ls file* -- Displays all the files, the names of which start with file
ls *.txt -- display all the files ending with just .txt
Eg : wc file_name
wc filename1 filename2 filename3 -- can give multiple files and get information about those files at
a time.
wc -l state.txt prints the number of lines present in a file
wc -l state.txt capital.txt With more than one file name
wc -L demo_file to find the length of longest line in the file
Eg: mv filename newfile -- will rename the existing file filename to newfile.
To set the read and write permission for other users, execute the below command: chmod o+w *.txt
To Remove thre write permission for other users, execute the below command : chmod o-w *.txt
15: Sending Email : mail [-s subject] [-c cc-addr] [-b bcc-addr] to-addr
18 : man: (Manual) - Interface for working with the online reference manuals. (HELP)
$ man cat
19. find: Used to search for files and directories as mentioned in the ‘expression’
Eg :
$ find -- List all files found in the current directory and its hierarchy
$find . -name cust.dat -- Find all the files whose name is cust.dat from all directories(.)
$find /root/infa_shared/SrcFiles -iname File1.dat -- Find all the files whose name is file1.dat and
contains both capital and small letters in /root/infa_shared/SrcFiles directory.
find / -type d -name dir10 -- Find all directories whose name is dir10 in / (root) directory.
find . -type f -empty -- Find all the Empty Files in all directories
du -sh * - summary of directories (-s) in human-readable format (-h : Byte, Kilobyte, Megabyte,
Gigabyte, Terabyte and Petabyte):
https://www.geeksforgeeks.org/du-command-linux-examples/
21: df: (disk free) Show number of free blocks for mounted file system
https://www.geeksforgeeks.org/df-command-in-linux-with-examples/
grep: Find lines in stdin that match a pattern and print them to stdout.
sort: Sort the lines in stdin, and print the result to stdout.
uniq: Read from stdin and print unique (that are different from the adjacent line) to stdout.
cat: Read lines from stdin (and more files), and concatenate them to stdout.
more: Read lines from stdin, and provide a paginated view to stdout.
cut: Cut specified byte, character or field from each line of stdin and print to stdout.
paste: Read lines from stdin (and more files), and paste them together line-by-line to stdout.
head: Read the first few lines from stdin (and more files) and print them to stdout.
tail: Read the last few lines from stdin (and more files) and print them to stdout.
wc: Read from stdin, and print the number of newlines, words, and bytes to stdout.
tr: Translate or delete characters read from stdin and print to stdout.
22 . grep Command -- search for string in the file. – it will show all the lines which contains the
string.
Eg :
grep "this" demo_file -- Search for the given string in a single file
grep "this" demo_* -- Checking for the given string in multiple files.
grep -i "this" demo_file -- Case insensitive search using grep -i ’ (Both upper and lower case)
(look for the string “this” in all the files in the current directory and all it’s subdirectory.)
grep -l this demo_* -- Display only the file names which matches the given pattern using grep -l
grep -n "this" demo_file -- Show line number while displaying the output using grep -n
grep “[a-e]” file1 -- Match all lines that contain any of the letters ‘a’, ‘b’, ‘c’, ‘d’ or ‘e’.
grep “[^aeiou]” file1 -- Match all lines that do not contain a vowel
grep “^hello” file1 -- Match all lines that start with ‘hello’. E.g: “hello there”
grep “done$” file1 -- Match all lines that end with ‘done’. E.g: “well done”
$ -- ending
https://www.geeksforgeeks.org/grep-command-in-unixlinux/
Assume the below initial contents of file1.txt for the following examples
01 Priya
04 Shreya
03 Tuhina
02 Tushar
02 Tushar
03Tuhina
04 Shreya
04 Shreya
03Tuhina
02 Tushar
01 Priya
01 Priya
04 Shreya
03 Tuhina
02 Tushar
24) uniq : command line utility that reports or filters out the repeated lines in a file.
Eg :
uniq kt.txt
uniq -c kt.txt -- It tells the number of times a line was repeated. (count)
uniq -d kt.txt -- It only prints the repeated lines. ( -d dupliacate)
uniq -u kt.txt -- only show lines that are not repeated ( unique)
sort file.txt | uniq -u | cat file.txt -- remove and display the
contents of the file
https://www.cyberciti.biz/faq/unix-linux-shell-removing-duplicate-lines/
25) head Command : head by default, prints the first 10 lines of each FILE to
standard output
https://www.geeksforgeeks.org/head-command-linux-examples/
26) tail Command : tail by default last 10 lines of each FILE to standard
output
https://www.geeksforgeeks.org/tail-command-linux-examples/
head -10 filename | tail -1 filename -- to display 10th line of the file
27) diff commad : This command is used to display the differences in the
files by comparing the files line by line. (Compare two or more files)
$cat greekfile | tr “[A-Z]” “[a-z]” --convert upper case to lower case
https://www.geeksforgeeks.org/tr-command-in-unix-linux-with-examples/
29) cut command : which is used to extract sections from each line of input
Eg : cut -c 2,5,7 state.txt -- command prints second, fifth and seventh character from each
line of the file.
https://www.geeksforgeeks.org/cut-command-linux-examples/
30) zip command : a command-line utility that helps you create Zip archives.
32) echo command : used to display line of text/string that are passed as an argument
https://linuxize.com/post/echo-command-in-linux-with-examples/
https://www.geeksforgeeks.org/rev-command-in-linux-with-examples/
34 ) sed command (stream Editor) : it can perform lot’s of function on file like, searching, find and
replace, insertion or deletion.
Eg : sed 's/unix/linux/' geekfile.txt -- replaces the word “unix” with “linux” in the file.
https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/
Awk is a scripting language used for manipulating data and generating reports.The awk command
programming language requires no compiling, and allows the user to use variables, numeric functions,
string functions, and logical operators.
1. AWK Operations:
2. Useful For:
3. Programming Constructs:
eg : awk '{print}' employee.txt -- prints every line of data from the specified file.
awk '/manager/ {print}' employee.txt -- prints all the line which matches with the
‘manager’.
https://www.geeksforgeeks.org/awk-command-unixlinux-examples/
36) history command : to give the enitre history of the comamnds which we have used.
Hisotry>a.txt
https://www.guru99.com/the-vi-editor.html
https://blogs.perficient.com/2013/07/30/informatica-removing-duplicate-source-records/
https://ramareddydcp.wordpress.com/2017/04/23/how-many-ways-we-can-eliminate-duplicate-
records-by-using-informatica-mapping-explain-with-an-example/
https://learn-develop-informatica.blogspot.com/2015/09/unix-commands.html
http://dwhlaureate.blogspot.com/2013/11/informatica-session-components-tab-pre.html
https://www.folkstalk.com/2011/11/top-unix-interview-questions-part-1.html
https://informaticareference.wordpress.com/category/oracle-interview-questions/
https://informaticareference.wordpress.com/category/oracle-interview-questions/page/12/