Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, 3 August 2014

Stop-frame animation

Time it takes: 120 minutes

Before processing power was abundant, stop-frame animation was the preserve of the professional. You needed some serious equipment and the enough patience to set each shot up, make a small change to your scene, take the photograph and move on to the next shot. Only then could you develop your frames and construct your animation. Computers remove most of the tedium, and turn what might have been hard labour into a few hours of fun.

Create the art

There are several ways to generate the images you'll use to construct an animation. One of the easiest is to use a digital camera to take photographs of your scene. This is great if you wanted to animate plasticine models, for example. Alternatively, stick purely to Gimp and create each frame manually using its drawing tools.
If you're importing images from a digital camera or a scanner, the trick is to make sure that each image is placed on a different layer within the same Gimp project. You can do this by opening the first frame of your animation, then selecting 'Open As Layers' from the File menu and Shift-selecting all the other image files in your animation. Each frame will then be listed in the layers panel on the right, and you should save your project as a native XCF document before you make any further changes. You can't flick through the animation at this stage, but you can use layer opacity to make sure the subject in each image is aligned. If there are any problems, Gimp has dozens of editing and filter functions that can help pull the quality of your animation up a notch.

Draw it yourself

For our manual approach, we selected the brush tool with a white background and a black paint colour, created a blank canvas at a resolution of 800x600 and started to draw, creating a new layer for each frame. We found it easier to see successive changes if each new layer had a transparent background, as this allowed us to see the previous frames. If you do this, you'll need to right-click on each layer and select Remove Alpha Channel before rendering the final animation. On your first attempt, we'd recommend keeping things simple. We drew a ball falling on to a single-lined trampoline, and the complete animation was 20 frames.

Export

Whether you drew the frames yourself or imported images from your camera, you can export a working animation from Gimp using the animated GIF format. Choose File > Save As from the menu and make sure the format you choose is GIF. Gimp will inform you that the project needs to be exported before it can be saved, and you should choose Save As Animation and then click on Export. This will create a GIF file on your system, and you can view your animation for the first time by right-clicking on this and opening it with Firefox. If you find the GIF format too restrictive, you can use a tool such as MEncoder to convert your animation to something you can share with other people.

Step by step: Animate your doodles

1. If you're using digital camera images, open the first in the animation and then use Open As Layers to load the rest.
2. When drawing each frame, create the layers with transparency and remove the alpha channel before saving.
3. Save the image as a GIF file and Gimp will ask you whether you'd like to create an animation from the file. Yes you do!

Record a podcast

Time it takes: 60 minutes

There are now thousands of podcasts available, but if you've taken the trouble to listen some of them, you soon realise that many are mediocre at best, and they probably left you feeling that you could do better. Well, now is the time to give it a go. Whether the subject covers open source, Linux or your favourite band, creating and publishing a podcast is a hugely rewarding process. After several months of recording the TuxRadar podcasts, here's our guide to getting the best possible output.

Setup

The most important thing to get right when creating a podcast is the recording. You need to make sure you've got a quiet environment for your performers, so avoid noisy air conditioning units and photographers. You also need to make sure you're using a reasonable quality microphone. If there's more than one person in the recording, each person should have their own mic. If not, you need to make sure they speak as close to the microphone as possible - ideally no more than 18 inches away. LugRadio used cheap piezo microphones for each member of the team, while we use general-purpose condenser microphones. Most soundcards will only record two inputs at once, which means you'll need a more professional solution if you need to record more, and a small external mixer can help balance the levels from the microphone before it makes it to your Linux machine. You need to make sure the signals are as loud as possible without clipping, as this will create distortion.

Recording

The best piece of software we've found for making the recording is Audacity. It's capable of recording multiple channels at once, and it's the only option for chopping your podcast down to size after the recording. Use the Preferences window to set up the inputs for your hardware and press Record when you're ready to start. Just leave the recording running for the entire duration of the show, and re-speak any fluffed lines or unwanted insults. We also recommend that you split your podcasts into sections, rather than leaving it as a two-hour-long stream of consciousness, but the choice is yours.
After you've finished the recording, you'll need to listen to the whole thing again in Audacity, cutting any areas that need to be cut. You don't need to be too exact about these cuts, as Audacity will try its best to avoid clipping noise. If you want to a musical interlude between each section, use the 'Add New Track' option from Audacity's track menu, copy the music from another Audacity session and paste it into the new track at the appropriate points.
Audacity is the best audio software we've found for recording, editing and mastering a podcast.
Audacity is the best audio software we've found for recording, editing and mastering a podcast.

Mastering and output

There's a lot you can do within Audacity to make your recordings sound better. The Noise Removal effect is quite good at removing low levels of background noise, for example. We'd also suggest using the Compression effect. Unlike normalise, which amplifies the recording until the highest signal is maximised, compression amplifies only the quieter sections. With a vocal recording, this can help reduce the highs and lows of conversation by making a more uniform level for the whole recording. If you keep the Normalise option enabled in the compression window, you get the best of both worlds. When you're happy with the recording, use Audacity's export function to create either an Ogg Vorbis file or an MP3. If it's the latter, you'll need the Lame library installed. We found that you can use the lowest-quality settings for output; it makes very little difference to the sound quality and it keeps file sizes low.
To publish your podcast, just upload it to some online storage and post a link from a blog or web page. If you want people to be able to subscribe to your podcast so that their clients automatically download a new episode, you'll need to create an RSS text file containing certain specific tags. The typical RSS feed is too large to print, but you can easily grab the one for TuxRadar and change our details. Make sure the latest podcast comes first in the RSS, and that date formats conform to the ISO standard. Each time you create a new podcast, you simply need to add a new 'item' section within the RSS file, and you're ready to go.

Secure remote desktops

Time it takes: 60 minutes

Not only do remote desktops enable you to access your old familiar machine from anywhere on the internet, they also enable you to build a multi-desktop, multi-user environment out of a single machine that doesn't necessary even need a screen. This is a great solution on netbooks, for example, where you may occasionally need the extra horsepower of a full-blown PC. Just connect to the server from your netbook desktop and you've got a full desktop on top of a small one.

VNC

There are several ways to run a remote desktop from Linux. The X server itself was designed to run remotely, and you can still forward windows from a local server to a remote one with relative ease, especially if you use SSH. But the X protocol is inefficient, and only fast enough for general use if you're connected to the same network as the server. A far better alternative is FreeNX. This breaks window and cursor movement up into a series of commands that can be transferred much more efficiently than X, and the remote desktop is much more responsive as a result. But there's a problem with FreeNX: It can be a complete pain to install, and there seems to be a different method for every distribution we look at. The day FreeNX becomes easy to install is the day we'll write instructions on how to get it to work.
This leaves us with VNC. VNC sends chunks of compressed image data rather than interpreting any drawing routings, and as a result sits half-way between the X server and FreeNX for efficiency. But it does have one big advantage, and this is that you can find VNC clients everywhere. Many mobile phones, PDAs and netbooks will have a VNC client available, and both Windows and OS X have free and paid-for client applications that can connect to VNC running on your Linux box. From a Linux perspective, KDE and Gnome both have built-in support for connecting to VNC servers.

Running the server

There are several variations of VNC, but our favourite is called TightVNC, which includes a few performance improvements over the original VNC protocol. On your server, you should be able to install the tightvncserver package from the package manager. To start a VNC session, you need to open a command line and type vncserver :1. This will launch a new server which will be attached to the second (:1) graphics console on the machine. The first would be :0, but this will be the current display on that machine, unless it's running in pure console mode. Any other machine running on the LAN will now be able to connect to the VNC server by using the IP address of the server followed by :5901.
As VNC uses just one port (5901) you can easily tunnel this port to a remote connection through SSH. This is a great solution if you want to access your Linux box from the wilds of the internet, as it means you only need to leave the relatively secure SSH port open (port 22), with just the SSH server facing the internet. The VNC server is safely tucked away behind the firewall. An SSH tunnel is a little like a wormhole.
It takes the data from port 5901 on the server, for instance, tunnels this through the standard SSH data connection on port 22, and reconstitutes the data on the client at the local port 5901. All you then have to do is use a VNC client to connect to localhost:5901 rather than the remote IP address.

Step by step: VNC through SSH

