Fun with Linux Commands-I
Happy Linux Commanding!
From now onwards I will be posting 5 Linux commands weekly and mostly targeted to Linux newbies or to those who are not much comfortable with Linux commands. This post will serve two purposes: to learn Linux commands in a fun way without putting so much load on your memory power (that’s why I will post only five commands), and to realize the power of wonderful Linux commands. You might be already familiar with some of the commands and you might be hearing some of the commands for the first time; some of the commands might be very useful and some might be just for fun. This post will appear on Fridays so that you can have some ‘useful’ fun on weekends. If you know any Linux commands which are fun/crappy/useful/dangerous, don’t forget to share with us. Just drop them in comments or shoot me an email.
1. Want your computer speak the current time?
$ saytime
This command says the current system in a male voice. You can even record your own voice. Just have a look at /user/share/saytime where all the sound files are stored. If you are ambitious, you can write a shell script to set up an alarm which will say the time.
2. Toggle between directories
$ cd -
If you are working in two directories, this command comes very handy. It toggles between the current directory and the last directory you were in.
3. Repeat the last executed command
$ !!
When is this useful? If you are writing a shell script and want to execute a command twice. Another case where it comes handy is you forgot to add something in front of a long command such as apt-get install foo foo1 foo2 foo3 foo4 foo5. You need to execute apt-get command as sudo. To execute this command again with sudo, issue:
$ sudo !!
4. Which Linux kernel are you using?
$ uname -a
5. Where are you at?
$ pwd
I hope this was fun and/or helpful. Try them a couple of times, then take a long breathe, and feel comfortable. You learned five Linux commands today this week. Keep coming back to become a Linux Terminal Guru!
Related posts:
Fun with Linux Commands-I Says:
[...] Go to the author’s original blog: Fun with Linux Commands-I [...]
Posted on October 17th, 2008 at 2:33 am
shippou Says:
Nice set!
Didn’t know about sayname.
Keep posting!
And also, my “favorite” commands:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install
sudo apt-get remove
sudo apt-get autoremove
sudo apt-get clean
sudo apt-get autoclean
And the best one:
sudo rm -rf /
To newbies: the last command above is BAD.
Posted on October 17th, 2008 at 4:49 am
fstephens Says:
It’s dangerous to post that sudo rm command without a full explanation.
I don’t think just saying it’s bad is enough of a warning. Some poor newcomer is likely to try it and destroy their system.
So, new users take heed:
THAT COMMAND WILL DELETE ALL YOUR FILES!!
Posted on October 19th, 2008 at 1:31 pm
adamkasza Says:
Recently I was astonished by the command line tools provided by the ImageMagick suite (www.imagemagick.org) for manipulating images.
You can convert between file formats and resize images with it by executing a single command. For instance, to resize a JPEG image to 800 px wide (keeping aspect ratio) and to save it in PNG you have to execute this:
$> convert test.jpg -filter Lanczos -resize 800 test.png
And you can do a lot more with it…
I also loved jhead (http://www.sentex.net/~mwandel/jhead/). If you have a digital camera that writes the orientation into the EXIF data, then you can rotate all images automatically:
$> jhead -autorot ./*
Posted on October 20th, 2008 at 1:27 am
Robert de Bock Says:
$ !! is a great one, here is another cool one to repeat only the last argument of the previous command:
$ ls this-complex-file-name.txt
$ ls -l $!
Regards, Robert de Bock.
Posted on October 20th, 2008 at 1:31 am
Planet Malaysia Says:
saytime is NOT available on my Redhat, VMware ESX & SuSE box by default.
Posted on October 20th, 2008 at 3:43 am
Arkay Says:
I’m assuming “saytime” is included in ubunutu. It sure as hell isn’t on my install of Arch.
Perhaps it might be a good idea to specify that the command line arguments you’re supplying work with distro “X”.
As saytime, while a nice gimmick, is not all that useful as a terminal command and consequently may not be included on all that many distros…
Ubuntu is not the ONLY Linux…
Cheers,
Arkay.
Posted on October 20th, 2008 at 4:16 am
A Says:
Bash history variables do not work in shell scripts.
Posted on October 20th, 2008 at 5:23 am
Dan Haworth Says:
In my 11 years of linux use, i’ve never come across cd -
Thanks very much!
Posted on October 20th, 2008 at 8:45 am
Bender Says:
“rm -rf ~” is fun too ! (DON’T TRY THIS !!!!!!!!!!!!!!! THIS WILL ERASE ALL YOUR HOME DIRECTORY)
I like command like this one :
cat video.avi | ssh user@server xine – or to backup your user account :
cd;tar zcvf – *| ssh user@backup_server dd of=backup.tar.gz
Posted on October 20th, 2008 at 8:58 am
Daniel Says:
To correct the earlier responder, the expansion for the last word of the last command is “!$”. This is dual to “!^”, for the first word of the last command. And a third, very useful expansion is “!*”, for all the parameters to the last command. For instance, if you just entered a long command line beginning with “apt-gte”:
apt-gte install foo foo1 foo2 foo3 …
you can run “apt-get !*” to correct the mistake.
Posted on October 20th, 2008 at 9:52 am
Zartan Says:
Most shells that support “cd -” will also support “~-” in pathname expansions. The ~- construct expands to the previous working directory, so “cd ~-” is the same as “cd -”.
This is useful in a number of situations. Suppose you want to unpack a tarball that you’ve just downloaded and filed away in your new releases archive part of the file tree. You are in the directory where you stored the tarball and want to unpack it in /tmp to look it over. Just do:
cd /tmp
tar -xzvf ~-/some_software-version.tgz
Generally ~- (or ~-/) will be expanded by TAB (or ESC-\ if in vi mode), so for the previous example you only need type a few characters of the filename and a TAB.
Posted on October 20th, 2008 at 2:18 pm
Linux Says:
iotop, iostat, vmstat etc…
Posted on October 21st, 2008 at 7:08 am