Basic and some Advance Command in Unix
Hello Everyone,
In my Previous Blog we discussed about some basic command of Unix which is commonly used. Today I will discuss more about some more important command which is commonly used. Before starting new commands please go through my previous blog for your reference.
https://dheeraj60.blogspot.com/2020/08/basic-and-commonly-used-command-in-unix.html
Control Command in Unix : In Unix we have some key command through which we can terminate as well as command can run in background. Below are the key command and it’s uses in terminal.
Control-C: Command terminates the currently running foreground process.
Control-D: Command terminates the currently running login or terminal session.
Control-Z: Command suspends the currently running foreground process to the background.
To see the process by using ps –ef command : This command shows every process running , and result shows with PID.
I am running this command in Putty terminal and it will show all the process running in the system . Command is as below
$ ps –ef
Another command which is very popular is top command in unix which displays a live status of current processes
Below is the output of both command in Putty Terminal .
Since there is no process is running so command ps-ef given the PID of our command only but top command displays live status of current process.
Now if you are in your Home directory and want to go in root directory from home we can use simply below command to move into root directory.
$ cd /
Below is the output in Putty Terminal of above command .
Now you can see that we are in root directory .
To clear the screen we need clear command in Unix which will clear all the commands and output from the current screen.
$ clear
History Command in Unix : History command used to print history of the current session.
$ history
It will show all the command issued in the system session . Below is the output for your reference.
Find command : Used to search for files and directories as mentioned in the expression . The find command in UNIX is a command line utility for walking a file hierarchy. It can be used to find files and directories and perform subsequent operations on them.
Basic Uses of Find Command
Find all the files whose name is dheeraj.txt in a current working directory.
find . -name dheeraj.txt
Find all the files under /home directory with name dheeraj.txt
find /home -name dheeraj.txt
Find all the files whose name is dheeraj.txt and contains both capital and small letters in /home directory
find /home -iname dheeraj.txt
Find all directories whose name is DOTC in / (root) directory.
find / -type d -name DOTC
Find all sql files whose name is categories.sql in a current working directory.
find . -type f -name categories.sql
Please see output of all the above 5 Find command carefully in Putty Terminal.
Find all the files whose permissions are 777 . Below is the command to check .
find . -type f -perm 0777 –print
Find the files whose permission is not 777 we can use below command
find / -type f ! -perm 777
Below is the output in Putty terminal of both the find command in upper side you can able to see most of the files whose permission is not 777 and in last I used first command to see permission files only.
Find and Remove single files we can use below command
find . -type f -name "dheeraj.txt" -exec rm -f {} \;
Here dheeraj .txt files removed after executing above command .
Below is the output of above command in Putty Terminal
To find and remove multiple files such as .sql or .txt, then use below command.
find . -type f -name "*.txt" -exec rm -f {} \;
find . -type f -name "*.sql" -exec rm -f {} \;
Note : Please don't use above command if you are working on any project just think before issuing this command . Also through Root we can use find command and find and remove any types of file .
In find command we have so many commands . so you can use man command to see all the options of man command .
Man command in unix : This command is very useful as it Interface for working with the online reference manuals. If we want to know more about any command we can use man command to see all the useful tips through man command . Suppose I want to issue below command
$ man –f find
$ man find
To check the disk space in Unix we use below command to see the disk usage.
$ df –h -- To see the diskspace in GB
$ df –k – To see the diskspace in KB
Below is the output of above command in Putty Terminal for your understanding.
Other command to check disk usage:
du: du command estimate disk usage is blocks
df: df command show number of free blocks for mounted file system.
Note : Still So many commands in Unix needs to be discussed as in Unix tons of command is available .
Please go through this blog carefully and ask me if you have any questions . In next blog I will again come up with advance unix commands like shed , grep and more advance command used in Unix and will try to write some basic shell script as well.
Thanks .
Very useful command Sir !
ReplyDeleteIt is very useful for me. Thanks...
ReplyDeleteAzure Data Factory Online Training
Azure Data Factory Live Online Training