1. Type 'vncserver :1' followed by a password to launch the VNC server.
2. Type 'ssh -l 5901:localhost:5901 server_ip' to connect to the server using SSH.
3. Use a VNC client such as KRDC to connect to localhost:5901.

Write interactive fiction

Time it takes: 60 minutes

Text adventure games were massively popular at a time when all computers could do was display text, and there has recently been a strong resurgence in their popularity thanks to mobile devices. The games eat few CPU cycles, burn very little power and don't require too much dexterity. You don't need to be a coding guru to write one either: the games are programmed using a form of natural language. For example, the game parser will understand the name and relative positions of the two locations described by the line 'The library is west of the landing.' This makes developing games almost as much fun as playing them. Secondly, there's a brilliant development environment that can help you map out the ideas and locations for your game, as well as help you enter and understand the source code. And to show just how easy it is, we're going to create the beginnings of an interactive masterpiece.

Install the IDE

The IDE is called Gnome Inform, and you'll need to grab packages for your distribution as they're seldom included in the average repository. The project's page on SourceForge includes binary packages for most popular distributions, and there shouldn't be any weird dependencies. Installing the application using a package manager should be a simple point and click process, and it can be executed by either typing gnome-inform7 on the command line, or finding the application hidden within your launch menu.
Games created using Inform 7 can be played on anything from mobile phones to wristwatches.
Games created using Inform 7 can be played on anything from mobile phones to wristwatches.

Get writing!

The main Gnome Inform window is split into two panels, both of which can be switched to display any one of seven screens. Normally, you'd use the panel on the left to type the source code for the game, and the panel on the right for testing the current build, documentation and debugging, but you're free to use each panel as you choose. To create a game, make sure one side has 'Source' selected, and type:
"Wretched Exchange" by "Anonymous Penguin" When play begins:
say "[italic type]It's one of the hottest days of the year. You're stuck in the office trying to get OpenExchange installed on to one of the crusty old Linux servers, and you can't leave until the CEO's Blackberry starts whirring with new email."
The Office is a room. "Why do all offices look alike? There's the low-slung polystyrene ceiling, complete with ambient lighting, and various desks and chairs littered across the lino floor tiles. The server room is to the north and an emergency exit to the south."
This is all you need to create a working title. Gnome Inform knows how to parse this data automatically, taking the title and author from the first line, and the intro text that follows 'When play begins:' But the most essential part of this code is the room description, as locations such as this are the core components within a text adventure. Inform automatically extracts the room description and is able to work out that the server room is to the north while the emergency exit is to the south from the natural language in the description.
Rooms aren't much good without objects, and you can add one to the office atmosphere with the following lines:
A coffee cup is here. The description is "On the inside, the cup is stained black by years of caffeine addiction. The outside sports the image of a penguin."
After taking the cup:
say "Taken. You sure wish you could find some fresh coffee."
After dropping the cup:
say "Dropped. So much for getting a caffeine hit."
In this chunk of text, we're saying there's a coffee cup in the room as well as defining a couple of actions - taking and dropping. Both of these are automatically understood by the parser, but there are going to be times when the parser doesn't understand an action, and in those cases you'll have to create your own. In the server room to the north, we're going to place an air-conditioning unit, and create a new action that activates the unit and solves the game.
The Server Room is a room. It is north of the office. "It's difficult to hear yourself think in here. Racks of servers are humming away, filling the air with an acrid damp humidity."
An air conditioning unit is here. The description is "Attached to the wall, this yellowing unit seems to have been bought on the cheap from the local Pub after the smoking ban made it redundant. Water is dropping from the unit on to the floor."
Activating is an action applying to one thing. Understand "activate [something]" as activating.
Before activating the air conditioning unit:
say "Wow! You turn on the unit and the servers gradually stop complaining.";
end the game in victory.
You can now run the game and complete it by going north and activating the air-conditioning unit. It's a ridiculously simple solution, but you should be able to see the massive potential in the natural way a game can be created. It's designed to feel much like reading a book, and the results can be fantastic.

Make sweet music

Time it takes: 30 minutes

You shouldn't need any training or musical skill to make music - all you need is the ability to tell the different between what you like and what you don't. We're going to prove this point by creating a piece of music using nothing but the mouse cursor and a single Linux application - Rosegarden. From Rosegarden, you can create drum tracks, melody and chords, all played through internal instruments, and save the output to a file.

Getting started

Rosegarden uses Jack to talk to your audio hardware and other audio applications, so you'll need to include QjackCtl when you install the packages. We also installed as many DSSI synthesizers as our package manager could find. QjackCtl is the GUI front-end to Jack, and you'll need to launch this before starting Rosegarden. We've had best results restarting the machine, opening QjackCtl, clicking on the Setup button, disabling the real-time checkbox, setting the sample rate to 48000, clicking OK and then clicking Start. This should work for the vast majority of audio hardware, and when Jack is running you should see 'Started' in the QjackCtl window. You can now safely launch Rosegarden.

Create something

We're going to start with the bass track. Make sure track number one is selected within Rosegarden, and, in the Track Parameters panel on the left, use the Device drop-down menu to select Synth Plugin (this configures the track to use one of the DSSI synths we installed earlier). In the Instrument Parameters panel below the Track Parameters, click on the 'No Synth' button. This will open a new window asking for the DSSI synth to load into slot one. The synths that are listed will depend on what you've installed, but we've opted for the XSynth plugin. If that's not available on your distribution, try something else. A synth parameter window will open, but you'll need to close this for the moment.
Back at Rosegarden's main view, make sure the pencil icon is enabled in the toolbar and draw a couple of new bars on the first track. A long block of yellow should appear. Now right-click on this block and select Open With The Matrix Editor. This will open a new window into which you can point and click to add notes to play on the synth. Click on the piano keyboard on the left of the matrix to preview the note, then click in the matrix to add notes. Drag the right border of notes to alter their duration, and if you enable the 'Show Velocity Property Ruler' from the View menu you'll be able to change the volume of each note by dragging the orange blocks that appear.

Put it all together

Now close the matrix editor and enable the loop icon in the transport window, then use the right arrow next to the loop icon to extend the white looped area around the block of notes, and press Play. Your notes will now play back in a loop, and you should go back to the track properties panel for that track, click on Editor, and tweak the sound assigned to the synth.
After this, it's a matter of repeating the process for several more tracks, using different sounds and clicking on a different selection of notes. If you keep looped playback running in the background, you'll be able to gradually build the complexity of the track. At that point, copy and paste the blocks of notes on each track, and move them horizontally to build a whole song.

Step by step: Export audio

1. Launch Audacity, open the Edit, Preferences windows and change the recording device to Rosegarden, then press Record.
2. Switch back to Rosegarden, make sure the cursor is at the beginning of the track and click on Play .
3. Go back to Audacity. You should see the project being recorded, and when the playback has finished you can save the file.

Build a media server

Time it takes: 120 minutes     

Linux is brilliant at serving files. It's this ability that keeps the enterprise world turning to Linux for its heavy lifting jobs and that keeps the world Googling 24/7. But it's just as good at serving files from a computer tucked away under the stairs or stuck in the loft, and a server in your house is now becoming an essential accessory. Mobile phones, games consoles and even televisions are rapidly developing the ability to read, display and play files held on a media-centre PC, and Linux is the perfect free software solution. All you need is a relatively low-powered PC, a decent amount of storage and somewhere safe to hide it.

Install the software

We've chosen to use Ubuntu Server Edition for two reasons. First, it's the same distribution that most people know and love, only optimised for use on a server. Second, you still have access to exactly the same packages and repositories as you do with with the desktop version, which makes installing and using software easy.
Put the disc into the machine you want to use as the server and select your language followed by 'Install Ubuntu Server'. Unlike the desktop version, there's no graphical installer. Instead you'll need to choose your configuration settings from the pages of options that appear throughout the installer. Don't let this put you off; there aren't any questions that can't easily be answered, and the installation is effectively no different from a standard desktop installation. The first question asks you again for the language, the second for your location and the third for your keyboard layout. After a brief pause, you'll be asked for a hostname. You might want to change this to something like 'mediaserver', rather than the default 'ubuntu' to avoid confusion with any other Ubuntu installations you may have running on the same network.
When MediaTomb is running, you can add files and folders to your media collection through the web interface.
When MediaTomb is running, you can add files and folders to your media collection through the web interface.

