Linux command line
at - command to schedule actions
Submitted by ggarron on Wed, 08/06/2008 - 20:35.One of the most uses I give to this command is to turn the PC off after some time, sure there are other ways.
I like the way you may execute batch jobs at a given time, all you need is:
1. Write your shell script
Which actually is a list of commands in a text file
2. Execute the at command
at now + 5 minutes < $HOME/listofcommands.txt
You can use times like "now", "noon", "midnight", or a date in the format of DD.MM.YY
check man at in order to have more details
Installing and uninstalling .deb package
Submitted by ggarron on Sat, 07/12/2008 - 14:05.Debian uses .deb binary packages and you manually install and uninstall them using dpkg tool.
dpkg has lots of options but maybe the most important or used ones are:
- -i
- Installs and configures a package
- -r
- Removes the package but keeps the configuration files on your systems, thus you may reinstall it later and does not need to configure it again
- -p
- Purges a package, meaning it will remove the package and also all configuration files
How to use it
du - Shows the disk space a file or directory is using in your disk
Submitted by ggarron on Sun, 06/22/2008 - 01:40.This is a very useful command you may use to find which file or directory is filling you disk.
So if you need to check the file and directory size in your home directory you can enter
cd
to switch to your home directory
du -S * | sort -n
How to find files, using command line (locate)
Submitted by ggarron on Wed, 05/21/2008 - 20:27.Continuing reviewing some of my old posts, I found this one Examples of find command, now I want to show you a faster and easier way to find files.
We are going to use the commands updatedb and locate
updatedb
How to find which service is listening on a given port
Submitted by ggarron on Mon, 05/19/2008 - 14:39.It is really important to know which ports are open in your PC, this is not only useful for Linux, but also for other operating systems, Linux has a lot of tools to check which ports are open, the most common is nmap which is a command line tool, but also exist a Graphical frontEnd for it if you prefer that way.
So to scan you own PC and find open ports you can enter:
sudo nmap -T Aggressive -A -v 127.0.0.1 -p 1-65000
wget - Resume downloads, limit the speed and much
Submitted by ggarron on Thu, 05/15/2008 - 23:09.wget is a command line tool used to download files, or complete webpages, it is a great utility with lots of options, as you can see if you read the wget man page
Some months ago, I have written about how to download files with wget, now I want to add some other tips to those already explained that day.
Resume a download
The /etc/default/rcS file
Submitted by ggarron on Thu, 05/15/2008 - 19:40.There is some behavior of your Linux Operating System which is easy to change, but not too common to know how.
The things you can change are:
- Frequency to erase /tmp/ directory
- Use UTC or local time
- How Verbose are the boot messages of your Linux
- If a disk error should be always repaired while booting automatically
There are more than those, but I will touch only those, for the rest, you can enter:
man /etc/default/rcS
vnstat - Command Line Tool to check how much bandwidth you use
Submitted by ggarron on Tue, 05/13/2008 - 14:17.It is always useful to know how much bandwidth you are using, also to check if your provider is honoring the contract you signed with them.
At my office I have installed Cacti and as I have a layer 3 SNMP capable switch, I can graph the bandwidth that all my office's PCs uses, and also the main pipe to the Internet (My ADSL connection), but at home, I do not have such an expensive switch (and I do not need it), and my ADSL modem is not SNMP capable, so Cacti is not a solution, but with Linux Operating System there is always a solution, and the one for this kind of problem is vnstat.
command line scientific calculator
Submitted by ggarron on Tue, 04/08/2008 - 03:54.I was looking for a good and light calculator for Linux, and found some command line ones, I liked this one wcalc it is really light, and accept almost all mathematical expressions, and I say "almost" because I do not want to say that are all and make a mistake.
The use of it is really simple, just enter wcalc followed with the math expression in the command line, press ENTER and you will the result.
To install it on Debian run:
sudo aptitude install wcalc
Trash can or Recycle bin in Linux Desktop (managed from console)
Submitted by ggarron on Fri, 04/04/2008 - 20:21.Linux Desktops, at least Gnome and KDE has a trash can, where your deleted files go, (only when deleted from a Desktop utility).
Now if you want to manage it from the console, you can, first we need to know that the trash can is only another folder in the File system structure and it is located at:
$HOME/.Trash
so you can send files to Trash just moving them to there, as an example, lets suppose you have a file in your home called balance.ods and want to move it to the trash can.
mv $HOME/balance.ods $HOME/.Trash/
How to assign a password to root user in Ubuntu
Submitted by ggarron on Wed, 04/02/2008 - 11:41.Ubuntu by default has no root password, and you can also configure Debian in that way if you choose the advanced installation option, and decide not to use the root password.
But what to do if later you need the root user? well you just need to assign a password to the root user and then you will be able to switch to root user.
sudo passwd
Type a good strong password twice, and you are done.
su -
Type the root password and voila! you are logged as root, you know you have to be carefull on what you do being root right?
Terminator - multiple terminals in one window
Submitted by ggarron on Tue, 03/25/2008 - 13:03.I really like to work with the console, and to connect to my servers using ssh, to administrate them, so sometimes I found myself with lots of terminal windows open, I have explored some solutions in the past, that you can see on this post about Terminal emulators, now I have found a new one which I really like, it is called terminator.
For Debian users it is available only on Sid, and as I use Lenny I had to install it from the sources.
Reading compressed Files
Submitted by ggarron on Thu, 03/13/2008 - 14:39.I did not know this, but if you need to show a compressed text file on the screen, you do not actually need to uncompress it.
You can use zcat to send the file to the standard output, uncompressed, but the original file remains untouched.
The syntax of the command is:
zcat file.gz
or you can also use,
gunzip -c file.gz
mplayer - command line movie and music player - music over ssh
Submitted by ggarron on Sat, 03/01/2008 - 15:26.Mplayer is one of most known movie players in Linux, and also in Mac OS, and Windows.
To install it in Debian / Ubuntu run:
sudo aptitude install mplayer
Mplayer has lots of options, and we will explore some of them here, the files format it can play according to its official site are:
MPEG/VOB, AVI, Ogg/OGM, VIVO, ASF/WMA/WMV, QT/MOV/MP4, RealMedia, Matroska, NUT, NuppelVideo, FLI, YUV4MPEG, FILM, RoQ, PVA files, supported by many native, XAnim, and Win32 DLL codecs. You can watch VideoCD, SVCD, DVD, 3ivx, DivX 3/4/5 and even WMV movies..
for - Control flow statement in shell scripts
Submitted by ggarron on Sun, 02/24/2008 - 12:17.One real important part of programming is to control the flow of the program, you need to be able to repeat some part of the code, jump to another part, etc, depending on the estate of some variables, there are a lot of commands to achieve that, and one of them is for
It can be used directly at the command line like this example using basename
for i in *.jpg; do echo $i $(basename $i .jpg); done
basename - removing directories and suffix from file names
Submitted by ggarron on Sun, 02/24/2008 - 11:47.If you need to remove the directory or any suffix from a file name you may use basename, this is really useful when you are creating shell scripts.
In the man page, there are this examples
basename /usr/bin/sort
Output "sort".
basename include/stdio.h .h
Output "stdio".
you can enter
info basename
Friendly interactive shell (Fish)
Submitted by ggarron on Tue, 02/19/2008 - 21:19.I think Friendly Interactive Shell (a.k.a. fish) is a real good tool for newbies on the console at Linux, it has a lot of features, which you can by typing help.
Well first lets see how to install the application.
Fedora / Centos
sudo yum install fish
Debian / Ubuntu
sudo aptitude install fish
Simple shell script
Submitted by ggarron on Sun, 02/17/2008 - 13:43.Maybe most of the readers of this blog do already know about shell scripts, and maybe they know even more than me (which is not difficult), but for those who does not know about it, I will write a little about shell scripts.
A shell script is a sequence of commands -For those coming from DOS is like a .bat file- this command will execute in the sequence they are entered, unless loops, if, do, for, or any other commands like those are used.
Writing the script
Lets go with the classic example, of "Hello World"
Changing screen resolution on the fly
Submitted by ggarron on Sun, 02/10/2008 - 03:30.If you want to change your screen resolution, while still running Linux but you are not using Gnome or KDE, which gives good options to change screen resolution, you will have to use the xrandr command
iftop - Check and analyze your traffic
Submitted by ggarron on Tue, 01/22/2008 - 09:15.Introduction
iftop is a real good utility both for your own PC/Laptop and for your server and specially good for the latter and even better if this server is acting as the main router in your premises.



