Friday 6 June 2014

Tricky tips for UNIX/LINUX shell commands

Search man pages with these commands.

Here are few commands that can come handy while searching through man Pages in linux.

$man -k ssh 

The above command will show all available commands that contain the word ssh in their description 
Also, if you would need to check short descriptios of the commands, you can use the following:

$whatis ssh

or:



$man -f ssh


ispell: A Spell check for UNIX

This is the program used to perform a very basic spell check from command line.
Here is a tip that lets you know how to use ispell.
firs, install it if it's not already installed, by running the following command:

#sudo apt-get install aspell aspell-en 

Now, to see ispell in action, run the command shown below:

#ispell <filname> <-----(in place of 'filname' enter any file you want to spell check)

You now have the option of several actions that you can take on misspelled words found in the file.
Type the number 'n' to replace the misspelled word.
Type 'R' to replace the misspelled word with a word that you wish to replace it with.
Press 'A' to ignore that misspelled word in this entire ispell session.
Press 'Q' to quit the program.
Press the space bar to ignore that misspelled word just once.
Press 'I' to ignore all the misspelled words

Find user account without passwords

Open terminal window and enter the following command, which will display all user account without passwords:

#awk -F: '($2 =="") {print}' /etc/shadow


Gaining remote access using ssh on a specific port

To connect to remote Linux system, we often use ssh, which is a program for logging into a remote machine and executing commands on it. 
By default, ssh uses port Number 22 to communicate. Here is a tip that lets you connect to the server with ssh without using the default port.

#ssh -p port-number root@host-name
  

Unmount that stubborn USB device

I often encounter a peculiar and irritating problem with pen drives and USB storage devices.
I was not able to eject/unmount these devices, and get the error message: 'The device is busy.' or 'The device is used by another program, please close the program and try again.' 
One simple solution is to run the command sync to flush out incomplete buffers, and then run:

$sudo umnount 

or:

$sudo umount /dev/sdb1


or:

$sudo umount /media/external 

There are, of course, more sophisticated methods, i will update it too as i get to know, but till then, try this simple solution first to resolve this irritating problem.



Force file system check during the next reboot

Here is a method that allows you to force a Linux-based system to run fsck command on the next boot of the system. fsck is used to check and optionally repair one or more Linux file systems.
To run this forcibly, go to the root directory and create a file named 'forcefsck' as shown below:

#cd /

#touch forcefsck

The file forcefsck will be deleted automatically after fsck is finished.
This will only run the full file system check on the next reboot of the system.


Know your CPU

Running the following command on the terminal can give you the entire details of the CPU being used in your system:

#lscpu

Access the Windows desktop

There is a powerful utility (command) on Linux to access the remote desktop of any Windows system. the rdesktop is found already installed in many Debian- based systems. 
If not, it can be installed by running the following command:

$sudo apt-get install rdesktop

It uses Remote Desktop protocol (RDP) for remote access. in order to access any windows Desktop, go to the terminal and type following command :

rdesktop ip-address -u username -p password

For example:

$rdesktop 172.16.1.1 -u ajinta -p AUrAngAbAd

It will log on to the Windows system in the network that has the following IP address: 172.16.1.1, with the username ajinta and password AUrAngAbAd. It will show the Windows desktop of this system. Now, you can operate this Windows system from your Linux system!



Installing .bin files in Linux 

We often download software as an execute file with the extension .bin and then do not know how to install it. here are a few steps that will let you run the .bin file in Linux.
First, change the file mode bits of the downloaded .bin file using the following command:

$cd /path/to/your/bin
$sudo chmod a+x <yourbinfile>.bin

Now run the executable by using./

$./<yourbinfile>.bin



Delete specific command from History

Use the 'up' arrow to browse through the history of commands that have been used in terminal and go to the command you want to delete. 
For example:

#cat /etc/passwd

Now press Ctrl+u
This will delete the selected command for History.  
To check if it is deleted or not, run the following command:

#history

The output of the above command will show a blank with the * symbol in the place of the deleted command.



Finding the biggest files in Linux 

Here is a command that will help you find the biggest files in the current directory:

$ls -lSrh

The 'r' cause the large files to be listed at the end, and the 'h' gives human readable output.

Thank you for reading i will post more of these command in my next post.....
------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment