TIPS &TRICKS

OpenSource For You - - For U & Me -

Aut­ofetch the last ar­gu­ment

So of­ten, we copy the last com­mand’s ar­gu­ment and paste it for the next com­mand. We do this task man­u­ally by se­lect­ing the ar­gu­ment, and then copy­ing and past­ing it. Here is a time-sav­ing tip that I’m sure you will love. Check the fol­low­ing ex­am­ple:

mkdir /home/cg/root/maulik

The mkdir com­mand is to cre­ate a new di­rec­tory. The next task is to go inside this di­rec­tory. Most peo­ple will copy the path, write the cd com­mand and then paste it.

Here is an­other sim­pler ap­proach. Use ‘!$’, which will fetch the last ar­gu­ment au­to­mat­i­cally. The other op­tion is to use the ‘Esc + .’ com­mand after cd.

Note: ‘!$’ or ‘Esc + .’ will fetch the last ar­gu­ment for any com­mand. If the last com­mand has no ar­gu­ment, then these will fetch the last com­mand.

bash-4.3$ bash-4.3$ pwd /home/cg/root bash-4.3$ bash-4.3$ bash-4.3$ mkdir /home/cg/root/maulik bash-4.3$ cd !$ cd /home/cg/root/maulik bash-4.3$ pwd /home/cg/root/maulik —Maulik Parekh. maulik­parekh2@gmail.com

Re­tain the re­mote ter­mi­nal us­ing the screen

If we hap­pen to close the re­mote ter­mi­nal ses­sion, we can still run the task on the re­mote ter­mi­nal with­out an is­sue by us­ing the ‘screen’ tool.

We need to have screen in­stalled on the re­mote Linux ma­chine so that we can use it. $apt-get in­stall screen Start a screen ses­sion on the re­mote ma­chine, as fol­lows: $screen -S name

After a dis­con­nect to the re­mote Linux ma­chine, run the fol­low­ing com­mand to get back to the same screen ter­mi­nal that was be­ing used:

$screen -dr name

Here, ‘name’ is the screen ses­sion’s name. To know the list of the ac­tive screen ses­sions, use the fol­low­ing com­mand:

$screen -list —Vas­an­thaku­mar T, vas­an­th_22k@red­iff­mail.com

Us­ing the long list com­mand with­out ls -l

You can use the un­doc­u­mented long list or the ll (dou­ble l) com­mand as fol­lows. If ap­pended with the di­rec­tory names, it will pro­duce a long list of the fol­low­ing:

1. All the items present in ap­pended direc­to­ries.

2. The hid­den files as well.

3. The space oc­cu­pied by direc­to­ries.

4. The direc­to­ries in se­quence, rang­ing from those with the least files to those with the most files.

On many dis­tros, this won’t work, in which case, you can cre­ate an alias ll of ls –l.

—Te­jas Rawal, te­jasprawal@gmail.com

Disk space usage by ‘n’ num­ber of items in a file

To find out the disk usage by ‘n’ num­ber of items in a

file, use the fol­low­ing com­mands: #cat /tmp/test.txt name1 name2 fold­er­name/name3 ... nameN fold­er­nameN #for i in `cat /tmp/test.txt` ;do du -sh $i ; done —Remin Raphael, remin13@gmail.com

A com­mand line hack for crontab

This small script in­stalls it­self in crontab if the script is al­ready not there.

I had a script [/tmp/script.sh] that I needed to run in crontab, but as it was un­der de­vel­op­ment, ev­ery now and then the ver­sion got up­dated, and I had to re­copy the script and add it.

The fol­low­ing script helped me a lot.

#crontab -l | grep -q ` bash /tmp/script.sh ` && \ echo “ex­ists” || cat <(crontab -l) \ <(echo “0 */2 * * * bash /tmp/script.sh “) | crontab -” You can mod­ify this sim­ple script to suit your needs. —Murali Srid­har, mu­raleesrid­har@gmail.com

How to find a file larger than 1GB, 100MB or any size

We of­ten need to get the list­ing of a di­rec­tory and fetch files that are big­ger than, say, 1GB or 100MB. Here’s a tip that you can use for this. Run the fol­low­ing com­mands with root ac­cess.

* For file sizes of 1GB or more, use the com­mand:

#sudo find / ­xdev ­type f ­size +1G ­exec ls ­lh {} \;

* For file sizes of 100MB or more, give the fol­low­ing com­mand:

#sudo find / ­xdev ­type f ­size +100M ­exec ls ­lh {} \; —Rupin Puthukudi, rupinmp@gmail.com

Dis­abling the touch­screen in Ubuntu

Many of the latest lap­tops come with a touch­screen. Some­times we need to dis­able or en­able the touch fa­cil­ity for a par­tic­u­lar pur­pose.

Here is a com­mand that will help you to do that, if you are us­ing Ubuntu: $xin­put set­prop 10 ‘De­vice En­abled’ 0 For en­abling the touch­screen, type: xin­put set­prop 10 ‘De­vice En­abled’ 1 —Sethu Ram, dy­cmiti@konkan­rail­way.com

How to change a user’s pass­word in a non-in­ter­ac­tive way

If you want to change a pass­word with­out prompt­ing for it, say, in scripts, use the fol­low­ing com­mand:

$ sudo echo -e “pass­word\npass­word” | passwd tes­tuser

—Kr­ishna Murthy Thim­ma­iah, gtk321@red­iff­mail.com

In­crease the size of your ‘his­tory’

The ‘his­tory’ com­mand dis­plays a list of the pre­vi­ous com­mands you used on the ter­mi­nal. By de­fault, it stores only the last 1000 com­mands that you used. Of­ten, we need to store more than 1000 com­mands. To en­able this, we have to change the fol­low­ing lines in the ‘.bashrc’ file in the home folder.

To open the ‘.bashrc’ file, use the fol­low­ing com­mand in the ter­mi­nal:

$vi ~/.bashrc …and change the fol­low­ing two lines: HISTSIZE=1000 HISTFILESIZE=2000

For in­stance, if you want to in­crease your his­tory size to 40000, then these two lines should be:

HISTSIZE=40000 HISTFILESIZE=40000 Now, save the file. —Na­garaju Dhuli­palla, na­gara­ju­nice@gmail.com

Newspapers in English

Newspapers from India

© PressReader. All rights reserved.