Partition the disk

The next installation step is disk configuration. This is a much more important consideration for a media server than it is for a standard desktop installation, because of the sheer volume of files that you'll be storing on it. The most convenient solution is to use an old disk of around 10GB (or less) for the Linux installation and a high-capacity drive for your media content. You can then select 'Guided - Use Entire Disk' on the installation page, then select the disk for the installation and give Ubuntu complete control over how it creates the installation. Your media storage disk can be configured later.
The second-best option is to create two partitions on a single drive, using the smaller partition for the root filesystem and the other partition for your data. This way, you can update the root partition if you need to, or easily back up your data partition without infecting it with system files. After skipping through the partition section you'll be asked for your real name, username and password. You should give this a little more thought than with the desktop, as it's likely that your server will be on all the time and accessible from the internet, so a secure username/password combination is vital. Press Continue to skip the HTTP proxy installation, and choose to install security updates automatically when asked. Finally, don't select any of the default server packages unless you want to enable SSH for remote administration then click on Continue to install the system.

Configure MediaTomb

We're now only a couple of steps away from a completion. When your machine restarts after installing all the main packages, you need to log in and type sudo apt-get install mediatomb into a terminal. This will grab the media-streaming software and install it on your system. All you need to now is type mediatomb to run the server. Watch the output, because you should see something like the following:
2009-07-16 15:20:52    INFO: MediaTomb Web UI can be reached by following this link:
2009-07-16 15:20:52    INFO: http://192.168.1.89:49152/
This is the port and the IP address for the server, and you should now be able to point a web browser on the same network at this address and use the simple user interface to add the files and folders that contain your various bits of media. After a few moments, the media should appear on any UPnP streaming client, such as those on a Playstation 3 and XBox 360.

Host a photo album


Time it takes: 60 minutes
There are plenty of online services that offer to host your photos for free, and sites like Flickr and Picasa are excellent tools for expanding your online social presence. But for most of us, they're not ideal for sharing personal photos with family and friends. Even when they offer password-protected collections with restricted access, sometimes you want to keep your own photos closer to your own storage. So why not host your own photo collection?
The software we've opted to use is called Zoph. It's built using PHP and a MySQL database, and enables you to import your collection of photos through a Zip or Tar file, organise them into albums, set attributes for author and geographical location, and share them with your friends and family.
Zoph is a comprehensive photo management application that runs on HP through a web browser.
Zoph is a comprehensive photo management application that runs on HP through a web browser.

Install the software

Taking Ubuntu 9.04 as a base, you need to install Zoph from the package manager, and this in turn will install the several Apache 2 dependencies, which is all we'll need for a working web server. You will also need to search for and install the mysql-server package to grab the database back-end, and the installer will ask you for a password to protect the root MySQL account. Remember this password, because you'll need to enter it after typing the following two lines on the command line. The first will create the database that Zoph uses to store the photo information, while the second will import the default table data provided by the Zoph package install into the MySQL server:
mysqladmin -u root -p create zoph 
mysql -u root -p zoph < /usr/share/doc/zoph/zoph.sql
If you're using a distribution other than Ubuntu, there's a chance that the zoph.sql file could be in a different location. Your distro's package manager can tell you where if you look at what and where has been installed with the Zoph package.

Configuration

The next step is to set up the permissions for the database we've just created. Log into your MySQL server by typing mysql -u root -p, and type these two lines, replacing password with your own password.
grant select, insert, update, delete on zoph.* to zoph_rw@localhost identified by 'password';
grant all on zoph.* to zoph_admin identified by 'password';
All we're doing here is creating a MySQL user account called zoph_rw and giving it the permissions required to read and write to the database. Zoph expects to find this account, and you next need to tell Zoph what password you've allocated to the zoph_rw user. You can do this by editing /etc/zoph/config.inc.php and changing password in the following line:
define('DB_PASS', 'password');

Sharing photos

That's all there is to the configuration. You should now be able to point a browser running on the same machine to http://localhost/zoph, which will in turn redirect you to a login page. Enter admin for username and admin for the password, and you'll find yourself within Zoph running on your own web server. The first thing you'll want to do is import your own photos, and this can be done by clicking on the Import button at the top of the screen. You can then select photos individually, or archives of photos within Zip or Tar files if you want to upload a folder or collection. Each upload can be given a description, and you can also create locations and photographer accounts, which can then be attributed to each import. This information can make a larger collection easier to navigate, but it's not necessary.
After adding your photos, you can browse them by switching to the 'photos' page or, if you've sorted them into albums, the 'albums' page. You can now share your photos with anyone else who can access your LAN by giving the IP address of your machine (or the hostname if there's a DHCP router sitting at the heart of your network). If you want to access your site from the internet, you need to make sure port 80 is forwarded from your gateway or access point to the machine running Zoph. You can then use the IP address of your internet connection from elsewhere on the internet, but you'll need to make sure that you keep Apache up to date on that machine. You can limit who can see your photos by creating user accounts for those people, and limiting those accounts to groups of photos if you need to to.

Saturday, 2 August 2014

GNU Screen Tips and Tricks

Throughout the text I will use this C-a for the shortcut of Ctrl+a and C-d for Ctrl+d. I’d like to emphasize that C-a A (Ctrl+a and next A) and C-a a are two different shortcuts :) . I will also refer to the program simply as “Screen”, not GNU Screen, for simplicity reasons.1. Quick start

To create a new terminal session just enter the command screen. It will grant you the access to, what appears at first look, to be an unchanged shell. But in fact there are many useful features a key sequence away. But let’s start from the begining :)
In the new shell, you can do the same things as in a normal terminal. When you want to shutdown the screen, you press the combination C-d. If you want to leave programs opened inscreen running after logout, you have to press C-a d before. Then the text [detached] will appear on the display, what means that screen is running in the background, and you can log out knowing that all your programs are still functioning. When you want to reenter the screen session, type screen -r. You can have more than one screen session, detaching from active ones and creating new ones. But to reattach to any of detached session, you have to know its PID (Process ID), or name. To see running sessions type screen -list. The first column contains the PID of each session. To restore a session type screen -r [PID]. But it is very inconvenient to remember or list these numbers every time you want to reattach. Fortunately you can use the “-S” switch. With its help you can give a name to each session when creating it. To create a session named “wget” you type screen -S wget. This makes it far easier to get back to any session. Just enter screen -r wget and it’s done.

2. Running programs in the background

Sometimes it would be useful to make screen automatically open a program in its session, give it a name and detach returning to a normal shell, in one command. Use the “-md” options to do this. Combining this with the “-S” option gives some interesting effects:
screen -S ekg_session -md /usr/local/bin/ekg &
Screen will create one session, name it “ekg_session”, start the ekg program running inside it and then detach it. Using this method, checking your account on a unix server, you can have either online or “away from the computer” status all the time by one command, while doing other things on the server. Naturally, you can combine many commands into a single command, which makes returning to your work environment easier:
screen -S ekg -md /usr/local/bin/ekg & screen -S mc -md /usr/bin/mc & //
screen -S rtorrent -md /usr/bin/rtorrent &
This makes screen create three differently named sessions in the background with my favourite terminal programs – ekg, mc and rTorrent.

3. Regions and tabs.

