Sunday, March 18, 2012

12 day to day useful Ubuntu commands*


These are day to day useful Ubuntu commands. Hope they are of any use in you day to day lives..:).

These commands should be working fine on Ubuntu 10.04, 11.04.

1. To search for a previously typed command:-

Form: history | grep command_name

E.g:- history | grep redis-server

Sample Output:-

 1632  redis-server
 1636  redis-server
 1638  sudo apt-get remove redis-server
 1658  redis-server
 1661  redis-server
 1662  redis-server &
 1872  redis-server
 1873  ps aux|grep redis-server
 1874  redis-server &
 1891  ps aux|grep redis-server
 1913  redis-server &
 1991  redis-server
 1992  redis-server &
 2038  history redis-server | grep
 2039  history | grep redis-server

2. To view particular file permissions of file(s) in a particular directory

Form: ls -l

Sample Output:-

-rwxr-xr-x 1 mohnish mohnish  84461758 2010-12-19 13:22 jdk-6u23-linux-i586.bin
-rwxr-xr-x 1 mohnish mohnish  21388070 2010-12-19 11:17 jre-6u23-linux-i586.bin
-rw-r--r-- 1 mohnish mohnish     86242 2011-02-19 16:19 nautilus-dropbox_0.6.7_i386.deb
-rwxr-xr-x 1 mohnish mohnish 278520832 2010-12-19 09:12
-rwxr-xr-x 1 mohnish mohnish  91764736 2011-03-02 23:34
-rw-r--r-- 1 mohnish mohnish  91581668 2011-03-03 06:24
-rw-r--r-- 1 mohnish mohnish   4873383 2011-01-06 21:17 ruby-1.8.7-p330.tar.gz
-rw-r--r-- 1 mohnish mohnish    292302 2011-02-24 07:05 rubygems-1.5.0.tgz

3. To view a running process wrt a particular name

Form: ps aux | grep process_name

A running process could be a running server etc.

E.g. ps aux | grep redis

Sample Output:-

mohnish@mohnish-laptop:~latest$ ps aux | grep redis
mohnish   2897  0.0  0.0  26976  1552 ?        Sl   13:22   0:02 redis-server
mohnish  18342  0.0  0.0   3332   876 pts/4    S+   14:39   0:00 grep --color=auto redis

4. To Kill a process

Form: kill -9 process_id

E.g. : kill -9 2897

5. Present Working Directory(pwd)

Form: pwd

E.g.:- mohnish@mohnish-laptop:~$ pwd

6. Use of Ctrl + R to search

Form:- [Keyboard Press] Ctrl + R (Followed by) [ Type the keyword you want to search]

E.g. : Ctrl + R (followed by sc) , returns:- (reverse-i-search)`sc': ./script/server

7. Power Off and Reboot via Terminal

Poweroff:- sudo poweroff

Reboot:- sudo reboot

8. Cache(Searching for a package wrt  Repositories), Install and Remove packages from your terminal

a. Cache

Form:- sudo apt-cache search package_name

E.g. sudo apt-cache search pidgin

Sample Output:-

b. Install

Form:- sudo apt-get install package_name

E.g. sudo apt-get install pidgin-sipe

c. Remove

Form:- sudo apt-get remove package_name

E.g. sudo apt-get remove pidgin-sipe

d. Update

Form/Command: sudo apt-get update

9. Clear Terminal screen shortcut

Scenario: When you terminal is overly crowded with stuff

Command:- Ctrl + L
(This even clears your mysql screen :))

10. Exiting your terminal

Command:- exit

11. Changing your pwd and listing contents in new directory

a. To change directory(cd)

Form:- cd directory_name

b. To list contents of pwd

Form:- ls

Eg. for a. and b.

mohnish@mohnish-laptop:~$ cd sample_pics/
mohnish@mohnish-laptop:~/sample_pics$ ls
16-4-2008-a.jpg  28-10-08-a.jpg  Blue hills.jpg     Desert.jpg      Jellyfish.jpg  kwp-full.jpg    Penguins.jpg  Tulips.jpg       Water lilies.jpg
17-5-2008-a.jpg  8-5-2008-a.jpg  Chrysanthemum.jpg  Hydrangeas.jpg  Koala.jpg      Lighthouse.jpg  Sunset.jpg    Wallpaper-1.jpg  Winter.jpg

12. Locking Your Ubuntu Desktop( a functionality similar to Windows + l)

When you are at leisure :), feel free to leave you desktop soon after the below

Command: Alt + Ctrl + l

[A special note: Using tabs to navigate with ease] :-

The use of tab in cd and in other terminal related commands like ls etc., is vital , as it saves you time from typing the entire directory_name/file_name etc., Please find below a sample use of tab while navigating your way inside the contents of a directory you would like to use:-

mohnish@mohnish-laptop:~$ cd m
me/               myforum/          myforum_unzipped/

The above shows up as soon as you press a tab, after you type "m" matching all directories starting with the letter "m".


I have learnt few of the above from my seniors at office, apart from other learning experiences. I am grateful to them for the same..

No comments:

Post a Comment