Tips & Tricks
Using the Linux process task manager
Whenever the system hangs and we cannot do anything about it, we can kill that process by using the terminal and resume our work as before so that we don’t need to restart our system. To do this, we must open the terminal by pressing Ctrl + alt + T.
Now, in the terminal, type the top command, which will show you all the running processes. From the output of the top command, note the PID (process ID number) that you want to kill. Let’s suppose my Chrome browser is using up all the memory or CPU resources, forcing my computer to hang, and its PID is 1309.
$top Press q to exit the top command: kill -9 <YOUR PID> $kill -9 1309 This will kill the process that is running on PID 1309. —Dhavalkumar Prajapati, dhaval.daiict@gmail.com
Change the last modified/created date of a file
Ever wondered if you could change the last modified/ created date of a file? Well, you can!
Consider the sample file as shown below, which was created on some arbitrary day:
-rw-rw-r-- 1 ec2-user ec2-user 52 Dec 17 07:37 sample Now, create a new file with a touch/vim: $touch new-file
The files in the directory will now look like what’s shown below: -rw-r--r-- 1 root root 0 Jan 14 05:05 new-file -rw-rw-r-- 1 ec2-user ec2-user 52 Dec 17 07:37 sample
Next, assign the last modified date of the sample to newfile: $touch -r sample new-file
Voila! The date of the new file is now the same as the sample file!
-rw-r--r-- 1 root root 0 Dec 17 07:37 new-file -rw-rw-r-- 1 ec2-user ec2-user 52 Dec 17 07:37 sample
This preserves the contents of newfile but only changes the last modified date.
—Dheeraj Tripathi, dheeraj007tripathi@gmail.com
An interesting command in Ubuntu
Aptitude is a text based interface based on the Advanced Packaging Tool (APT) system. Many of the common package management functions, such as installation, removal and upgrade, can be performed in Aptitude with single-key commands, which are typically lower case letters. It can be installed by using the following command:
$sudo apt-get install aptitude To verify, use the following: $aptitude
Aptitude will accept the moo as a parameter, which executes the following funny words as an output. Shown below is an example of the same:
$aptitude -v moo
There really are no Easter Eggs in this program.
$aptitude -vv moo
Didn't I already tell you that there are no Easter Eggs in this program?
$aptitude -vvv moo Stop it!
$aptitude -vvvv moo
Okay, okay, if I give you an Easter Egg, will you go away?
$aptitude -vvvvv moo All right, you win.
/----\
-------/ \
/ \
/ | -----------------/ --------\ ---------------------------------------------$aptitude
-vvvvvv moo
What is it? It's an elephant being eaten by a snake, of course.
Here, ‘v’ is a ‘verbose file’. —Ramprakash S, ramkeelai@gmail.com
An exit shortcut
We use various terminal commands that are interpreter based. To come out of these, just press Ctrl+D. This shortcut works for the Linux, Python, ssh, sftp and MySQL terminals.
—Tushar Kute, tushar@tusharkute.com
Print a distinct extension in a folder
To print distinct extensions in a given folder, use the following command:
find /path/to/your/directory -type f | awk -F. '!array[$NF]++{print $NF}'
This command will capture the extensions in a given folder by separating the field names with a period (‘.’) and printing the last entry, i.e., the extension. For regular files that don't have any extension, the absolute path of the file gets printed.
—Madhu Babu, madhumadhana93@gmail.com
Run as the super user using 'nautilus'
Instead of working from the terminal using sudo every time, type the following command on the terminal: $sudo nautilus
As soon as you run this command, a file explorer will be opened. All actions that you wanted to do on the terminal using the sudo permission can now be done in this file explorer’s GUI.
—Anirudh k, anirudh.3194@gmail.com
Remove unwanted and duplicate files using FSlint
With time, we start keeping the same files with the same name (or a different name) on various folders in our system, either knowingly or unknowingly.
Here is an easy way of getting rid of duplicate and unwanted files present anywhere in your computer. FSlint is open source software for Linux systems. It can be used on both the command line and GUI modes. First, you need to install it to start using it.
So type the following commands in the terminal:
sudo apt-get update sudo apt-get install fslint
After successful installation, you can use FSlint by searching for it in the Ubuntu dashboard.
—Akhilesh Pandey, akhilesh.sssihl@gmail.com
Run a command and come back to the current working directory immediately
You can run a command in Linux and immediately come back to the current directory. All you need to do is to run the command in parentheses.
$(cd /home/abhishek/Documents/ && ls)
The above command will list all the files in the directory Documents and come back to the present directory immediately.