Even though running multiple screen sessions is catered to, its creators give you another choice of how to work. You can run multiple shells within one session! What’s more, you can even display these shells in one terminal window.
But so as not to get lost in these windows, I suggest you create tabs similar to those found in web browsers. You can do this by writing to your configuration file ~/.screenrc one of the following codes:
hardstatus alwayslastline      
hardstatus string '%{= mK}%-Lw%{= KW}%50>%n%f* %t%{= mK}
%+Lw%< %{= kG}%-=%D %d %M %Y %c:%s%{-}'
or
hardstatus alwayslastline
hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{= kw}%?%-Lw%?%{r}
(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m 
%{W}%c %{g}]'
or
hardstatus alwayslastline
hardstatus string '%{gk}[ %{G}%H %{g}][%= %{wk}%?%-Lw%?%{=b kR}
(%{W}%n*%f %t%?(%u)%?%{=b kR})%{= kw}%?%+Lw%?%?%= %{g}][%{Y}%l%{g}]
%{=b C}[ %m/%d %c ]%{W}'
With the first code each tab will have a number, a name plus time and date. The second one will give you tabs that will be created in the center and the active tab will be highlighted in red and also have the hostname displayed. The last code will additionally display the processor usage. You can create your own codes but it is a rather specialized task – I refer you to the system manuals for more information.
You already have tabs, now it’s time to create new terminals.
Open a screen session then press C-a c. A new tab is created. But both tabs have the same title. To change the title of the active tab, press C-a A and enter a new name. Creating tabs without a shell but with a program running automatically is a useful feature. The new tab will inherit the name of the program. To use this option press C-a : and enter the following command screen [program name] (this is the way you enter all commands during the screensession). To go to the next tab press C-a n and to return to the previous one press C-a p. To switch between the tabs use C-a ". This will show you a list of all the tabs.
Regions
Regions are a very useful feature. They enable opening many programs and shells in one window of screen. To do it just press C-a S. The window will split into two separate areas. There will be your actual shell at the top part of the window and the bottom part will be empty. To switch to the bottom part press C-a [Tab]. You have to create a new shell in the new window, so pressC-a c. You can create more regions by pressing C-a S more than once and creating new shells in them. Tabs display the active region shellname in its titlebar. You can also switch between tabs being in a region, so e.g: you have 4 tabs and 2 regions. Each region can display one of these tabs. A nice trick is that many regions can display the same tab and they will react simultaneously. It is difficult to describe but is very helpful when you work in multiuser mod and you want to see what another person is doing. You can change the size of each region by entering resize [size], where size is the number of lines.
Two windows filling whole the display with screen splitted into two regions
Img. 1 Two windows filling whole the display with screen split into two regions

4. Configuration file

Previously I mentioned about the configuration file. I wrote that it is in a subdirectory in the home directory named ~/.screenrc. But you can have tens of such files, and when you want to use any of them run screen with the option -c [filename]. What these files can be? Simply it can contain any of the commands that you usually enter after pressing C-a :. Below I include one of configuration files which causes splitting a window into two regions and running ekg in the top one.
  • screen ekg — runs ekg
  • title ekg — gives title to the window
  • split — splites window into two regions moving ekg to the top one
  • focus — switches to the bottom region
  • screen — runs default shell, in my case it is bash
  • title bash — sets title to the bottom region
  • focus — switches back to the top one
As you can see, you can automate a lot of actions which you would do after connecting to a server or running a terminal. A full list of commands can be found in the manual.

5. Logging to file.

To log all the data displayed in a screen session or tab into a file, enter the following command:
  • logfile [filename] where filename is the name of the file where all the data will be logged. The default name is screenlog.0 (or 1,2,3… if there are more screen shells).
  • flush [seconds] is used to set delay between each write to the logfile, by default it’s 10 seconds.
  • To start logging enter log on, to stop log off.

6. The password to screen session.

If there is an important program running in a session you can protect it by using a password. To do this enter password. Then you will be prompted to type your password twice.
After that the hashed password will be displayed. Next you have to copy it to the configuration file after the word “password” in the same line. To cancel the password associated with the session just enter password none in the session or delete the line from the configuration file to cancel the password permanently.

7. Screen running right after connecting to a remote host.

In fact this tip has not much in common with screen but still I think it is very useful. If you want to run screen right after connecting to a remote host just enter ssh [username]@[remote host name] -t screen -RD. Unfortunately this command will work only if there is only onescreen session running on the remote host. If there is more than one session you have to know its PID or name and use this: ssh [username]@[remote host name] -t screen -R [sessionname/PID]. When you shut down the screen, SSH will automatically log out.

8. Locking the display.

To lock the display use the following command lockscreen or the shortcut C-a x. It doesn’t block the session (like it was in point no. 2), but only “freezes” the display. So detaching and attaching again will cause that you grant the access to session. It can be useful when you are connected to a remote server using the previous tip and you have to go away from the computer. You can’t change the password, because your own user password will be used.

9. Comments

I think these tips will be useful for you. I have been using screen for a long time without knowing about such things as regions, tabs and all features I described here.

55 Best Linux Tips, Tricks And Command Lines


 
55 Best Linux Tips, Tricks And Command Lines

Here we bring to you the 55 best tips, tricks and command lines of all time contributed by our readers. Try your hands and have fun.

