1.If you mess up with boot-loader and during installation it complaining about UUID you can fixed it with blkid
blkid - command-line utility to locate/print block device attributes
output from my machine
/dev/sda1: UUID="B0FC1625FC15E67E" LABEL="disk[sda1]" TYPE="ntfs"
/dev/sda2: UUID="50B207AAB207941E" LABEL="disk[sda2]" TYPE="ntfs"
/dev/sda4: UUID="420E5E570E5E4457" LABEL="disk[sda4]" TYPE="ntfs"
/dev/sda5: TYPE="swap" UUID="a906cb1b-a3ac-4738-9980-f6470af45659"
/dev/sda6: LABEL="disk[sda6]" UUID="7a5ac338-5d55-46b2-bd35-d07fafa38421" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda7: UUID="fb55ad63-7c40-4d26-8428-ec2ad4790f6e" TYPE="ext3"
/dev/sda8: UUID="1f10cf9e-9b2e-448f-ac8b-a9b8481cf349" SEC_TYPE="ext2" TYPE="ext3"
2.If you delete some file from command line accidentally (if you delete from command line it deleted permanently) and want to recover you need the foremost package.
You can install it by
#apt-get install foremost
foremost - Recover files using their headers, footers, and data structures
After installing run
#foremost -t filetype-i /dev/sda1
3. If you want to shutdown your pc at particular time say 11:30 pm then issue the following command
#shutdown -h 23:30
4.If you mess-up with grub and want to recover then boot from ubuntu live cd. Open terminal and run
$sudo grub
grub> find /boot/grub/stage1
(hd0,5)
(hd0,6)
grub>root (hd0,n)
grub>setup (hd0)
grub>quit
$sudo reboot
###here n is the partition no from where you want to recover grub
5.Set Date and time through command line
$sudo date 020212312009
It will set the date and time to Mon Feb 2 12:31:00 IST 2009
6.Print through Command line
$lp filename
7.Quickly Find a PID with pgrep
pgrep looks through the currently running processes and lists the process IDs which matches the selection criteria.
pgrep firefox
- This will list all PIDs associated with the firefox process.
8.Execute The Last Executed Command
!!
This will execute the last command you used on the command line.
Isn't the UP arrow for that?
The !! command is very useful when you forget to start a command with sudo :
apt-get update
sudo !!
9.Execute The Last Command Starting With ...
If you want to execute a command from history starting with the letter S you can use the following:
!s
- This will execute the last command used on the command line that started with s.
10.Last Argument
You can use the last argument from the last command by refering to it as $_
so you only need to type a long path like this once:
cp assignment.htm /home/phill/reports/2008/
cd $_
to go straight to the 2008 folder as well.
You can use this however you like. Always the last argument of the command above.
Like using $_ for the last argument of the last command, you can also hit ALT+. to quickly paste it at the cursor.
11.Run a Command Repeatedly and Display the Output
watch runs a command repeatedly, displaying its output. This allows you to watch the program output change over time. By default, the program is run every 2 seconds. watch is very similar to tail.
watch -d ls -l
- This will watch the current directory for any file changes and highlight the change when it occurs.
12.Save Quickly in VI/VIM
Save and quit the file you’re editing in vi by exiting insert mode, holding shift, and hitting z twice (ZZ). That is quick or not, it depends.
You can use :wq OR more easily :x
13.Quickly Log Out of a Terminal
You can quickly log out of a terminal session by using: CTRL+D
14.Navigate to the Last Directory You Were In
cd –
will take you to the last directory you were in.
15.Make Parent Directories the Smart Way
mkdir -p /home/adam/make/all/of/these/directories/ will create all directories as needed even if they do not exist. Why waste time doing something silly like: mkdir make ; cd make ; mkdir all ; cd all ; mkdir of ; cd of … you get the point. Use mkdir -p ! This is one command I really lacked.
16.Delete the Entire Line
If you’ve just typed a long string of commands that you don’t need to enter anymore, delete the entire line by using: CTRL+U,K. That is not easy. CTRL+U deletes whatever is to the left of the cursor and CTRL+K deletes what is to the right. If you are at the end of command, CTRL+U will do. Especially if you start typing password and you make a mistake. Alternatively, you can use CTRL+C, which discards the current typed command, and gives you a new line.
CTRL+L will clear the screen.
17.Set the Time stamp of a File
touch -c -t 0801010800 filename.c will show the time stamp as 2008-01-01 8:00. The format is (YYMMDDhhmm).
18.Command to File
fc will open the last command from your shell history in the default editor. You can also specify a text editor. You can add a history line number or the first few letters of the most recent command.
fc -e kate wget
- will open kate with the last shell command starting with wget. You can edit the command, and when you save and close kate, the command will execute.
19.Ampersand
Ending a command with & runs the command with a new PID, releasing the command line back to you. Useful for running a background process.
20.Resetting your terminal-session
Instead of killing and re-starting your terminal session, you can merely type the command reset. This will reset your terminal back to its defaults, clear the screen, and everything will be as it was before.
21. Playing with packages:-
Checking package status:-
dpkg -l
Discovering package names:
#apt-cache search java
Using dpkg to find package names
#dpkg -S java
If an installation breaks in the middle of the process and you find that it's no longer possible to install or remove packages, try running these two commands:
# apt-get -f install
# dpkg --configure -a
22.Remove unnecessary packages
deborphan | xargs apt-get -y remove purge
23.Resolve "Waiting for root file system..."
When you get dropped to Busy Box prompt, type in:
modprobe ide-disk; modprobe ide-generic; cat /sys/block/hda/dev; mknod /dev/hda1 b 3 0
Then press ctrl+D, and your machine will boot!
Source:- http://ubuntuforums.org/showthread.php?t=686253
24.View total memory in a system:-
egrep "(MemTotal|SwapTotal)" /proc/meminfo
25.Fixing NTFS Mount Error in GNU/Linux
One of the common problem you might encounter while using a external hard drive (or partition) formatted with NTFS (since you multi boot or you want to use the external device with windows and gnu/linux) is that - it fails to mount occasionally giving the below error.
$LogFile indicates unclean shutdown (0, 0)
Failed to mount '/dev/disk/by-uuid/FE5C75355C74E9B3': Operation not supported
Mount is denied because NTFS is marked to be in use
The reason is because you might have probably unplugged the device directly from windows instead of going through 'Safely Remove Hardware' option and hence the NTFS log is not marked unused.
There is a tool to fix it.
sudo ntfsfix /dev/drive_name
If you receive "ntfsfix: command not found" error message, then probably the ntfs utilities are not installed in your distribution (I have figured out that the utility to manipulate nfts is installed in openSUSE by default, but not in Ubuntu 8.04). In that case, you'll need to issue the following before ntfsfix command.
sudo apt-get install ntfsprogs
Which will install the ntfs tools. Once you've installed it, you can issue ntfsfix command. If you are not sure about the drive name, please use the below command to find the drive name.
sudo fdisk -l
If you are using 80Gig external USB Storage, then you will find the below in your command output:
Disk /dev/sdb: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x3347a943
Device Boot Start End Blocks Id System
/dev/sdb1 1 9729 78148161 7 HPFS/NTFS
which is of course your NTFS USB drive. now you can issue the command as below.
sudo ntfsfix /dev/sdb1
26. If there is any problem in shutdown:-
DO the following things:-
#vi /etc/modprobe.d/power
add the following bit of code to the new file:
options apm power_off=1 realmode_power_off=1
And then EXIT from the file and reboot.
27. Copy from cd and create an iso image through command line.
dd if=/dev/scd0 of=/home/kousik/ubuntu.iso
28. Mount a iso image
mount -o loop disk1.iso /mnt/disk
29.Use packages of DVD to sources.list as repository:-
Extract iso to desktop
Copy /root/Desktop/boss3.0/dists/tejas/main/binary-i386/Packages and /root/Desktop/boss3.0/dists/tejas/main/binary-i386/Packages.gz to /root/Desktop/boss3.0/ folder
Then change the repository list
deb file:///root/Desktop/boss3.0/ tejas main
Then run apt-get update
30. GRUB1 and GRUB2 splash images
For Grub1
Another cool function with GRUB is putting a splash image on the boot menu screen. By default, GRUB will make the menu screen a plain black-and-white menu. There are menu options to change the black and white colors, but why stop there? Grab your favorite picture, or head to one of the URLs listed below which have splash images created for you. If you are creating your own, it will need to be in XPM format, a maximum color palate of 14 colors, and 640x480 resolution size. The GIMP can help transform your graphic to these specifications. As an alternative, you can use the ImageMagick suite of programs. The application convert can help with this conversion process. You can run it as follows:
$ convert -resize 640x480 -colors 14 mycoolpicture.jpg mybootsplash.xpm
$ gzip mybootsplash.xpm
In this case, the file mycoolpicture.jpg will be resized to 640x480, reduced to 14 colors, and saved in the XPM graphical format. The second step compresses the XPM file using the gzip compression method. GRUB can display the gzipped-xpm splash images well.
If you don’t want to create your own splash image, check out some of the following web sites which have them available for download:
GRUB Splash
http://schragehome.de/splash/
Once you have the XPM or gzipped-xpm file, you need to add a line at the top of GRUB’s menu.lst to instruct GRUB to load the specified boot splash image. The line should read as follows:
splashimage=/boot/grub/debsplash.xpm.gz
In my case, I’m using the Debian boot splash image as my background.
For GRUB2
Install grub2 splash image package by
$sudo apt-get install grub2-splashimages
Then modify /etc/grub.d/05_debian_theme file
Give the wall paper path around line number 10
WALLPAPER="/usr/share/images/grub/Hortensia-1.tga"
comment out
use_bg=false
Put
use_bg=true
Then run
$sudo update-grub2
output should be like this
Generating grub.cfg ...
Found Debian background: Hortensia-1.tga
...
This means you have done it successfully.
Reboot-check-and-enjoy :)
31. GRUB on CD-R/W media
I’ve also mentioned several times about installing GRUB to use for a bootable CD-R/W disk. When generating the ISO image, you will use some special settings of mkisofs. The command to build a bootable GRUB CD-R/W looks like:
$ mkdir -p iso/boot/grub
$ cp stage2_eltorito iso/boot/grub
$ mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot \
-boot-load-size 4 -boot-info-table -o grub.iso iso
The key is to copy the stage2_eltorito file into the /boot/grub directory of the CD image tree, and run mkisofs with the options specified above. As mentioned earlier, you can also burn a menu.lst file along with kernels and disk images and put them all on the CD. In the menu.lst, you will need to use (cd) as the device, rather than (hd0). Splash images work well, too.
32. Connect to Reliance ZTE MC315+
Your /etc.wvdial.conf
[Dialer Defaults]
Modem = /dev/ttyS3
Baud = 57600
SetVolume = 0
Dial-AT-OK ATDT Command =
Init1 = ATZ
FlowControl = Hardware (CRTSCTS)
Phone = #777
Username = ##########
Password = ##########
New PPPD = yes
Carrier Check = no
Stupid Mode = 1
As root user run these two command
setserial /dev/ttyS3 baud_base 230400
wvdial
--> WvDial: Internet dialer version 1.56
--> Initializing modem.
--> Sending: ATZ
+ZIND:8
--> Sending: ATQ0
ATQ0
OK
--> Re-Sending: ATZ
ATZ
OK
--> Initializing modem.
--> Sending: ATZ
ATZ
OK
--> Modem initialized.
--> Sending: ATDT#777
--> Waiting for carrier.
ATDT#777
CONNECT
--> Carrier detected. Starting PPP immediately.
--> Starting pppd at DATE
--> Pid of pppd: 7947
--> Using interface ppp0
--> pppd: X[04][06][08]H [06][08]
--> pppd: X[04][06][08]H [06][08]
--> pppd: X[04][06][08]H [06][08]
--> pppd: X[04][06][08]H [06][08]
--> pppd: X[04][06][08]H [06][08]
--> local IP address 220.224.34.198
--> pppd: X[04][06][08]H [06][08]
--> remote IP address 220.224.134.72
--> pppd: X[04][06][08]H [06][08]
--> primary DNS address 202.138.97.193
--> pppd: X[04][06][08]H [06][08]
--> secondary DNS address 202.138.96.2
--> pppd: X[04][06][08]H [06][08]
Note:With the value of baud 57600 in /etc/wvdial.conf, keep changes the value of baud_base as "n*baud " with `setserial` where n is 2,4,8,16
i.e. baud=57600, baud_base=115200,230400,460800 ....
for baud_base 230400 or 460800 modem will start responding but may vary.
33. If firefox starting @ offline mode (Due to eth0 is disable ):-
Open "/etc/dbus-1/system.d/NetworkManager.conf " from root user
Change
3/4 lines contain
34. Erase a re-writeable CD from command line
#cdrecord blank=all -immed dev=/dev/cdrw1
35. Write a iso image to a cd
#wodim --devices
Output #wodim --devices
wodim: Overview of accessible drives (2 found) :
-------------------------------------------------------------------------
0 dev='/dev/hdb' rwrw-- : 'SONY' 'CD-RW CRX230ED'
1 dev='/dev/hdc' rwrw-- : 'HL-DT-ST' 'CD-ROM GCR-8523B'
-------------------------------------------------------------------------
Then run
#cdrecord -v dev=/dev/hdb -speed=8 binary.iso
36. Get the repository size in GB
wget http://ftp.us.debian.org/debian/dists/lenny/main/binary-i386/Packages.gz -O - |zcat|sed 's/Installed-Size://'|grep Size|awk '/Size:/ {pkgsize+=$2} END {print "package size = "pkgsize/1073741824" GB"}'
37. If you want to see the file permission in numerical form
$stat -c '(%a)%8hs%.19y%n' /etc/*
38. Get the directory/folder size from Command line
$du -sh
39. If you want to keep the files under /tmp directory during rebooting
Modify the following file sudo vi /etc/default/rcS
Set TMPTIME to 60 so that files in /tmp will deleted if their modification time is more than 60 days ago.
TMPTIME=60
40. Adding a startup script to be run at bootup
So you have a script of your own that you want to run at bootup, each time you boot up. This will tell you how to do that.
Write a script. put it in the /etc/init.d/ directory.
Lets say you called it FOO. You then run
% update-rc.d FOO defaults
You also have to make the file you created, FOO, executable, using
$chmod +x FOO
You can check out
% man update-rc.d for more information. It is a Debian utility to install scripts. The option “defaults” puts a link to start FOO in run levels 2, 3, 4 and 5. (and puts a link to stop FOO into 0, 1 and 6.)
41.USB hard drive read only access
If your usb stick mounting in read-only mode just run the following command
$ sudo dosfsck -a /dev/sdb
This command will help you to check and repair MS-DOS file systems. Here I assume that my usb stick detected at /dev/sdb. Just check where usb is mounted by "fdisk -l"
42.Change the bit rate of a mp3 file:-
Install lame
Then run the following command
lame --mp3input -b 96
Here we want to convert bit rate to 96 bps
43. Backup with rsync :-
For copy to a USB or other dir without deleting the original file run the following command
rsync -avh /source/dir /destination/dir/
For copy to USB and also want to delete the source dir run the following command
rsync -avh -delete /source/dir /destination/dir/
44. Deleting comment lines starting with a special symbol:-
Let's say that your comment lines start with the symbol #. You have a handy one-liner for sed that will get rid of them:
$sed '/^\#/d' filewithcomment > filewithoutcomment
45. Working with startup scripts:-
Create startup script at /etc/init.d/ then go to that directory. Run
for Debian based system:-
#update-rc.d scriptname defaults
For Redhat system:-
#chkconfig scriptname
For disable startup script run:-
for Debian:-
update-rc.d -f scriptname remove
for Redhat:-
chkconfig -d scriptname
46. Boot debian faster:-
Open /etc/init.d/rc file
Search for "CONCURRENCY" keyword, you can see CONCURRENCY=none
Then modify this line to
CONCURRENCY=shell
Then reboot and watch.
47. Add Splash screen to debian:-
Install splashy splashy-themes in your debian system.
Then open your menu.lst (/boot/grub/menu.lst)
and in the line with kernel value add these words at the end of that line
"vga=791 splash quiet"
You can download more theme from http://splashy.alioth.debian.org/wiki/themes/contrib
Then extract theme into /etc/splashy/theme/ directory(here you can see other themes also).
Then run #splashy_config -s
Then reboot and enjoy with new theme.
48. Get exact RAM size in MB
cat /proc/meminfo | awk 'match($1,"MemTotal") == 1 {print $2/1024}'
49. X:- No Screen Found error:-
You'll need to reconfigure the X-server:
dpkg-reconfigure xserver-xorg
50. Removing "Too many levels of symbolic links" error:-
If you create symbolic link then try to access it and get the following error like this "cannot access `Lenka': Too many levels of symbolic links"
Then there is the problem with the path . Always give the Absolute path(i.e. /home/user/Lenka) rather than Lenka in ln -s
Eg ln -s /home/guest/Desktop/Lenka/ /var/www/mp3/
not ln -s Desktop/Lenka/ /var/www/mp3/
Then it will work fine.
51.Read from standard input and write to standard output and files:-
For this use tee,tee is normally used to split the output of a program so that it can be seen on the display and also be saved in a file.
Example:-
$strace alacarte 2>&1 | tee log
52. If you faceing problem in resizing Windows Partitions:-
Boot from windows .Run chkdsk \f from command prompt. After that restart twice.Then you can resize your partition.
53. Configure Tata indicom HUAWEI and Reliance HUAWEI
Check lsusb :-
Bus 005 Device 009: ID 12d1:140b Huawei Technologies Co., Ltd.
Check :- cat /proc/bus/usb/devices
T: Bus=03 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#= 2 Spd=12 MxCh= 0
D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=12d1 ProdID=140b Rev= 0.00
S: Manufacturer=HUA�WEI TECHNOLOGIES
S: Product=HUAWEI Mobile
S: SerialNumber=�����������������
��
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=500mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage
E: Ad=87(I) Atr=02(Bulk) MxPS= 64 Ivl=0ms
E: Ad=08(O) Atr=02(Bulk) MxPS= 64 Ivl=0ms
login as a root and copy usb_modeswitch.conf in /etc folder and usb_modeswitch executable in /usr/sbin
run following command..
Download the files from here
#usb_modeswitch -v 0x12d1 -p 0x140b -d 1
#usb_modeswitch -v 0x12d1 -p 0x140b -H 1
test using wvdialconf that device is detected or not and then configure
/etc/wvdial.conf
Sample file:-
#start of wvdial file
[Dialer Defaults]
Modem = /dev/ttyS3
Baud = 57600
SetVolume = 0
Dial-AT-OK ATDT Command =
Init1 = ATZ
FlowControl = Hardware (CRTSCTS)
Phone = #777
Username = ##########
Password = ##########
New PPPD = yes
Carrier Check = no
Stupid Mode = 1
#End of wvdial file
The next command may be optional for USB
Then run setserial /dev/ttyS3 baud_base 230400
and run wvdial
54. Reverse search by Grep
If you want to search with grep that reverse the meaning of a grep search
Use -v option
e.g. grep -v disk | dmesg
This will print all line except line containing disk
55. How to view logfiles in Debian:
Use dump-utmp (dump-utmp - print an utmp file in human-readable format)
For that you have to install acct package
Then run
$dump-utmp /var/log/wtmp
This will show the the file into human readable format
56. Change hostname
To change hostname run
#echo "New_host_name" > /proc/sys/kernel/hostname
Then reboot and check
57.Create own Debian repository from an installed Debian or Ubuntu system:- You can create your own repository from an installed system. This can be helpful for saving bandwidth and saving your time also(if system some how got corrupted).
For this package needed is dpkg-dev. You can install it from synaptic package manager.
Then create a directory, e.g. my_repo . This is the root of your repository. Under this create a directory named binary
After that copy .deb files from /var/cache/apt/archives/ into binary directory.
Then go that my_repo directory and run
dpkg-scanpackages binary /dev/null | gzip -9c > binary/Packages.gz
This will create your packages list.
After that save whole my_repo directory into another system and change the /etc/apt/sources.list file and add the path of the my_repo directory like this:-
deb file:///home/boss/my_repo binary/
If you don't have internet connection you can comment out other lines.
Then reload the repository list and check .
58. Removing GPG warning during apt-get update
If you face the following warning :-
W: GPG error: http://www.vislab.uq.edu.au lucid/ Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY DA9163F7B638808E
You have to run these command:-
$gpg --recv-keys DA9163F7B638808E
Output:-
gpg: requesting key B638808E from hkp server keys.gnupg.net
gpg: key B638808E: public key "Christoph Willing (UQ)
gpg: Total number processed: 1
gpg: imported: 1
Next:-
$gpg -a --export DA9163F7B638808E | sudo apt-key add -
Output:-
OK
After that run apt-get update.
59.Resolving " could not gain access to /dev/sound/dsp for writing"
Run these two commands :
$sudo ln -s /dev/snd /dev/sound
$sudo ln -s /dev/dsp /dev/snd/
Then check...
60.Unmount forcefully ...
Run these two comman If you are faceing problem in unmounting usb, you can do it forcefully
Assuming you mount your USB at /media/disk, run :-
#umount -l /media/usb
61.Configure sify-bbclient for Ubuntu 10.10
Download Sify Broadband client from here http://202.144.65.70:8090/linuxinstall.html
Download the non-rpm ...
Extract the archive and install the Sify Broadband client by running
$./install.sh
from terminal(first go to the directory).
Then run try to run
$sudo ./sifyconnect
It will complain libcrypto.so.4 and libssl.so.4 not present. You have to just create a softlink for these 2 files.
$sudo ln -s /lib/libssl.so.0.9.8 /lib/libssl.so.4
$sudo ln -s /lib/libcrypto.so.0.9.8 /lib/libcrypto.so.4
After that go to System-> Preference->Network Connection and select your wired connection give the proper settings which you have got from your ISP. Then check.
Then run
$sudo ./sifyconnect
62. Replace a String in a file.
replace 'From' 'To ' -- filename
63. Switch between different java installed in your system
Run
$sudo update-alternatives --config java
This will show you all installed java versions.Then you choose which you want to use.
64.Enable SCIM(Smart Common Input Method ) for Libreoffice.
First you have to install scim.
Then run the following command
$export XMODIFIERS=@im=SCIM
$export GTK_IM_MODULE=scim
$export QT_IM_MODULE=scim
$scim -d
Then go the installed directory of Libreoffice( My case it was /opt/libreoffice3.4/
$cd /opt/libreoffice3.4/ure/lib/
$ sudo mv libstdc++.so.6 libstdc++.so.6.orig
$ sudo mv libgcc_s.so.1 libgcc_s.so.1.orig
Then check if it works by pressing comtrol+space.
65. Restore Ubuntu 12.04 Panel
If Ubuntu 12.04 panel doesn't appear properly, run
$ sudo apt-get install dconf-tools
and
$sudo dconf reset -f /org/gnome/gnome-panel/
This will restore your panel.
66. Detect rogue dhcp
# ifconfig ethX promisc
# tshark -i ethX -n port 68 -R 'bootp.type == 2'