command line

Here are a few tasks that you might want to consider using the command line for.

1. Resizing images

Unless you are doing some sort of cropping there is no reason to load up Photoshop or the Gimp. A simple command will usually suffice for almost all your image resizing needs.

convert -resize 300 image.jpg image-small.jpg

If you finding yourself doing lots of image resizing during the day, this command could potentially save you a LOT of time. You can even do mass image resizing.

2. Adding a Drop Shadow to an Image

I found myself spending a ton of time adding drop shadows to images. Using a simple command I was able to create drop shadows in seconds.

suse screenshot

convert screenshot.jpg \( +clone -background black -shadow 60×5+0+5 \) +swap -background white -layers merge +repage shadow.jpg

Note: You must have Imagemagick installed for this command to work. Debian/Ubuntu users can use apt-get install imagemagick.

screenshot dropshadow

Obviously, I don’t expect you to memorize this command. To shorten it use an alias.

3. Splice Together an MP3

If you want simple MP3 splicing this command has your back:

cat 1.mp3 2.mp3 > combined.mp3

4. Clone a Hard Drive

DD is one the most simplistic and powerful image applications out there.

dd if=/dev/hda of=/dev/hdb

5. Burn an ISO to a CD

Why open up K3B or some other program just to burn an ISO? Map this command to an alias and get burning.

cdrecord -v speed=8 dev=0,0,0 name_of_iso_file.iso

Note: You need to get the info for the ‘dev=’ part by running ‘cdrecord -scanbus’

6. Video Conversions

Let’s say you want to convert an AVI to an Mpeg file:

ffmpeg -i video_origine.avi video_finale.mpg

Or convert an Mpeg to AVI:

ffmpeg -i video_origine.mpg video_finale.avi

There are all sorts of things you can do with ffmpeg.

7. Replace Words in a Text File

No need to open up a GUI text editor when you have sed.

This command from Eric’s Wendelin’s blog will replace all instances of a color in CSS with another one.

sed ‘s/#FF0000/#0000FF/g’ main.css

Subscribe via Email

Subscribe to Nixtutor via Email

Enter your email address:

Was this information useful?

