Linux is fast being seen as an open source alternative to Microsoft's more popular Windows operating system. Who wouldn't love an operating system that's fast, good-looking, and almost free from security threats, doesn't bloat and comes without any cost? Also, all the major applications now have a Linux version of themselves too. What more, it's not like there are no updates or support, a very much necessary requirement for an OS, but instead updates are periodically rolled out and there is a pretty active Linux community out there. The only catch is that it has a steep learning curve but still you can perform basic things without any problem. This is why we'll share loads of tips and tricks, troubleshooting guides, how-tos, administration guides and general tweaking regularly on this page.
Table of Contents
- Handling the Command Prompt in a Smart Way
- Check System Information
- Display the System's SMBIOS Hardware Components
- Limit the CPU Usage of a Process
- Text-Based Web Browsing
- Download a Website
- DOS Versus Linux Commands
- Make Your Linux Box Speak
- Play Songs From the Command Line
- More passwd Flags
- View the Contents of a File Inside a ZIP Archive
- Sort Folders By Size
- Finding the Size of a Folder or Sub-folder
- Creating Secure Passwords
- Generate Sequences
- Prevent Linux From Remembering Your sudo Password
- Sudo Insults
- A cat with a Twist
- Restoring Defaults in KDE4
- Kill Processes Graphically
- Change X's Resolution on the Fly
- What Have You Done?
Handling the Command Prompt in a Smart Way
Working on the command prompt is an essential task for any Linux system administrator. However, many newcomers find it difficult to use the Bash prompt. Here are some tricks to speed up your work.
1. Recall the last argument from the previous command to save time: 'ALT' plus '.' (Hold down the ALT key and press the dot). For example, let's assume you created a new directory as follows:
mkdir -p /tmp/demo/software/text
Now, you would like to change the directory to /tmp/demo/software/demo. So type cd and press ALT plus . and see how Bash copies the argument that you gave to the previous command – in your case, it's the path you provided to mkdir.
2. Short-cut keys for command editing:
- CTRL + l :- Clears the screen.
- CTRL + u :- Deletes the entire line.
- CTRL + k :- Deletes to the end of the line from the current cursor position.
- CTRL + c :- Cancels the command.
- CTRL + z :- Suspends the command.
- CTRL + R :- This is used to search for a command in command history. For example, yesterday or few hours back you typed 'a very, very long command' and you need the same command again. Then hit CTRL + R and type the first few letters of the command.
- CTRL + T :- Transposes characters. For example, let's assume that you wanted to type the date command and ended up typing the following:
Sure, you can delete the last two characters and retype it again, but wait! You can hit CTRL + t and you are done.
How to Check System Information
If you want to see system information about your computer then open terminal and type following command:
Use manual pages for more information like which parameters are supported by uname. For example you can use -p to print the processor type.
Display the System's SMBIOS Hardware Components
Do you want to know the entire details of each piece of hardware on your computer? Here’s a command for it! (Run with root permissions).
dmidecode -t x
Replace x by,
- 0 for BIOS.
- 1 for system.
- 2 for base board.
- 3 for chassis.
- 4 for processor.
- 5 for memory controller.
- 6 for memory module.
- 7 for cache.
- 8 for port connector.
- 9 for system slot.
- 10 for on board devices.
- 11 for OEM strings.
- 12 for system configuration options.
Limit the CPU Usage of a Process
You can use the cpulimit command to limit CPU usage of any process or application in Linux. You can limit a certain running application, either by its name or by its PID. For example, to restrict the VLC media player to go beyond a 20 per sent CPU usage limit, use the command below:
cpulimit -e vlc -l 20
We can also use the PID, as follows:
cpulimit -p 5399 -l 40
To find the process name or PID, use ps -d command.
Text-Based Web Browsing
You may use elinks or links in text mode to browse websites from a console. elinks can not only be controlled by a keyboard but also by the mouse to an extent, and is an advanced version of links. Here's how to get started:
This will open www.techlila.com in your browser. Press the Esc key to access the menu where, among other items, you will find File? Exit to close the browser.
Download a Website
Here is a simple and effective way to get the files downloaded recursively from a website without actually visiting each and every link to the sub pages. This is also useful in case the pages are of type XHTML or text type—one can make them .html by use of an appropriate switch like -E. Go to the directory onto which you wish to download all the content from site, and use the following command:
wget -r -p -k -E
-r is for recursive download of pages
-p is for linking pages locally so that users can browse them easily once the download is completed
-k is to create the directory structure, and
-E is to create .html extensions to the type XHTML or text files.
Enjoy, and try out different contents on the Net. Do not forget to check out the manual pages for wget there's always more information.
DOS Versus Linux Commands
Following table lists MS-DOS commands with their Linux counterparts. Please note that Linux commands usually have a number of options.
Checkout: A-Z Index of the Windows CMD command line.
Make Your Linux Box Speak
Ubuntu and many other distros have an inbuilt speech synthesiser called espeak. Use the following command in the terminal:
Did you hear your Linux box report, "linux"?
If you to hear a line then add a line in quotes as
"I'm new in Linux World"
Play Songs From the Command Line
You can play any song file from the command line without using any player but a utility called SOX. More often than not, SOX is available in your distro's repository. You can install it in a Debian-based system (Ubuntu) as follows:
sudo apt-get install sox
To install packages on other distros read this article: Package Management Tips for Linux Users. To play a song from the command line, use:
…where song.mp3 is the path to your MP3 file. To stop playback, hit Ctrl+C. If your song's file name contains spaces, specify the file name within double quotes. For example:
play "song 2.mp3"
When playing audio files, you can even specify more than one input file as follows:
play "song 2.mp3" "song 3.mp3" "song 5.mp3"
More passwd Flags
You can change user account details using the passwd command. Yes, it can do more than changing just the password. Open the new terminal and enter the following commands:
passwd -d [user_name]
where -d deletes the user's password. Some other useful flags are:
-l locks the user account.
-u unlocks the user's account.
-? is to get help.
View the Contents of a File Inside a ZIP Archive
To view the contents of a file inside a ZIP archive without extracting it into the local file system, use the following command:
For example, the command given below will print out the contents of test.txt into the console. "test.txt" file is a file inside the test.zip archive.
unzip-p test.zip test.txt
Sort Folders By Size
To sort folders by size, use the following command:
du --max-depth=1 /home/ | sort -n -r
Finding the Size of a Folder or Sub-folder
To find the size of a current folder, type the following command in terminal:
To find size of all sub-folders and files in the current folder, type in:
du * -sh
s stands for 'summarise'
h stands for 'human readable format'
Creating Secure Passwords
We need to create strong passwords for Web forms, e-mail accounts, Web registration pages, etc. We can create one easily in GNU/
openssl rand 4 -base64
The above command will create a random base 64 encoding string each time it's run. Since the string you get from the command is different each time the command is run, it's secure and easy to create a strong password this way.
You can use the seq command to generate sequences. For example:
seq 1 5
The output for the above command will be:
Prevent Linux From Remembering Your sudo Password
You can prevent Linux from remembering your sudo password. In order to do this, use the following command:
..and add this line to the file:
Defaults timestamp_timeout = 0
You may change 0 to any number representing the minutes you may want your password to be 'remembered', or let it be 0, in which case you will need to type your password each time you type sudo.
If you want to see insults after each time you give wrong password to sudo. Then, Open terminal and type:
In that file add new line :
Then every time sudo will insult with funny lines.
A cat with a Twist
We use cat command to view a text file from beginning to end, right? Want to read a text file from the end to beginning? Use the tac command and see the difference.
Restoring Defaults in KDE4
Sometimes while personalizing your panel you may accidentally delete it. And then you may want to restore the distro's default panel back again. This is how we do it on KDE 4. Log out and open a command prompt using Ctrl+Alt+F1. Then log in as the same user and run this command:
This is the file where configurations are stored for any user. If you remove it, the default settings will reappear. Use Ctrl+Alt+F7 in order to access the X server to log back in.
Kill Processes Graphically
The xkill command closes the connections of a client to X server. Using the xkill command changes your mouse cursor into a 'kill' sign. Now when you click the left mouse button on any window that you want to kill, it gets killed. Note that this program is very dangerous, yet useful for aborting program windows that otherwise do not shut down.
Change X's Resolution on the Fly
In order to change the resolution of X we can make use of the command xrandr. Simply type this command on a terminal and it will display all resolutions supported by the X window. Then in order to set the resolution of the X window to one of the supported resolutions, say 1024×768, simply execute the following:
xrandr -s 1024x760
It will immediately change the resolution of the X window, on the fly.
What Have You Done?
The history command will give you the complete history of all the commands you've run till now along with their serial numbers. For example:
1 su –
3 rm -rf .kde4/share/apps/kmail/mail
4 rm -rf .mozilla/
5 rpm -qa | grep flash
7 rpm -qa | grep rpm
8 ps -A | grep rpm
9 cd /var/lib/flash-player-plugin/
10 su –
There is a history manipulation command too called fc. Type:
This will allow you to edit the command using the Vim editor. When you save and exit, it runs the command automatically.
For more available options, you can refer manual (man) pages. You can use man pages in following way:
man "command name"
For example, man dmidecode