Advance Unix Command Part 2.
Hello Everyone,
In my Previous blogs I already discussed about several commands which commonly used in Unix . Today I will discuss some more command which commonly used in Unix . Before starting new commands I will suggest you to please go through my below blogs for Unix command .
https://dheeraj60.blogspot.com/2020/08/advance-unix-command-part1-dotcmdb.html
https://dheeraj60.blogspot.com/2020/08/basic-and-some-advance-command-in-unix.html
https://dheeraj60.blogspot.com/2020/08/basic-and-commonly-used-command-in-unix.html
Let’s start with Unix command :
Connect to a remote mysql database. Below is the command to connect remote mysql database as well as local mysql database.
Note : You should first now the host name to connect mysql database as well as password.
$ mysql -u u255474504_root -p -h 127.0.0.1
Connect to a local mysql database.
$ mysql -u u255474504_root –p
Below is the output of above command in putty Terminal.
For this we use passwd command . First it will prompt for the old password followed by the new password and after entering the new password you will see message as all authentication tokens updated successfully. Command is as below.
$ passwd
Note : Super user can use passwd command to reset others password. But this will not prompt for current password of the user. Command for this is as below .
$ passwd USERNAME
See the output of above command in Putty Terminal . I haven’t used the second command as i don’t need to reset other user password.
Less command is very efficient while seeing large files, as it doesn’t need to load the full file while opening, but once you use less command two commands/Keys are very useful
1. CTRL+F – forward one window
2. CTRL+B – backward one window
less command to to see large file is as below
$ less dheeraj2.txt
Below is the output in putty terminal .
Command that will output the sorted contents of a file dheeraj2.TXT and place the output in another file with same content name OUT.TXT, below is the command for this.
sort dheeraj2.TXT | uniq > OUT.TXT
Output of the above command is as below in Putty Terminal:
Command that will allow a UNIX system to shut down in 10 minutes, after which it will perform a reboot. Below is the command.
/sbin/shutdown –r +10
Note: I am not issuing this command in my terminal now.
How to zip and unzip the file in Unix .
Here we zip dheeraj2.txt file and unzip the same file . Below is the command to zip and unzip file in unix.
$ gzip dheeraj2.txt
To zip the file
$ gunzip dheeraj2.txt
To unzip the file
Below is the output in Putty Terminal for above commands.
cut command mainly used to extracts a given number of characters or columns from a file . Extract characters 5 to 10 from each line from text dheeraj2.txt we use below cut command in unix .
$ cut -c 5-10 dheeraj2.txt
Below is the output of above command in putty terminal.
Creating one text file table.txt through which I use cut command I will display 1st value of position 3 in column for all 5 records by using below cut command and create table .txt file.
Creating table .txt command by using cat command
cat > table.txt
emp_id;emp_name;salary
101;Ashish;20000
102;Krishna;15000
103;Prashant;25000
104;Deepak;22000
Cut command to display records for particular 3rdposition for all the 5 records in table.txt file.
$ cut -c 3 table.txt
Below is the output of above command in putty terminal.
Using Cut command if you want to see starting position from name to destination as per your need from text file table.txt use the below command.
$ cut -c 1-22 table.txt
Below is the output of above command in putty terminal.
Please go through this blog carefully and also my previous blogs related to Unix as this commands are very important if you are working in Unix environment and also if you are preparing for interview. Please let me know if you have any questions on this. In next blog I will come up with more Unix command and some basic idea about shell scripting.
Thanks.
It is very useful for me. Thanks...
ReplyDeleteAzure Data Factory Online Training
Azure Data Factory Live Online Training