39 Responses

  1. [...] 7 Tasks You Shouldn’t Use a GUI For Sometimes the GUI is just too slow. Learn how to resize images, add drop shadows, splice mp3s, clone hard drives and more with the command line. [...]

  2. Johnny Stavros

    7-29-2009

    These are cute tricks, that are frankly only useful for primitive tasks under very specific, “ideal” conditions.

    The mp3 splicing trick only works when both files have no gaps, equal volume settings, and similar enough tempos. What of beat matching? Mixing? Normalization? Precision tools for tasks which require precision!

    Same applies to the drop shadows, it’s a cute trick, if all you’re doing is applying a drop shadow to a square image, but what about applying shadows to individual typeface glyphs? Shapes with jagged or slanted edges? Curved edges? Applying shadows to individual elements in a larger design, without also applying shadows to the backdrop? Simulating an object casting a realistic shadow? There is a place and time for ImageMagick, but to suggest that such is a task you “shouldn’t” use a GUI for is pretentious, dishonest and frankly, the mark of an amateur.

  3. bobsmith

    7-29-2009

    You know, this is a nice tutorial, and I’m sure it’s useful for some. The problem with the command line, however, is that it requires one to work in the blind. By that I mean that you’re really never sure that the command is going to do what you want it to do – there are usually a jillion options, directory changing, switches, syntax… Who can remember all that? Who WANTS to remember it?

    With a GUI there are plenty of visual cues and instructions built right into the GUI. So all you have to remember is that Brasero burns disks (or whatever). When you open Brasero it’s intuitive. You don’t need to remember anything and you can be certain you’re doing what you intend to do because each button is clearly marked.

    With the command line you can open a terminal and read the man pages, which are ALWAYS horribly written and indecipherable. Or you can keep a cheat sheet somewhere and consult that, I suppose, but by the time you find what you want and verify that it will really do what you want, you could be done with a GUI. Why would anyone want to mess with the command line when a GUI (for most things) is so much easier?

  4. Kevin

    7-29-2009

    I get an error with your imagemagick command for the drop shadow.

    convert: invalid argument for option `60×5+0+5′: -shadow @ wand/convert.c/ConvertImageCommand/2228.

  5. Bob

    7-29-2009

    In the case of cdrecord, you can leave off most of the stuff and it’ll decide for itself

    cdrecord path/to/file.iso

    is usually sufficient.

    That said, I normally have a Nautilus window open because, say, I’ve downloaded the ISO from a web browser and clicked “open containing folder,” in which case right-clicking and selecting “burn to cd/dvd” is much quicker.

  6. [...] 7 tasks to do in #Linux #bash #commandline http://www.nixtutor.com/linux/7-tasks-you-shouldnt-use-a-gui-for/ [...]

  7. Mark Sanborn

    7-30-2009

    Make sure you have those slashes in there.

  8. wodny

    7-30-2009

    Usually combining mp3′s isn’t so simple. For example files with different bitrates.

  9. Fred

    7-30-2009

    I would spend more time looking up all the options than it takes to load up the GUI and do what needs to be done with a GUI tool. Yeah, if I were resizing a ton of images, it may be easier, but even when I have a ton of images, it is rare that I want to resizing them all by using the same ratio. I usually want to look at the image and decided if I want to crop, resized, or crop and resize. Just because there is a command line way of doing things, does not mean it is the best way of getting the results one wants, or the fastest.

  10. Hey Thanks for the Handy Tips man…

    @rungss on Twitter

  11. ges

    7-30-2009

    Maybe it would be better to re-write Gimp to make it CLI only :D hahahah…
    If you wanted to write a good tip of this kind you should remember about commands like ls or cp.. which are really much quicker in terminal than in a gui…
    Keep going.. ;)

  12. pipo

    7-30-2009

    to get the result on stdout and keep main.css unchanged:
    sed ’s/#FF0000/#0000FF/g’ main.css

    to update main.css:
    sed -i ’s/#FF0000/#0000FF/g’ main.css

    to update main.css and keep the original in a backup file main.css.bak
    sed -i.bak ’s/#FF0000/#0000FF/g’ main.css

  13. Mark Sanborn

    7-30-2009

    Pipo,

    Nice catch. I must have missed that.

  14. I R A Darth Aggie

    7-30-2009

    Who can remember all that?

    As Professor Jones famously stated, I wrote it down so I wouldn’t have to remember. It is for this reason the G*d invented “man”.

    > man convert

    [much interesting reading]

  15. dbg

    7-30-2009

    Kevin, the problem you have is because of the “x” after the “60″. If you cut and paste the command you get a “×” character which looks like a nice “x” in html but doesn’t work on the command line. Just delete it and type in a real “x”.

  16. robb

    7-31-2009

    for a very basic task, yes it works.
    but not for some additional.
    nice tutorial.

  17. Marcus Harman

    7-31-2009

    !/bin/bash
    grep -i “great ideas”

  18. ejes

    7-31-2009

    bob smith – The fact is, you can use your point and click interface for EVERYTHING if that’s what you want… but these shortcuts are FASTER, scriptiable, 100% reproduceable and quite honestly way simpler than any possiblity you can come up with. So, if you feel like you need cryons to do all your work – go for it, finger paint too – but leave the CLI for the actual masters of computers and get out of our way.
    Johnny Stavros – nonsense, all of these task (minus the mp3 one) i do quite frequently on the CLI – I am a frequent user of SED, AWK and SOX. (oh, sox filea.mp3 fileb.mp3 will ALWAYS work for joining mp3′s (or wavs, iff, really any file you can throw at it)) and these “primitive” examples come up quite frequently in real life.

  19. BigScaryDuck

    7-31-2009

    I have found a ton of uses with ImageMagick especially when batch resizing images. As for the SED command it would be simpler to just run the command in Vim. Go to command in Vim and use ‘s/foo/bar/gc’ The G will set it to Global for the whole file and the C is optional, it will ask you to confirm each replacement. Also, you can replace the ‘/’ with anything, i.e. ‘s%foo%bar%gc” or ‘sTfooTbarTgc’.

  20. Aleve Sicofante

    7-31-2009

    The title is unfortunate. These are things you “can” do without a GUI but you definitely “should not” do without a GUI. I was expecting some ideas where using a GUI would actually be more cumbersome than the command line. Disappointing. :-(

  21. Casey

    7-31-2009

    The problem is that it is easier to open up gimp (etc) then to look up the command, because I am NOT going to remember the details.
    But, the commands are useful if I want to write a script to do a task.

  22. Justin

    7-31-2009

    It’s nice that you know how to use a command line for these things, but I certainly don’t believe you SHOULDN’T use a GUI for them, that just makes no sense at all.

  23. bob

    7-31-2009

    If you are just screwing around with an image, or trying things out, use your gui. But when you are doing some sysadmin stuff and are asked to make changes to hundreds of files, you’ll be happy that you learned the cli. Good stuff. Emphasis on SCRIPTABLE!

  24. seanFalloy

    8-1-2009

    @bob smith
    The fact that the cli is still around (and used by most (real) computer users) is a testament to how useful an powerful it really is. Obviously you have used it a few times but you have never really used it enough to fully understand it– and as for the memory thing its really quite easy once you use it all the time. (i rarely need to look a the man pages). I do have to agree though the GUI is useful for some things.

    Thanks for the tutorial.. i have never uses convert before .. that said i prefer vim over sed just because you can open the file and make sure its the right one before changing it ( yes cat | less works but its more of a hassle )

    – for those of you that are not familiar with vim run vimtutor and learn the basics of the most powerful editor ever (no offence emacs haha)

  25. vicente

    8-1-2009

    How can imagemagick be used to resize a complete folder?
    If using a bash script with a “for” loop, how can I get just the name part of the files without extension?
    for i in $(ls); do
    convert -size 300 $i “$i-small”
    done;
    will convert “logo.png” in “logo.png-small”.

  26. bjohnson

    8-2-2009

    @ejes says: “…leave the CLI for the actual masters of computers and get out of our way.”

    What a ridiculous, arrogant, and ignorant comment. Here’s a guy who’s encouraging users NOT to use the CLI, because it should be used only by smart guys like him. It’s guys like this who give Linux a bad name.

  27. Christoph Jeschke

    8-2-2009

    If you know your extension, use basename:

    $ basename foo.bar .bar
    foo

    If not, you must find the extension using awk:

    $ echo foo.bar | awk -F. ‘{print $NF}’
    bar

    Combined:
    $ basename foo.bar .$(echo foo.bar | awk -F. ‘{print $NF}’)
    foo

  28. Ben

    8-2-2009

    #8 connect to the internet

    iwconfig eth1 essid ESSID key ke:yi:n:he:x
    dhclient eth1

  29. vicente

    8-2-2009

    Christoph, thank you for the basename command and the awk magic.

    Maybe these two miniscripts are helpful for somebody.

    Converting all images of a folder to jpg:

    for i in $(ls); do
    convert $i `basename $i .$(echo $i | awk -F. ‘{print $NF}’)`.jpg;
    done;

    Resizing all images of a folder, adding “-small” to their names:

    for i in $(ls); do
    ext=`echo $i | awk -F. ‘{print $NF}’`;
    convert -resize 300 $i `basename $i .$ext`-small.$ext;
    done;

  30. Robin

    8-3-2009

    unzip | touch myself | zip

  31. ewanm89

    8-5-2009

    Once the CLI is known it can be faster, but say I want to resize a whole directory of files, I would script it. The biggest advantages of the CLI usually is faster execution of application (drawing text is nowhere near as complicated as a GUI leaving more CPU time free for the actual Math in the application) and also for scripting and such.

    As far as the MP3 splicing, tagging one after the other like that also means you have extra headers and also it kills of the efficiency of some of the compression steps (hint, it’s not all lossy).

    If I happen to already have a terminal open I may use it, and if I happen to have the GUI app open for some reason I may use that. depends on what I need to do and what I already have up. I always burn CDs using he CLI because I’m so use to doing it that way for example.

  32. George

    8-5-2009

    I used the mp3 splicing trick just now for lord of the rings, the version i have is split up into multiple files, using that simple and easily remembered trick i now have them in one file per movie.

  33. richs-lxh

    8-6-2009

    Your tips and guides get better and better, thanks for taking us back to basics. One more i would add is that Linux users should never use a gui to update/upgrade their system. A simple Ctrl+Alt+F1 to get to the terminal and then a “sudo killall gdm” to kill the graphical desktop. This avoids all the possible Xorg/Graphic-Driver problems which many new users face when upgrading and dist-upgrading their system.

    rich

  34. Chuck

    8-7-2009

    Good stuff. You forgot a big one — backups. Set an rsync -ra /disk/one /disk/two (or something like that) as a cron task.

  35. Cameron

    8-31-2009

    Has anyone mentioned how dangerous the dd command is?

    If you put in one wrong drive letter and do a block for block copy you could kill your whole hard drive.

    Just throwing out there that it is one of the dumbest suggestions to bring up from a data safety standpoint.

  36. Mark Sanborn

    8-31-2009

    With power, comes great responsibility.
    - Someone smart

  37. SeismicMike

    9-1-2009

    @bobsmith:

    You make some compelling points but remember these advantages of the command line:

    1. No GUI. By that I mean, no graphics or any of that to load, which means far less resource hogging

    2. More power. Yeah, GUIs are nice if you’re not real sure what you’re doing or if you want to accomplish a simple task, but I know for sure that there are many tasks that I far prefer to do from command line because of the power it gives me in one simple command. Yeah I gotta remember some weird syntax, but it’s better than waiting for the app to load, then clicking 5-10 menu buttons, etc.

  38. Tariq

    9-3-2009

    All are useful but 3. You should be using mp3wrap and ffmpeg for mp3 merging. Also, you completely missed out on searching, is there anything more useful than ‘find’ and ‘grep’ on the cli?