Linux How To Thread

I thought it might be useful if we started a thread about how to do different things using Linux. I know a lot of you are Linux aficionados so please feel free to add to this thread on whatever topic you would like to discuss. I will start with an introduction on how to use nano, a command line text editor.

At some point using Linux you may wish to delve deeper and look under the hood of your operating system. The Linux terminal allows you to run programs and edit text files to name but a few. Many system configuration settings can be changed by editing text files. There are excellent GUI text editors like Gedit and Kwrite that will let you edit text files.
However, there may come a time when you need to edit a text file on the command line interface (CLI).
In the following example I will use the Debian operating system and the nano text editor.

  1. Open up a terminal prompt and get root access. Type su then enter your root password.
  2. If you don’t have nano installed then install it with the following command:

aptitude install nano

  1. Let us say that you wish to add the backports repo to your sources.list. At a root shell prompt start-up nano and give the command pathway to your sources.list

nano /etc/apt/sources.list

  1. This will display your sources.list which is a list of all software repositories on your Debian system. Add the following line to your sources.list:

deb backports.debian.org/debian-backports squeeze-backports main

  1. To save your file using nano you will issue the following keyboard combination:

Ctrl+o <--------- that is a lowercase o

  1. To exit nano you will issue the following keyboard combination:

Ctrl+x

  1. Then update your sources.list by issuing the following command:

aptitude update

You can now install software from the backports repo. A command line interface text editor can be a valuable thing if your system needs to be repaired and X windows no longer functions. Here is another tutorial on how to use the terminal prompt.

http://linuxcommand.org/

Faster way

grep backports /etc/apt/sources.list

if nothing shows up that means the backports line isnt already in the sources.list. Doesnt really matter because apt will ignore duplicate lines but do it right.

echo “deb backports.debian.org/debian-backports squeeze-backports main” >> /etc/apt/sources.list && apt-get update

make sure you have two >> or it will overwrite the entire sources.list file and then you have to rebuild it. Also I bought a rad book back in the day called linux essential reference. Plain english language, examples of scripts, command usage etc not man page madness… I highly recommend it.

Ugly script I made to copy songs in a playlist from a huge messy media library to a new directory. I used it to copy my songs to a thumb drive for portability:


if  -z "$1" ]; then
        echo "Choose a Playlist"
exit 1
fi
if  -z "$2" ]; then
        echo "Choose a Directory"
exit 1
fi
DIRNAME=`echo $1 | sed "s/.m3u*//g"`
if  ! -d $2/"$DIRNAME" ]; then
        mkdir $2/$DIRNAME
fi
IFS=$(echo -en "\n\b")
for i in $(sed "s/#E.*//g" < $1 | sed "/^$/d"); do
cp $i $2/$DIRNAME
done

It checks to make sure you enter the playlist and directory you want to copy the files to, then it creates a directory in that path with the same name as the playlist file if it doesnt already exist and copies all of the mp3s from the playlist to that directory. I tend to make random scripts to do things just because…

How to apply security patches and updates on a Slackware system.

Slackware now ships with the slackpkg utility which allows you to easily download and install security patches and updates with a few simple keyboard commands.

  1. Use nano or the editor of your choice to uncomment one and only one mirror on your system. Save and exit. I am running Slackware 13.37 in my example.

nano /etc/slackpkg/mirrors

# USA, 45Mbit ftp://slackware.oregonstate.edu/pub/slackware/slackware-13.37/

Open up a terminal prompt and get root access. Type su, then enter root password. Then run the following commands in this order to update, download, and install security patches and any new programs that are available.

  1. Check for updates:
  1. Install any new programs that are available:
  1. Upgrade your system:
  1. Run this command if you’re upgrading to a new version of Slackware or if you have obsolete packages that you wish to remove:

Simple trix

When you exit nano with CTRL-X it offers a Y/N choice to save your changes.

The equivalent of sudo su on Fedora is su-

If it isn’t already, set your browser’s start page to google.com/linux

Use your TAB key: cd /e(TAB) will expand to cd /etc. IF cd /etc/spam(TAB) doesn’t do anything, it means there’s more than one directory in /etc that starts with the letters s-p-a-m try adding a couple more cd /etc/spamas(TAB) = cd /etc/spamassassin

Grep: use quotes searching for nonstandard characters:
grep iggy@schwartz.com /var/log/mail.log shows iggy’s mail traffic
grep “from<iggy@schwartz.com” /var/log/mail.log shows only what iggy sent

Awesome possum good sir. :smiley:
Will read when have time. Give it a try. I have a few extra machines to mess with now.

[quote=“herbie_popnecker”]Simple trix

When you exit nano with CTRL-X it offers a Y/N choice to save your changes.

The equivalent of sudo su on Fedora is su-

If it isn’t already, set your browser’s start page to google.com/linux

Use your TAB key: cd /e(TAB) will expand to cd /etc. IF cd /etc/spam(TAB) doesn’t do anything, it means there’s more than one directory in /etc that starts with the letters s-p-a-m try adding a couple more cd /etc/spamas(TAB) = cd /etc/spamassassin

Grep: use quotes searching for nonstandard characters:
grep iggy@schwartz.com /var/log/mail.log shows iggy’s mail traffic
grep “from<iggy@schwartz.com” /var/log/mail.log shows only what iggy sent[/quote]

Bash also has a nice way to extend tab completion. howtoforge has an awesome tutorial on how to enable it for debian (its pretty much the same for every distribution). It enables things like tab completion for ssh, apt-get etc.

howtoforge.com/how-to-add-ba … -in-debian

An excellent site for tutorials (howtoforge.com) although sometimes they don’t clearly explain why a step is necessary. Google it and you’ll usually find the answer in an earlier tutorial.

Here is a video from one of the Slackware core developers, Vincent Batts: Slackware Demystified.