If you are a Linux user and open to having some fun with your open source operating machine, then this is a must-read article for you. Here is a compilation of 55 tips, tricks and command lines of all time, enough to keep you equipped. Have a look:
1. Back-up and restore Thunderbird e-mails
In Linux, when you want to reinstall your system for any reason, you need to take a back-up of your data along with your e-mails in Thunderbird. Given below are a few simple steps that back-up e-mails manually.
Check for your Thunderbird e-mail and profile folder. If you have not changed it, it should be in /home//.thunderbird/.default_folder/
For example, the alphanumeric folder name on my system is vx3vg9j2.default
Copy the whole alphanumeric folder and place it in some other computer or storage device as an e-mail backup. Do remember to close Thunderbird before doing this.
After reinstalling your PC with any Linux-based OS, install the Thunderbird e-mail client and configure your e-mail credentials before closing the Thunderbird client.
Go to your Thunderbird folder in the new installation /home//.thunderbird/ folder. The alphanumeric named folder will be a different one now.
For example: /home/guest/.thunderbird/jx3gv9k2.default
Copy the contents of the old alphanumeric folder that is kept as a backup to the above location.
That is, you need to copy the contents of vx3vg9j2.default to jx3gv9k2.default
Now, open the Thunderbird client and you will find that all the e-mail credentials, e-mails, e-mail rules and address book will be available as they were before re-installation.
--Sobhanadri Agnihotram,
sobhanadri.a@gmail.com
2. Execute commands on a remote Linux machine
If you want to execute any command or script on a remote Linux machine, you can use ssh. Below are a few examples.
The syntax for running a command or script on a remote server is:
ssh [USER]@[IP] [command or script]
Let us look at how this can be done. Suppose you want to display the directory contents of /root of a remote host, you can run the following command:
[narendra@ubunu]$ ssh root@172.16.223.128 ls -l /root
root@172.16.223.128's password: 
total 12
drwxr-xr-x. 2 root root 4096 Mar 12 00:05 device_drivers
drwxr-xr-x. 2 root root 4096 Mar 12 01:31 pthreads
drwxr-xr-x. 2 root root 4096 Mar 12 01:32 python
[narendra@ubunu]$
The same can be done to run any script on the remote computer.
--Narendra Kangralkar,
narendrakangralkar@gmail.com
3. Run a Linux command after every reboot 
This tip allows you to run any Linux command or script just after system reboot. You can use the @reboot cron keyword.
If you have a script in your /home directory and it needs to be run on every boot, open the cron file in editable mode and add the following:
$crontab -e
@reboot /home/xyz/myscript.sh
Do remember to enable crond on boot.
Imran Sheikh,
imrannsheikh@gmail.com
4. Comment out hashes in large configuration files
Here is a small tip for system administrators, who need to tackle large configuration files, which include lots of commented lines (marked by #). With this tip you can remove all those hashes and provide only an uncommented configuration view for faster lookup into the file.
If you want to check the configuration file of the Squid proxy server, run the following command:
#cat squid.conf | egrep -v ^#
This will show only lines that do not start with a hash mark, thus giving the configuration parameter that is being used in the current set-up.
--Yogesh Upadhyay,
yogeshupadhya@gmail.com
5. Replacing '\n' with 'space' in each line of a file
You can use the awk statement given below to remove the '\n' from each line and replace it with a blank space: 
awk '$1=$1' ORS=' ' /etc/passwd
--Rajeev N Sambhu,
rajnellaya@gmail.com
6. Know your shells
Here is a command that will let you know about the available shells on your Linux distribution:
#chsh -l
To change your login shell, use the following command: 
# chsh
--Chandralekha Balachandran,
reachlekha@gmail.com
Advanced ls commands
The following commands are very useful to know your system better.
lspci – Lists all PCI devices. Use -v for verbose output.
lsusb – Lists all USB devices. Use -v for verbose output.
lsmod – Lists the status of modules in the Linux kernel.
lsattr – Lists file attributes on a second extended Linux file system.
lsof – Lists the file descriptors opened by all the processes. A very useful command when a process fails to close any file descriptors.
To know more details, you can view the manual pages of each command mentioned above. 
--Prasanna Mohanasundaram,
prasanna.mohanasundaram@gmail.com

7. Checking for rootkits 

Attackers install rootkits on a machine to gain root access, while its presence is hidden from the real administrator of the server. A tool that can help you to detect rootkits on your machine is 
chkrootkit. You can download this from ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz
To install chkrootkit, you need to compile the code that you have just downloaded. Extract the downloaded tar file and change to the extracted directory, as shown below:

# tar -xvf chkrootkit.tar.gz

# cd chkrootkit-0.49/

Now compile the code by running the following command:

# make sense


After successfully compiling, the tool is ready to be used. To check for rootkits, simply run chkrootkit as the root user:

# ./chkrootkit

--
Samual, samual45@gmail.com 
8. Finding and replacing a test with sed

Let's look at how to find and replace a test using sed, a stream editor for filtering and transforming text. Let us first create a sample
text file with the following text:

$ cat > sample.txt

This is a first test of sample test file
This is a second test of sample test file

Press Ctrl+D after you finish entering the text.
Now run the command below to display the contents of the newly created text file:

$ cat sample.txt

The output should be as displayed below:

This is a first test of sample test file
This is a second test of sample test file

Now, substitute the first occurrence of the pattern 'test' in each line with 'log':

$ sed 's/test/log/' sample.txt

This is a first log of sample test file
This is a second log of sample test file

If you want to substitute the second occurrence of pattern 'test' in each line with 'log', use the following commands:




$ sed 's/test/log/2' sample.txt

This is a first test of sample log file
This is a second test of sample log file

To substitute every occurrence of the pattern 'test' in each line with 'log', use the code below:

$ sed 's/test/log/g' sample.txt

This is a first log of sample log file
This is a second log of sample log file

The syntax for the above options is:

sed 's/original_pattern/replacement/options'

Also, by default, sed will send the data to the stander output device,
and you can redirect it to any file by using the redirection operator ">".

$ sed 's/test/log/g' sample.txt > mod_sample.txt

--
Jagan Teki, 402jagan@gmail.com
9. Backing up a MySQL database 
There are several methods to back up a MySQL database, one of which is to a command line option. You need to have mysqldump installed for this method.
mysqldump is a command line utility that comes with the MySQL installation It can be used to archive one or all databases.
Given below is the command to back up a single database:
mysqldump --user [user_name] –password=[password_of_the user] [database name] > [dump_file]
The command for back up of all databases in existence is as follows:
mysqldump –u[user name] –p[password] –all-databases > [dump file]
To restore the back up taken by mysqldump, use the normal SQL command.
mysql --u [username] --password=[password] [database name] < [dump_file]
--Manish,
mt81@in.com 
10. How to show the name of the current database in the MySQL prompt
If you need the name of the currently selected database in your MySQL prompt, use the following lines in your MySQL configuration file (my.cnf):
[mysql]
prompt='mysql(\d)> '
Now, when you connect, the MySQL prompt will look like what's shown below:
mysql((none))> use test;
Database changed
mysql(test)> 
mysql(test)> use mysql;
Database changed
mysql(mysql)> 
This makes it very easy to identify the name of the database that you are currently working on.
--Mohana Sundaram N,
mohan.linux@yahoo.com 
11. Find your MySQL configuration file 
We often have to administer a system that has been set up by someone else. In such a situation, it's difficult to find the correct configuration files for different applications. Here is a tip to find the correct configuration file for MySQL:
mysql -? | grep ".cnf"
--Remin Raphael,
remin@smartgeek.in
12. View the contents of tar and rpm files
Here are two simple commands to show you the contents of the tar and rpm files.
1. To view the content of a tar file, issue the following command:
#tar -tvf /path/to/file.tar
2. To view the content of an rpm file, use the command given below:
#rpm -qlp /path/to/file.rpm
--Giriraj G Rajasekharan,
girirajgr@gmail.com
13. Playing around with MP3 files
Here is a tip that helps you cut, split, join or merge MP3 files in Ubuntu, resulting in a better quality output.
To cut an MP3 file, you need to install poc-streamer, as follows:
$sudo apt-get install poc-streamer
The syntax for mp3cut is given below:
mp3cut [-o outputfile] [-T title] [-A artist] [-N album-name] [-t [hh:]mm:ss[+ms]-[hh:]mm:ss[+ms]] mp3 [-t ...] mp3 -o output: Output file, default mp3file.out.mp3
For example, if you want to cut a one-minute clip of the MP3 file named input.mp3 to a .wav file called output.wav, run the following command:
$mp3cut -o output.wav -t 00:00(+0)-01:00(+0) input.mp3
If you want to join two MP3 files, you need to install mp3wrap, as follows:
$sudo apt-get install mp3wrap
The syntax for mp3wrap is shown below:
$mp3wrap merged_filename.mp3 filename1.mp3 filename2.mp3
…where filename1.mp3 and filename2.mp3 are my input files that can be merged together.
Finally, you can split a single large MP3 file into small files by installing Mp3split using the following command:
$sudo apt-get install mp3splt
Now, to split the large file, run the following command:
$mp3splt filename.mp3 00.00 01.23 03.20
Filename.mp3 is my input file, which can be split into two MP3 files. One is from the start to the 1 min 23 sec point, and another one is from 1 min 23 sec to 3 min 20 sec. Mp3split can make smaller files without decoding even the file.
--Rajasekhar Chintalpudi,
rajasekhar.chintalapudi@gmail.com
14. GRUB 2 recovery
We often come across a condition in which the boot loader gets corrupt. Here are a few steps that will help you recover your GRUB 2 boot loader.
Boot from a live CD or DVD, which supports GRUB 2 (Ubuntu 9.10 CD or above. A DVD will take more time than a CD, so I suggest you boot from a CD).
Open the terminal and run fdisk -l to check the partition from which you want to recover GRUB 2.
Here I assume that you want to recover it from /dev/sda1.
Then run the following commands:
$sudo mkdir /media/sda1
$sudo mount /dev/sda1 /media/sda1
$sudo mount --bind /dev /media/sda1/dev
$sudo mount --bind /proc /media/sda1/proc
Now chroot into that partition by running the command given below: 
$sudo chroot /media/sda1
Then re-install GRUB, as follows:
#grub-install /dev/sda
The output should be like what's shown below:
Installation finished. No error reported.
If you get an error, then try the following command:
#grub-install --recheck /dev/sda
After a successful installation, exit from chroot and unmount the file systems that were mounted to recover GRUB. Now reboot.
#exit
$sudo umount /media/sda1/proc
$sudo umount /media/sda1/dev
$sudo umount /media/sda1
$sudo reboot
You've successfully completed recovering your GRUB boot loader.
--Kousik Maiti,
kousikster@gmail.com 
15. Record whatever you do in the terminal
Have you ever felt that you should record everything you do in the terminal in a file?
Then try out the following tip. There is a command named script, which can be used with option –a to append the output to a file.
Given below is an example that will show how it works:
Mandriva~:$ script -a lfy
Script started, file is lfy
Mandriva~:$ uname -a
Linux localhost.localdomain 2.6.33.5-desktop-2mnb #1 SMP Thu Jun 17 21:30:10 UTC 2010 i686 i686 i386 GNU/Linux
Mandriva~:$ uname
Linux
Mandriva~:$ exit
exit 
Script done, file is lfy
Here, the name of the file is lfy. You can verify it later by using the code given below: 
Mandriva~:$ cat lfy
Script started on Mon 16 May 2011 02:09:47 AM EDT
Mandriva~:$ uname -a
Linux localhost.localdomain 2.6.33.5-desktop-2mnb #1 SMP Thu Jun 17 21:30:10 UTC 2010 i686 i686 i386 GNU/Linux
Mandriva~:$ uname
Linux
Mandriva~:$ exit
exit
Script done on Mon 16 May 2011 02:10:32 AM EDT
--Sibi, 
psibi2000@gmail.com 
16. Wonders of VIM
VIM has a very useful command set. Here are a few commands that can be used to increase your productivity.
VIM as a file comparator:
Use '-d' switch to compare two files in VIM. This command splits the VIM screen vertically and shows the differences.
vim -d file1 file2
17.  load new files in separate windows:
If you have a file named 'first.txt' loaded already in VIM, then use ':split second.txt' to load another file named 'second.txt' in a separate window--IM will split the screen horizontally and load the second file. You can use ':vsplit' to split the screen vertically. 'Ctrl+w' can be used to switch between the windows.
18. VIM as a command:
Normally, we use VIM as an editor; however, it can be used as a command. It allows the execution of VIM commands with switch '-c', for example. Here is a command to replace all '>' characters to '>>' in a file FILE.TXT without opening VIM.
vim -c ":s/>/>>/g" -c ":wq" FILE.TXT
19. To open a file in read-only mode:
Use the '-R' switch to open a file in read-only mode; later on, '!' can be used to forcefully write to the file.
--Satya prakash, 
satya.comnet@gmail.com 
20. Check your processor and OS architecture
You might want to install a 64-bit OS on your machine, but the processor might just be 32-bit compatible. Sometimes it happens the other way too, i.e., you install a 32-bit OS on a machine that has a 64-bit processor. Here is how to find out whether the installed OS as well as the CPU are of 64-bit or 32-bit.
Given below is the command that will output the details of the OS installed:
$ uname -m
The result for a 64-bit OS installation (for x86_64 architecture):
x86_64
The result for a non-64-bit OS installation (for i686 architecture):
i686
To know about the processor, run the following command:
$ lshw -class processor | grep width
Shown below is the result for a 64-bit installation:
width: 64 bits
The result for a 32-bit installation:
width: 32 bits
Note: Please install lshw if it is not already installed on your system
--Srikanth Vittal,
vi.srikanth@gmail.com 
21. Sudoing with Fedora 
Ever felt tired of entering the super-user password after typing 'su –c' again and again? Type 'su -c visudo' just once and uncomment the following line:
# %wheel ALL=(ALL) ALL
Replace 'wheel' with your sudo username. So if the username is egghead, the line becomes…
%egghead ALL=(ALL) ALL
Save and quit. You're good to use egghead as the sudo user.
--A. Datta, 
webmaster@aucklandwhich.org 
22. Let your Linux system welcome you
Issue the following script and name it welcome.sh 
echo "Hi zades you are welcome today is " | festival --tts
date| cut -d" " -f 1-3 | festival --tts 
Now put the command sh welcome.sh at start-up. This will allow the script to run every time you log in to your system. Once done, restart your system to hear the message that is written in the Echo command. 
The festival command is used to change the text to voice. You can use this command in many ways according to your creativity. Do remember to check that you have festival installed before trying this tip.
--Vinay Jhedu,
vinay.komal100@gmail.com 
23. Ignoring the case during TAB-completion
By default, TAB-completion is not useful if the name of the file or directory starts with an uppercase. You can make your Shell totally ignore the case for the name by adding the following entry in /etc/inputrc: 
set completion-ignore-case on
Then restart your Shell. From now onwards, TAB-completion will complete your file or directory name, and completely ignore the case.
Do remember to make changes to inputrc only as the root user.
You can read more about this in the manual pages of readline:
man readline
--Sachin P,
iclcoolster@gmail.com
24. Find your OS and distribution name
Here is a tip that will let you know the name of the OS, along with other details:
[root@vl-pun-blg-qa27]# lsb_release -a
LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: CentOS
Description: CentOS release 5.5 (Final)
Release: 5.5
Codename: Final
--Narendra Kangralkar,
narendrakangralkar@gmail.com
25. Auto mounting a partition on Linux
The file that contains data regarding the devices to be mounted at start-up is in /etc/fstab. To automatically mount a partition, follow the steps given below.
First, create the directory in which your partition will be mounted. Create one directory per partition. I created the directory in /media. This directory is known as the 'mount point' for the partition.
To create the mount point, open up the terminal and type the following command:
sudo mkdir location_of_dir/name_of_dir
…or you can use Nautilus, the file manager, to create a folder.
If the directory is created in a location in which you need root privileges, use sudo. After creating the mount point, modify /etc/fstab as per your requirements. It is always advisable to create a backup of the /etc/fstab file before making any changes, because any error in that file can prevent your OS from booting.
Now, make changes in fstab to auto mount the HDD partition:
sudo gedit /etc/fstab 
Open the /etc/fstab with a text editor of your choice with root privileges.
In this file, add the details in the same order as done for the existing partitions.
The order should be as follows: the device name, the default mount point, the file-system type, mount options, dump, and the fsck option.
The device name is the name of the HDD partition (such as /dev/sda5): the mount point is the full path of the directory where the partition is to be mounted. The file system type is the type of file system like ext4, fat, ntfs, etc. Mount options are normally given as defaults, while dump and fsck options are given as 0.
I had a partition /dev/sda5 and I created the directory /media/mydisk. My partition was of type ext4, so to my /etc/fstab, I added the following command:
/dev/sda5 /media/mydisk ext4 defaults 0 0 
Save the file and in the command prompt, type the following:
sudo mount -a
Now, the partition will be automatically mounted on every reboot.
--Vineeth Kartha,
vineethkartha@ieee.org
26. Creating a virtual file system
Here is a simple tip that allows you to create a virtual file system and mount it with a loopback device. 
STEP 1: First create a file of 10 MB using the following command:
$ dd if=/dev/zero of=/tmp/disk-image count=20480
By default, dd uses a block of 512 so the size will be 20480*512
STEP 2: Now create the file system as ext2 or ext3
Here, in the following example, let's use ext3 as a file system:
$ mkfs -t ext3 -q /tmp/disk-image
You can even use Reiser as a file system type, but you'll need to create a bigger disk image. Something like what's shown below:
$dd if=/dev/zero of=/tmp/disk-image count=50480
$mkfs -t reiserfs -q /tmp/disk-image
STEP 3: As the final step, create a mount point and mount the file system:
$ mkdir /virtual-fs 
$ mount -o loop=/dev/loop0 /tmp/disk-image /virtual-fs
Note: If you want to mount multiple devices, you will have to increase the loop count as mentioned below:
loop=/dev/loop1, loop=/dev/loop2,... loop=/dev/loopn
After you complete the above steps, you can use it as a virtual file system. You can even add this to /etc/fstab to mount this virtual file system whenever you computer is rebooted.
Open your /etc/fstab in a text editor and add the following:
/tmp/disk-image /virtual-fs ext3 rw,loop=/dev/loop0 0 0
--Aarsh S Talati,
aarshstalati1989@gmail.com 
27. Identify your current shell name
You can identify your current shell name by using the following commands:
[narendra@CentOS]$ echo $SHELL
/bin/bash
The "SHELL" environment variable stores the name of the current shell.
You can also use the command given below to get the shell name:
[narendra@CentOS]$ echo $0
bash
"$0" will print the name of the program; here the program name is 'current shell'.
--Narendra Kangralkar,
narendrakangralkar@gmail.com 
28. Scan open ports
The command given below will scan all the open TCP ports on the loopback interface:
nmap -sS -O 127.0.0.1
In general, you can use the following:
nmap -sS -O 
To scan open UDP ports in the system, use the command given below:
nmap -sU -O 
--Prasanna,
prasanna.mohanasundaram@gmail.com 
29. Rev up!
As *nix sysadmins, we need to do a whole bunch of text-based data processing, either in files or data streams.
Here is a shell command called rev that I came across and wanted to share with you geeks because I really liked it and found it useful.
The rev command utility reverses the order of characters in every line. In short, it creates a mirror image. The most common use of rev is to reverse the line, extract a particular string and then pipe through rev a second time to restore the original.
So, if I want to get the year mentioned at the end of a string, this is what I will do: 
$cat fileinfo.txt
Last Changed Date: 2011-08-11 18:10:08 -0500 Thu, 11 Aug 2011
$cat fileinfo.txt | rev
1102 guA 11 ,uhT 0050- 80:01:81 11-80-1102 :etaD degnahC tsaL
$cat fileinfo.txt | rev | awk '{print $1}'
1102
$cat fileinfo.txt | rev | awk '{print $1}' | rev
2011
Voila! Got the year! This is just one workaround, out of the many ways of doing this same task. After all, it doesn't hurt to learn something new.
--Ram Iyer,
ramiyer1@gmail.com
30. Increment or decrement a number present in Vim editor 
This tip will increment and decrement a number in Vim editor. To increment, use Ctrl+A and to decrement, use Ctlr+X.
The following example will explain it further.
Let's suppose a number, 5, is present in the file that is being edited in Vim editor. Now, if you need to increment or decrement the number by 1, place the cursor on the digit and press Ctrl+A to increment it (i.e., it becomes 6); if you press Ctrl+A again, 6 becomes 7, and so on. In the same way, if you press Ctrl+X, the number will be decremented by 1.
If you press 8 and then press Ctrl+X, the number will be decremented by 8. Similarly, pressing 12 and then Ctrl+A will increment the number by 12.
--Adithya Kiran Gangu,
adithya.kiran@gmail.com 
31. Search and delete files from a folder
If you want to delete all the .lock files from a folder, use the following command:
find -name *.lock | xargs rm -rf
This will find all the files with the .lock extension and delete them. This can be done for any files that you need to delete.
--Mridhul,
mridhul@live.com 
32. Get the right information easily
Newbies exploring GNU/Linux sometimes find it difficult to get the right information about a device that is not working. Yet, this information is required to make the device work. Here is a command that gives you the details of all PCI devices and the kernel driver that is associated with them.
Open the terminal and log in as the root user. Now run the following command:
lspci -k
lspci gives you the information about the PCI buses and also the devices connected to them, and the -k switch displays which kernel module is handling the device. So if it is missing on some device, you need to install the driver for that device.
--Pankaj Tanwar,
pankaj.tux@gmail.com 
33. Number conversion in the Vim editor 
Here is a tip that will let you convert hexadecimal numbers to decimal numbers and vice versa in the Vim editor.
To convert hexadecimal numbers to decimal numbers, you need to type the following in the Vim editor's command mode:
:echo 0x111
Press Enter and you will get the result:
273
You can even try the command given below to convert the number:
:echo printf ('%d',0x111)
273
Now to convert decimal numbers to hexadecimal numbers…
:echo printf ('%x', 273)
111
You can even perform simple arithmetic on Vim's command prompt as given in the example below:
:echo printf ('%x',273-173)
64
:echo 0x111-0x10
257
--Adithya Kiran Gangu,
adithya.kiran@gmail.com
34. Know the libraries used by a program
Here is a tip that will help you know what shared libraries are being used by a program.
For example, to figure out exactly which libraries are used by ls, run the following command:
ldd /bin/ls
The output will be a list of all shared libraries:
linux-gate.so.1 => (0xffffe000)
libselinux.so.1 => /lib/libselinux.so.1 (0xb786c000)
librt.so.1 => /lib/librt.so.1 (0xb7862000)
libcap.so.2 => /lib/libcap.so.2 (0xb785c000)
libacl.so.1 => /lib/libacl.so.1 (0xb7852000)
libc.so.6 => /lib/libc.so.6 (0xb76e4000)
libdl.so.2 => /lib/libdl.so.2 (0xb76df000)
/lib/ld-linux.so.2 (0xb78a4000)
libpthread.so.0 => /lib/libpthread.so.0 (0xb76c4000)
libattr.so.1 => /lib/libattr.so.1 (0xb76be000)
--Aarsh S Talati,
aarshstalati1989@gmail.com 
35. Use YUM to download a package
Often, you need to download rpm packages without installing them on the system that you are using to download it. Using the normal YUM command downloads the packages and also installs them on your computer. Here is an option that will only download the rpm package for you. It will download it in the folders specified in the '--downloaddir' option.
# yum update httpd -y --downloadonly --downloaddir=/opt
Now, you can install all rpm packages in this folder by running the following command:
# rpm -Uivh *.rpm
Do remember to run these commands as the root.
--Pratyay Modi,
pratyaymodi@gmail.com 
36. Resolve FSCK failed error 
Sometimes, while booting your Linux system, you may come across the error shown below:
FSCK failed. Please repair manually and reboot. The root file system is currently mounted read-only. To remount it read-write do:
bash# mount-n -o remount,rw /
Attention: Only CONTROL-D will reboot the system in this maintance mode. shudown or reboot will not work.
Give root password for login:_
Provide your root password and try the following command: 
mount -n -o remount,rw /
If this does not work for you, reboot your system and do a manual file system check on your root partition as follows:
umount /dev/hddXXX
fsck -CV /dev/hddXXX
…where hddXX is the root partition.

--Abhishek Chib,
abhishek.chib@gmail.com
37. Undo your changes even after quitting the VIM editor
As all of us know, if you make changes in a file using VIM editor, the changes are permanent and you cannot get the old version back after you save and quit the editor.
But VIM v7.3 allows you to get the old version back even after quitting the editor.
Here is a tip that shows you how to configure VIM to remember changes.
To enable Undo, execute the following commands in VIM just before starting to edit the file.
:set undofile
:set undodir=/tmp
This is to be done every time you start editing a file. In case you need the configuration to be there for all files that you open in VIM, create a file called '.exrc' or '.vimrc' in $HOME directory. In my case, it is /myhome. 
Open the just created file and add the following commands:
# vi /myhome/.exrc
set undofile
set undodir=/tmp
Save and close the file.
:wq
From now onwards, the Undo history is maintained in the background for all files that you edit with VIM. 
--Adithya Kiran Gangu,
adithya.kiran@gmail.com
38. Using 'vi' commands on your terminal 
Using 'vi' commands while working on the terminal is a good work enabler. To set your terminal to 'vi' mode, you need to use the following command:
set -o vi
Now you can use the command mode and the insert mode of 'vi' while working on the terminal.
--Dipjyoti Ghosh,
dipjyoti.ghosh@gmail.com 
39. Get your IP address
Here is a one line command to fetch all the IP addresses (except localhost) of your computer:
# ifconfig | grep "inet addr:" | awk '{print $2}' | grep -v '127.0.0.1' | cut -f2 -d:
Note: Use the above command as the root user.
--Balkaran Brar, 
balkaran.brar@gmail.com
40. Make your system speak for you! 

You can make your system speak for you by using the Speech Synthesizer command normally available in Ubuntu and many other distributions of Linux.
To do so, issue the following command:

# espeak "hello how are you"

You will hear a voice speaking for you.
To change the pitch of the voice, you can issue the following command in the format shown:

# espeak -p 80 "hello how are you"

…(default being 50)
Issuing the following form of command will control the speed of the speech, in terms of words per minute:

# espeak -s 80 "hello how are you"

There are more interesting options available in the man pages.
--
Sanjay Goswami, 
sanjaygoswamee@gmail.com 
41. Measuring the network throughput between two Linux systems 

Iperf is a tool that measures the bandwidth and the quality of a network link. It can be installed very easily on any Linux system. One host must be set as the client and the other one as the server. Make sure that iperf is installed on both systems. If it is not installed, then use your package manager to install it before trying this tip.

Now run iperf on one of the Linux systems as the server, as shown below:

linux-erv3:/home/test/Desktop # iperf -s

------------------------------------------------------------
Server listening on TCP port 5001

TCP window size: 85.3 KByte (default)
------------------------------------------------------------

Go to the second Linux system and run iperf -c as the client:

linux-6bg3:~ # iperf -c 192.168.1.100

------------------------------------------------------------
Client connecting to 192.168.1.100, TCP port 5001
TCP window size: 16.0 KByte (default)
------------------------------------------------------------

[ 3] local 192.168.1.109 port 39572 connected with 192.168.1.100 port 5001

^C[ ID] Interval Transfer Bandwidth

[ 3] 0.0- 6.3 sec 6.38 MBytes 8.51 Mbits/sec

By default, the iperf client connects to the iperf server on the TCP port 5001 and the bandwidth displayed by iperf is the bandwidth from the client to the server. In the above example, it is 8.51 Mbits/sec between two Linux test systems connected over a wireless network.

--
Prasanna,
prasanna.mohanasundaram@gmail.com
42. Print a file with line numbers 
If you want a file with line numbers (say for printing), you can use the 'nl' command in Linux:
$ nl file.c 
This prints the file with line numbers to standard output or this can be even redirected to a 
file as shown below:
$nl file.c > output.txt
Here, output.txt will have the codes of file.c with each line having a line number.
--Phaniram Vallury,
ramvvs@gmail.com 
43. Cut specific logs 
If you need to cut specific logs from the complete log of any application, here is a tip that will 
be of help.
Open the log file in a vi editor and set the editor to display the line number:
vi server.log
:set nu
The above process will provide you the line numbers in the logs. You can then search for 
the specific string and note down the line number (e.g., 550). Now, note down the last line 
number by using Shift+G (e.g., 780)
sed -n 550,780p server.log > threaddump.log
So the threaddump only contains lines from 550 to 780.
--Venkatesh R,
venka.2k@gmail.com 
44. Reset ifconfig counters 
As you can see, ifconfig keeps a couple of counters (RX/TX packets, RX/TX bytes, errors, 
dropped, overruns, frames and carrier collisions). You can quickly spot if there is a problem by 
just looking at the ifconfig counters:
#ifconfig eth0
eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4233700943 errors:2 dropped:0 overruns:3 frame:5
TX packets:1917219659 errors:1 dropped:0 overruns:0 carrier:348
collisions:5753 txqueuelen:3000
RX bytes:1467520026 (1.3 GiB) TX bytes:2299240337 (2.1 GiB)
You can now find out what driver is being used by the network interface, which you want to 
reset by using ethtool.
#ethtool -i eth0
driver: e100
version: 3.4.14-k4-NAPI
firmware-version: N/A
bus-info: 0000:01:07.0
# modprobe -r e100; modprobe e100; ifup eth0
This will reset all counters.
--Vinod Rana,
rana3807@gmail.com
45. Power yourself with Netstat 
Here are a few uses of the netstat command that can help you.
To display the kernel interface table:
netstat -i
To display the kernel routing table:
netstat -rn
To display all open network sockets:
netstat -uta
To display network statistics:
netstat -s
--Prasanna,
prasanna.mohanasundaram@gmail.com 
46. Finding the full path of the shell command
There is a command named which that takes one or more arguments as input. It prints to standard output the full path of the shell command. It does this by searching for an executable or script in the directories listed in the environment variable PATH:
[aarsh@localhost ~]$ which poweroff
/usr/bin/poweroff
If the command is not found, it gives the output shown below:
[aarsh@localhost ~]$ which moodule
/usr/bin/which: no moodule in (/usr/lib/qt-3.3/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/aarsh/bin)
--Aarsh S Talati,
aarshstalati1989@gmail.com 
47. Securing files
Here is a simple tip to password protect your files:
vi -x test
This command will ask for an encryption key. You have to type the key twice. Then save and quit the opened file.
Now, whenever you open this file, it will ask for that password first.
--Sumit Chauhan,
sumit1203@gmail.com 
48. Uninstalling a package 
To completely uninstall a package, first check the exact name of the package to be uninstalled by using the following command:
sudo dpkg --get-selections | grep package_name
The output of the above command will display the name of the package.
Once you know the package name, you can remove it by using the command shown below:
sudo apt-get remove --purge package_name
--Neeraj Joshi,
neeraj88joshi@gmail.com 

49. How to check the date and time the system was rebooted 
Here is a simple command to check the system's reboot date and time:
#last reboot
reboot system boot 2.6.18-53.el5 Sat Aug 6 18:02 (8+04:45)
wtmp begins Sat Aug 6 18:02:07 2011
The command below will give you the date and time the system was booted:
#who -b
system boot 2011-08-24 09:43
--Sumit Chauhan,
sumit1203@gmail.com 
50. Reloading XWindows System
Sometimes, while working on a Linux-based computer, XWindows System doesn't respond very well. Here are the steps to reload XWindows System in a non-responsive Ubuntu system.
1. First open the command mode by pressing: Ctrl + Alt + F2
…and then entering your username and password.
2. Then run the following command:
top 
Search the process named 'Xorg' in the list.
If it does not appear, wait for a few seconds. Then find the PID of the 'Xorg' process, listed at the extreme left of the output on the top.
You can also get the PID using the command given below:
pgrep Xorg
3. Now run the following command to kill the Xorg process:
sudo kill "PID"
…where PID is the process ID of Xorg.
This will reload the XWindows System.
Note: You must have root access to use these commands
--Indermohan Singh,
indermohansinghk7@gmail.com
51. Handling log files
Developers require a lot of testing after coding the software and they frequently need to handle the log files to identify the errors in the code of an application program. Given below are the steps to handle various log files that are being generated on a Linux system.
1. Clearing a log/text file:
$ >filename
The above command will clear all contents of the file.
2. To view the log/text file:
$ tail -f filename 
This command will display the file contents as and when the log is written. It also displays the flow of the log.
3. To use more sophisticated tools on log files:
$ less filename
This will display the log file contents. You can also use the commands below while using less.
a. To refresh the log automatically, press: 
"f" 
after issuing the less command.
b. To stop refreshing the logs, press: 
CTRL + C
c. To scroll up, press:
w
d. To scroll down, press:
d
e. To exit the mode, press:
CTRL+C 
and then press
q
--Pranavam Siddharthan,
pranavam.s@gmail.com
52. Changing file names from upper case to lower
To manually change the case (upper to lower or vice versa) of a large number of files can be tedious. So, here is a script that can make life easy:
#to change uppercase filenames to lowercase 
#!/bin/sh
if [ $# -eq 0 ] ; then
echo Usage: $0 Files
exit 0
fi
for f in $* ; do
g=`echo $f | tr "[A-Z]" "[a-z]"`
echo mv -i $f $g
mv -i $f $g
done
If you want to change the case from lower to upper, replace 
g=`echo $f | tr "[A-Z]" "[a-z]"`
with
g=`echo $f | tr "[a-z]" "[A-Z]"`
in the script.
--Anil Awasare,
anil.awasare@gmail.com
Counting the number of files in a directory
Here is a simple command that can count the number of files in a directory (not the hidden ones):
echo * | wc -w
--Anil Awasare,
anil.awasare@gmail.com
53. Find and move files
You can find and move files in two steps. Step 1 enables you to find all files with .mp3 as the file extension. In Step 2, you can move them.
Step 1:
[narendra@ubuntu]$ find DIR_NAME -type f -iname "*.mp3"
./dir2/f4.mp3
./dir2/f3.mp3
./dir1/f2.mp3
Note: Replace DIR_NAME with your actual directory name.
In the above example, you are only finding the files (that's why you used -type f) that have extension '.mp3'. Now you can move these files by using the '-exec' option of the 'find' command.
Step 2:
[narendra@ubuntu]$ find DIR_NAME -type f -iname "*.mp3" -exec mv {} /tmp/mp3/ \;
Here, '{}' matches each filename which is found by the 'find' command. And '\;' is used to indicate the end of the command.
After executing this command, all mp3 files are moved into the '/tmp/mp3' directory.
--Narendra Kangralkar,
narendrakangralkar@gmail.com

54. Burning a DVD using the command line
Do you know that burning content using the command line onto a DVD on your Linux-based computer can be easy and fun? Here are the steps and commands that allow you to do so.
Burning an ISO image
You can download your favourite Linux distribution and type the following single command:
$ growisofs -dvd-compat -Z /dev/dvd=your_linux_image.iso
Here /dev/dvd is your DVD burner device.
Burning a non-ISO image
For burning non-ISO images onto a DVD, first create an ISO image of the data and then burn the ISO image on the disk:
$ mkisofs -r -o /tmp/my_stuff.iso ~/Desktop/My_Stuff/
$ growisofs -dvd-compat -Z /dev/dvd=/tmp/my_stuff.iso
There are several options of mkisofs and growisofs that can be explored to suit your requirement.
You can read the man pages for more details of the commands and their options.
--Dibyendu Roy,
diby.roy@gmail.com
55. Find out the elapsed time of a running process
There are a lot of processes running on your Linux system. Here is a command that will let you know how long the process has been running:
#ps -eo "%p %c %t"|grep "sshd"
In response to the above command, you will get the following output:
2850 sshd 172-01:37:22
29532 sshd 125-09:07:10
In the above command %p is pid, %c is command and %t is elapsed time.