OpenSource For You



Autofetch the last argument

So often, we copy the last command’s argument and paste it for the next command. We do this task manually by selecting the argument, and then copying and pasting it. Here is a time-saving tip that I’m sure you will love. Check the following example:

mkdir /home/cg/root/maulik

The mkdir command is to create a new directory. The next task is to go inside this directory. Most people will copy the path, write the cd command and then paste it.

Here is another simpler approach. Use ‘!$’, which will fetch the last argument automatica­lly. The other option is to use the ‘Esc + .’ command after cd.

Note: ‘!$’ or ‘Esc + .’ will fetch the last argument for any command. If the last command has no argument, then these will fetch the last command.

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. maulikpare­

Retain the remote terminal using the screen

If we happen to close the remote terminal session, we can still run the task on the remote terminal without an issue by using the ‘screen’ tool.

We need to have screen installed on the remote Linux machine so that we can use it. $apt-get install screen Start a screen session on the remote machine, as follows: $screen -S name

After a disconnect to the remote Linux machine, run the following command to get back to the same screen terminal that was being used:

$screen -dr name

Here, ‘name’ is the screen session’s name. To know the list of the active screen sessions, use the following command:

$screen -list —Vasanthaku­mar T,

Using the long list command without ls -l

You can use the undocument­ed long list or the ll (double l) command as follows. If appended with the directory names, it will produce a long list of the following:

1. All the items present in appended directorie­s.

2. The hidden files as well.

3. The space occupied by directorie­s.

4. The directorie­s in sequence, ranging from those with the least files to those with the most files.

On many distros, this won’t work, in which case, you can create an alias ll of ls –l.

—Tejas Rawal, tejasprawa­

Disk space usage by ‘n’ number of items in a file

To find out the disk usage by ‘n’ number of items in a

file, use the following commands: #cat /tmp/test.txt name1 name2 foldername/name3 ... nameN foldername­N #for i in `cat /tmp/test.txt` ;do du -sh $i ; done —Remin Raphael,

A command line hack for crontab

This small script installs itself in crontab if the script is already not there.

I had a script [/tmp/] that I needed to run in crontab, but as it was under developmen­t, every now and then the version got updated, and I had to recopy the script and add it.

The following script helped me a lot.

#crontab -l | grep -q ` bash /tmp/ ` && \ echo “exists” || cat <(crontab -l) \ <(echo “0 */2 * * * bash /tmp/ “) | crontab -” You can modify this simple script to suit your needs. —Murali Sridhar, muraleesri­

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

We often need to get the listing of a directory and fetch files that are bigger than, say, 1GB or 100MB. Here’s a tip that you can use for this. Run the following commands with root access.

* For file sizes of 1GB or more, use the command:

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

* For file sizes of 100MB or more, give the following command:

#sudo find / xdev type f size +100M exec ls lh {} \; —Rupin Puthukudi,

Disabling the touchscree­n in Ubuntu

Many of the latest laptops come with a touchscree­n. Sometimes we need to disable or enable the touch facility for a particular purpose.

Here is a command that will help you to do that, if you are using Ubuntu: $xinput setprop 10 ‘Device Enabled’ 0 For enabling the touchscree­n, type: xinput setprop 10 ‘Device Enabled’ 1 —Sethu Ram, dycmiti@konkanrail­

How to change a user’s password in a non-interactiv­e way

If you want to change a password without prompting for it, say, in scripts, use the following command:

$ sudo echo -e “password\npassword” | passwd testuser

—Krishna Murthy Thimmaiah,

Increase the size of your ‘history’

The ‘history’ command displays a list of the previous commands you used on the terminal. By default, it stores only the last 1000 commands that you used. Often, we need to store more than 1000 commands. To enable this, we have to change the following lines in the ‘.bashrc’ file in the home folder.

To open the ‘.bashrc’ file, use the following command in the terminal:

$vi ~/.bashrc …and change the following two lines: HISTSIZE=1000 HISTFILESI­ZE=2000

For instance, if you want to increase your history size to 40000, then these two lines should be:

HISTSIZE=40000 HISTFILESI­ZE=40000 Now, save the file. —Nagaraju Dhulipalla, nagarajuni­

 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from India