7 Simple and Useful Command-Line Tips

7 Simple and Useful Command-Line Tips

Tutorial Details
  • Program: Terminal / PuTTY
  • Difficulty: Beginner

One of the most useful, but under-used, tools a web developer has is the command-line. The terminal often scares people away; so here’s where we demonstrate some of the most useful day-to-day commands.


1. The Basics

If you’re new to the command-line, you’re going to want to know a few things to help find your way around.

Changing directories

You can change to a different directory with the following:

cd ../relative/path/to/other/directory/or/file
cd /absolute/path/to/other/directory/or/file

If you get lost, you can go back to your “home” directory with the command “cd ~”.

Listing files and directories

If you need to know what files a particular directory contains:

ls ../relative/path/to/other/directory/or/file
ls /absolute/path/to/other/directory/or/file

You can use the “-l” switch to show the contents as a list, and the “-A” switch to also show hidden files (on Linux based machines, files and directories whose name begins with a “.” are considered ‘hidden’).

Showing your current directory

Sometimes you just want to know what directory you’re currently in!

pwd

This will display a path to your current folder.

Copying files

Copying files from one place to another is quick and easy:

cp /files/or/directories/to/copy /directory/to/copy/to/

You can also use the “-R” switch when copying to make it recursive, so all sub-directories and files are also copied.

But typing is slow, and what if I can’t remember the exact path or command?

Most of the time, the command-line has tab-completion enabled, so you can start typing the name of a command or a file path, press tab, and it will complete it for you. If there is more than one option, it won’t complete for you but if you double-press tab, it will list the options.

Tab-completion makes typing out long file paths much faster!

How do you know what options a command has?

There are a few ways to determine what options a command has. Most commands have a –help (or -help, or -h) operator available, which lists the possible arguments and options you can use:

cd --help

If you find that the brief help given by the –help operator isn’t enough, you can read more detail with the man program:

man mysqldump

Which will tell you all about the “nano” program. Simple commands like “cd” may not have an entry in man.


2. Making a Database Backup (with GZip Compression)

Backing up your database is something you should do often. Like most things, there are a lot of ways to do this, but using the command-line is one of the best. Why? Because it helps you get around potential problems like execution timeouts for tools like phpMyAdmin, and potential network dropouts from using a local administration tool like MySQL Workbench.

The command to run the backup is fairly small, but may require some explaining:

mysqldump -u mysqluser -p mysqldatabase

Now, to explain what’s going on here! The “mysqldump” program is a tool for creating database backups. The parameters being used are:

  • “-u” switch means you’re going to specify a username to connect with, which must follow, like “-u mysqluser” above
  • “-p” switch means you’re either going to immediately specify the password to use (with no space), or it’ll prompt you for one
  • The final parameter used in the example above is the name of the database to backup (of course!)

If you ran the command above, you would’ve seen the contents of your database go whizzing by on the screen. That’s good, because we know that part works (actually connecting to the database), but it’s also bad, because… where did it go? Answer: nowhere! It scrolled past, and that was it. Now we need to capture it and put it in a file.

To place the contents of the output into a file, for back-up purposes, we need to use what’s called a redirection.

mysqldump -u mysqluser -p mysqldatabase > db_backup.sql

So we added a redirecter, and the filename we wanted the output to go into. Now you should be able to see a file named “db_backup.sql”, and if you open it you can see a SQL script with the structure and content of your database ready for restoration or migration.

One last thing that could be useful for a backup, is compressing the SQL script. For this example, I’m going to use GZip compression, because it’s quite common, but you could also use Bzip2 or something else.

To add compression into this command, we just do what’s called piping. We pipe the output from the mysqldump through gzip, and then redirect it into the file we want, like so:

mysqldump -u mysqluser -p mysqldatabase | gzip > db_backup.sql.gz

I also added the “.gz” to the filename, so I know it’s compressed and not just plain text anymore (it’ll also be smaller!)


3. Restoring from a Database Backup (with GZip Compression)

So you’ve got a backup of your database (either using the method above, or some other way), and something has gone wrong and you need to restore, or you’re migrating it to a new server. You could use one of the other tools mentioned before, but in the example of phpMyAdmin, what if your database backup file is bigger than the allowed upload size? Well luckily, the command-line doesn’t mind.

The command to restore is very similar to the one for backing up. Firstly, without GZip compression:

cat db_backup.sql | mysql -u mysqluser -p mysqldatabase

We use the “cat” command to output the contents of the backup script, and pipe its contents into the mysql program. As you can see, the mysql program takes the same options as the mysqldump one does in section two.

Now if the script was GZip compressed, we can’t just output its contents into mysql, as it will be compressed data instead of a nice SQL script. So we do the following:

gunzip < db_backup.sql.gz | mysql -u mysqluser -p mysqldatabase

See, it's very familiar, just switched around a bit.

What's happening here is we run "gunzip" too and redirect the backup script into it to be decompressed. We then pipe the decompressed output into the "mysql" program.


4. Find / Replace in a Text File

Sometimes you have a big file, like maybe a database export, and you need to do some find / replace on it... but it won't open in any of your text editors, because your machine runs out of memory trying to open it! Well, here's a way around that, by using the command-line and a little regular expressions.

The way this works is to output the contents of the SQL script (or whatever file you're using), pipe it through a program called "sed," which is specifically form manipulating streaming content, and then redirect that output into the new file. Sound complicated? Well... I guess it is a little, but the command itself looks simple!

cat original_dump.sql | sed s/Japheth/Japh/ > new_dump.sql

The new part here is really the "sed" program. Basically what it's doing is taking input and matching the first pattern (in this case, my name, "Japheth"), and replacing it with the second pattern (in this case, a shortening of my name, "Japh"), then outputting that.


5. Securely Copying Files to / from a Server (over SSH with SCP)

If you're working on the command-line and need to copy a file, especially if you need to do it securely, why go and fire up your FTP client? Just use a program called Secure Copy, or SCP, which is especially for doing remote file copying securely. Secure Copy uses SSH to copy the files, so you need to make sure you can connect to the remote computer via SSH first (I'll talk about this a little more at the end of the article, so hold that thought).

The syntax of the scp command is similar to that of the cp command covered in section one, with the addition of the hostname of the remove computer and the username to connect with:

scp /path/to/local/file username@hostname:/path/to/copy/to/

The bits to note are "username@hostname:", which, as I explained above, are the username to use and hostname to use when connecting. You will be prompted to enter the password for that user, and you also will get a progress indicator for the copying so you can see how it goes.

You can use the "-r" switch (note: it's lowercase for scp, uppercase for cp) with secure copying to make it recursive. Also, if this is the first time using SCP or SSH to connect to the remote machine, you may be asked to accept an RSA fingerprint for security, which you should accept (assuming you're certain you're connecting to the correct server).

It's worth mentioning that this works both ways. You can also copy files from the remote computer to your local machine by switching the arguments around:

scp username@hostname:/path/to/remote/file /local/path/to/copy/to/

If you're SSHed into one web server, and you want to copy files to another one, you can use this command to copy the files directly without having to download them to your local computer first!


6. Finding Specific Files in a Large Project

Finding a file with a particular name

Want to find a specific file but not sure where in the many directories of your project it's hiding? (or even if there's more than one!)

find ./ -iname "index.php"

The "find" command is for locating files within a directory heirarchy. It has many options, so its uses are quite varied. Here I've specified to search in the current directory with "./", and used the "-iname" switch, which means to search for a file with a name like the one I supply. There is also a "-name" switch, but the "-iname" switch is case-insensitive, so it'll find INDEX.php as well.

Finding a file with particular content

Ever known that you had written a function for something, but can't remember which file it was in?

grep -iR myFunction ./

"grep" is a program for printing out lines that match a particular pattern. You can provide it with some switches, like the "-i" for making it case-insensitive, and "-R" for making it recursive in my example. Then provide a pattern, and the path to search in (here I'm searching the current directory with "./"). This example will show the filename and the line in that file for any matches it finds to "myfunction" (case-insensitve because of the "-i").

If your projects are Subversion working copies, you may find that it's annoying to see results from the ".svn" directories. To exclude particular directories from the search, use the "--exclude-dir=" switch, for example "--exclude-dir=.svn".


7. Performing Bulk Actions on Specific Files

Now we know how to find particular files; what if we want to do particular things with those files? For example, I often work on a Mac, and find that when I save files to Windows shares or Linux Samba shares on the network, Mac OS X kindly litters "._filename" files everywhere. So I like to be able to clean these up regularly.

To find such files, I use both methods from the previous section for finding files with a particular name:

find ./ | grep "\.\_.*"

We're finding a way to output all files in the current directory (recursively), and are then piping the output to grep, which ensures that it matches my regular expression. The regular expressions just says, "match anything that starts with a literal . followed by a literal _ followed by 0 or more of anything else." Run it like so to make sure you see the desired files.

Now to do something with all the files you captured from that command, you wrap it with back-quotes (``). If I wanted to delete all of them:

rm -f `find ./ | grep "\.\_.*"`

I have the "rm" command (to remove, or delete, files) with a "-f" switch (which means to force a delete without asking for confirmation), and it will run for each file returned by the command within the back-quotes!

I feel it would be irresponsible not to mention here that you should be very careful using the "rm" command. If you use the "rm" command with the "-f" switch, make sure you know exactly what you're going to be deleting, and that you really want it gone! If you use "-f", you won't get a second-chance.


How do I get Command-line Access to my Web Host?

I mentioned earlier in the article about connecting to a remote computer via SSH. A lot of these commands are most useful when used on your web server, which likely runs linux, so you'll need to be able to connect to the command line. The way to do so is by using a program called SSH, which does it securely.

On Mac OS X, or on linux, you can run SSH from the Terminal application:

ssh username@hostname

If you're on Windows, you'll need to use a freely available program called PuTTY.

You will be prompted for your password when you are connecting.

If you do not have SSH access to your web host already, you will most likely be able to request it, and they will set it up for you.


In Summary...

Like most things, "you don't know, what you don't know." It might seem difficult to discover how to use the command-line; but there's a huge amount of power available to you once you wrap your head around it! Hopefully, this article will get you started exploring! Any questions?

Tags: terminal
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://john.onolan.org JohnONolan

    Nice! You’re right, I have always been petrified of command line stuff, but this has made it a lot easier :)

    • http://japh.com.au/ Japh
      Author

      Thanks, John :D

      You’ll be able to have a go at using some of the stuff in here then. I’m hoping this article can make a nice reference article for people.

  • http://www.quizzpot.com Crysfel

    I don’t understand why the terminal often scares people away, it is the most powerfull tool :)

    • http://www.reindel.com Brian Reindel

      sudo rm -R ../*

      That’s typically good enough reason to scare some people.

      • krisnrg

        I don’t think it’s a good idea to post destructive commands without warning. rm was discussed but it’s worth pointing out that / means your root directory and * matches every file in it. Effectively this command would delete the contents of your hdd.

      • http://swimandsing.com Jamie

        If you can sudo, you better damn well know what you are doing with rm -r

        oh, and rm -rf /* is much quicker. Maybe try it on a server in a cron job when you are not there on your last day at your job. If it is a cron don’t forget /dev/null so you don’t alert the authorities.

        This is just a joke, it won’t necessarily work.

        find /home/site/net.tutsplus.com/blogs/comments/krisnrg -type f -exec rm -v ‘{}’ \;

        krising, take a look at the internet a little closer, you will find way more destructive stuff than rm -rf.

      • http://www.reindel.com Brian Reindel

        @krisnrg

        The point is to make sure that designers and client-side developers who don’t deal with this every day understand that there can be serious implications to running commands on the command line. Most commands that deal with file and folder manipulation, as well as administrative tasks, require you to run them as super user. When you do that, you are opening yourself up to the possibility that something can go very wrong. For those that can’t afford backup services, this can be a very disheartening experience. My advice is to think before you type, and think one more time for good measure.

      • k

        sudo rm -rf /

        that scare too much

  • http://www.daniel-petrie.com Daniel Petrie

    Oooo command line, something I’ve been needing to learn. Thanks!

  • http://moscreative.com Serhiy

    Nice Tut!
    Would awesome to see tut with how to configure vps server from scratch over ssh

  • http://carlosvidal.pe Carlos Vidal

    When I have a bunch of pictures to include into a database, I save the directory list into a text file, like this

    ls > pictures.txt

    Then you can search for line breaks and replace them with commas and save the file again as CSV that can be easily imported into MySQL or modify as a spreadsheet.

  • http://andrewburgess.ca Andrew Burgess

    Great tutorial; I need to learn to use the terminal more!

  • http://michael.theirwinfamily.net Michael

    Thanks for the post!

    Using Lucid Lynx?? :-)

    • http://japh.com.au/ Japh
      Author

      Thanks! And yes, using Lucid Lynx :D

      • http://www.rizqtech.net rizq

        Great ;) , i love using terminal too.

  • http://www.deluxeblogtips.com Deluxe Blog Tips

    Very basic but useful post. I think the operation which is often used via command line is working with database. In this post, there’s only 2 tips when backup and restore database. It should be better if there’re some examples of mysql commands that can be done via command line.

    • http://japh.com.au/ Japh
      Author

      Great suggestion! The idea for this article was to provide some basic tips for people who don’t use the command-line much (or at all), and show some of its power in general usage. I think your suggestions would deserve an article of their own, as it’s specifically about using the command-line for managing MySQL.

      • http://swimandsing.com Jamie

        Japh, I would love to see a tut on MySQL from the command line. I think it would be great if it could be done with examples of how you might do the same function from phpMyAdmin. I find myself figuring out how to do things in MySql, but ultimately doing the same from the command line on a regular basis.

        I would also love to see how you can find an sql from say a php script that another has created, then modify and test it in phpMyAdmin, then use it in the command line so you can maybe run that sql in a cron job for a backup or an archive and delete.

        again, good tut, and I hope we see more from the admins point of view.

    • http://jamie@swimandsing.com Jamie

      Good point, but;

      The two examples given here are the best. If you don’t know what you are doing with MySql, you should be very careful with the command line. Even thought the purest db admin would say that you should use the command line, most of what you do can be done much more efficiently and safely via a tool like phpMyAdmin. For the web developer, there is no time to worry about learning everything about MySql via the command line.

      Going into more about MySql from the command line would have been far beyond the scope of this tut.

      If you are needing to use the command line for MySql as a database manager, you should be looking elsewhere.

      This is not a dis on the author of this tut. To the author, well done.

  • http://eviled.org Luis

    Instead “cd ~” you can go back to your home with “cd”. Try to find ~ on a spanish keyboard :)

  • http://tech.tomgoren.com Tom Goren

    Excellent article!

    However, you wrote:

    “”"
    If you find that the brief help given by the –help operator isn’t enough, you can read more detail with the man program:

    man mysqldump

    Which will tell you all about the “nano” program. Simple commands like “cd” may not have an entry in man.
    “”"

    Pretty sure you meant “man nano” in this context.

    Just my two cents :)

  • http://tech.tomgoren.com Tom Goren

    In addition tip no.4 could be simplified a bit, and also save an unnecessary usage of ‘cat’.

    Yours:

    cat original_dump.sql | sed s/Japheth/Japh/ > new_dump.sql

    Alternative:

    sed ‘s/Japheth/Japh/g’ original_dump.sql > new_dump.sql

    For the brave:

    sed -i ‘s/Japheth/Japh/g’ original_dump.sql

    Which will make the changes straight to the original with no ‘undo’ option (don’t forget to backup).

    In addition, a nice trick with sed text replacement, is that you can use almost any character instead of the slash to delimit your search and replace terms, thus occasionally saving the effort of escaping slashes in the term.

    Example:

    If you wanted to replace all instances of the following string:

    “/images/thumbs/example/abc.png”

    With this:

    “/graphics/small/abc.png”

    Then using slashes as the delimiter you would have to do the following:

    sed ‘s/\/images\/thumbs\/example\/abc.png/\/graphics\/small\/abc.png/g’

    Horrible of course, and there are even worse examples.

    Here is a better option, using a comma instead:

    sed ‘s,/images/thumbs/example/abc.png,/graphics/small/abc.png,g’

    Much nicer no?

  • Uno Jones

    are you on Ubuntu 10.04?

  • Daniel Rose

    In Mac OS X, you can drag’n'drop a file or folder into Terminal to insert the path to the file/folder. I don’t know if this is working on the other operating systems or command-line-software, too.

  • http://ds.laroouse.com esranull

    great tutorial thanks lot

  • http://swimandsing.com Jamie

    I am glad to see this kind of tut here now.

    One command I just learned is to find the sizes in a directory and the directory size
    du

    this is very useful for a web admin.

    I always use df but that only tells me the size of the drives.

  • http://swimandsing.com Jamie

    Using scp is much faster than ftp. When I am lazy ( most of the time ) I make the mistake of using my ftp application to transfer files. I can never remember the synax for scp and many other command line commands, so I just keep a text file of all of the commands that I use commonly. It is amazing how many command line commands that you can find just by Google.

    Set up an ssh key pair so you can just scp files without entering passwords. This is also very handy to make file transfers via a cron job. rsync is also super handy from the command line and the cron. I use rcync with my xserv via launchd ( pretty much the same as cron ). Most, if not all, Linux / Unix have rcync installed by default including Mac OS X.

    If you want to have some fun with others in your office or home with a Mac. Try a Google search for “fun with the terminal”. It is pretty funny to watch the response from someone reacting to: ssh to a users Mac then:
    osascript -e ‘say “I am sorry Micheal, I cannot do that” using “Zarvox”‘
    or crank the user volume
    osascript -e “set Volume 20″

  • http://blog.larsjung.de Lars

    good article to motivate people to start using the command line! it’s important to show the risk of “rm”, you did a great job here.

  • http://www.jsxtech.com Jaspal Singh

    Nice post for beginners, but I would like to see more admin commands.
    Thanks for sharing.

  • http://digitalcraftworks.com Ben Dunlap

    ‘Simple commands like “cd” may not have an entry in man’.

    Actually they usually do; they’re typically just folded into the manual page for the shell you’re using. On a modern linux system that will almost always be bash.

    So if you see this error:

    “No manual entry for cd”

    Try typing “man bash” and then searching the manual page for “cd”.

    The search, of course, is initiated by pressing ‘/’ (forward slash).

  • http://garotosopa.wordpress.com/ Diogo Galvão

    Just two cents, literally:

    You can usually go back to your home directory by just typing “cd”, you don’t need to specify ~.

    And to perform substituitions on the same file without redirecting the output you can specify -i to sed, that stands for in-place, like in “sed -i s/realy/really/g *.html”.

    wbr.

    • http://japh.com.au/ Japh
      Author

      Great points, thanks!

      The reason I didn’t demonstrate in-place substitution is because I prefer to do things non-destructively. If you do an in-place substitution and you stuffed it up, you have more work to do than if you redirected the output to a new file :)

  • aperson

    Yeah, that sure looks like nano’s man page to me. Oh, and you don’t need to cd ~, just cd will do.

  • http://www.aakashweb.com Aakash

    It is great ! But i am new to command lines. Don’t laugh at me! where to use these commands ? what software ?

    • http://japh.com.au/ Japh
      Author

      If you’re using a Mac or Linux these commands are to be run in the Terminal application.

      If you are on Windows, you cannot really use these commands directly, but you can connect to a remote server with the PuTTY application.

      I cover this a little in the “How do I get Command-line Access to my Web Host?” section of the article.

      Good luck! :)

      • http://www.aakashweb.com Aakash

        Its Great ! I am on Windows. Though i use FTP for transferring my files, linux commands will be effective for “zipping”, “extracting” and deleting some un-deletable files on my server.

        My web hoster asks me to use these commands. But i don’t know where ?

        You cleared me thank you!

  • alfredwesterveld

    Maybe you mention that this is for linux/unix (or cygwin) at the top(of your document).

  • http://www.canaydogan.net Can Aydoğan

    Great tut!. Thanks.

  • Anjum

    You can view detail list for files using “ls -la” to backup all your website u can use “tar -cvzf NameOfNewTarFile.tar.gz *” This will tar your file.

    Hope this also help :)

  • Jay

    This article is so timely. I’m using one of several FTP clients to download a HUGE website and every one of them choked (Transmit 4, Forklift, Filezilla), but SCP is the CHAMP!

    Thanks so much!!!

    • http://www.flickr.com/photos/lorenzhs nuk

      Depending on the remote machine’s CPU and your internet connection, you could make it even faster if you gzip it

  • http://www.flickr.com/photos/lorenzhs nuk

    In principle, a really great article and cool idea to get command line stuff to people who are afraid of it, but I stumbled across one little thing.
    Where you are doing
    $ find ./ | grep “\.\_.*”
    I’d rather do:
    $find -name “*._*”
    - should be faster than listing everything and piping it through grep.

    Also, a cool tip for anyone who’s a bit further into command-line stuff is to try zsh (Z SHell) instead of bash (Bourne Again SHell). I think it’s way more powerful, one of its greatest advantages being its superior completion and autocorrection, another its scripting abilities.

    • http://www.flickr.com/photos/lorenzhs nuk

      One more thing: according to man cp and man grep there is no difference between -r and -R – at least that’s on my system (Ubuntu karmic), but should be that way on any other system, too

    • outis

      This also reveals an error in the tutorial: the RE “\.\_.*” doesn’t match file names beginning with “._”, as the tutorial states; it matches files names with “._” at any point in the name. “^\._” would match file names beginning with “._”, but (as nuk writes) using find alone is simpler and faster.

      As for bulk processing, with find’s -exec option or the xargs command, you can apply arbitrary commands to the files find finds.

      # replace “foo” with “bar” in all C source & header files
      $ find . -name ‘*.[ch]‘ -a -exec sed -i s/foo/bar/ {} \;
      # find total size of all html files
      $ find . -name ‘*.html’ -a -exec ls -kl {} \; | awk -v total=0 ‘ { total += $5 } END { print total } ‘
      # archive C source & header files
      $ find . -name ‘*.[hc]‘ | xargs tar cyf src.tar.bz2

      find’s -delete lets you, well, delete found files:

      $ find . -name ‘._*’ -a -delete

  • http://www.adyngom.com Ady

    Very useful, the “man” is often overlooked but can come in really handt to get you up to speed, if you were to read on on one command a week you will find yourself building up on your confidence in no time. Feeling comfortable on the command line is a great asset for a serious developer ( front or back-end). The other topic that needs to be covered a little more in depth here is SVN, my vote for an extensive tut on that.

  • http://www.cbesslabs.com Bratu Sebastian

    Hell yea, I remember a few years ago in an afternoon I was with a friend in the metro station and talking about rm -rf and stuff, it was great, two fellow linux admins talking about how would one go about breaching a company server. :))

    You remembered me about that times, thank you !

    And @Jamie, about the quitting at work and rm -rf the server, it could be cooler to make this in a cron job, and happen automatically after 10 days, so nobody would know it was you :)

  • http://www.thenewnigeria.com Emeka

    This is very useful. Please can you possibly write more on this?

  • http://www.thenewnigeria.com Emeka

    Please how do i add my pix to my comment lines

  • http://www.sportbloging.info Sporter

    The point is to make sure that designers and client-side developers who don’t deal with this every day understand that there can be serious implications to running commands on the command line. Most commands that deal with file and folder manipulation, as well as administrative tasks, require you to run them as super user. When you do that, you are opening yourself up to the possibility that something can go very wrong. For those that can’t afford backup services, this can be a very disheartening experience. My advice is to think before you type, and think one more time for good measure.
    +1

  • DontCatToPipe

    any pipeline of the form

    cat somefile | foo

    is a pointless use of ‘cat’. If the next command in the pipeline is going to read from its stdin, just say

    foo < somefile

    It saves an entire fork-exec plus setting up file descriptors for the pipe.

  • http://www.magnusbonnevier.se Magnus Bonnevier

    Great Tutorial.

    I have been wanting to get a little more advanced when it comes to linux command line.

    And to all people suggestions that “it would be cool” to delete files on a companys server when they quit…. its rather sad that people would do that…. you should be ashamed of yourselfs.

    But i guess as long its not your server getting its files deleted it´s ok ? right.?

  • http://www.codeforest.net Codeforest

    Really great to see such nice collection of command line tips on one place.

  • rafakek

    great tutorial. I’m waiting for more.
    Thank you

  • http://gwr.co.nz Glen Robertson

    Awesome, tut.

    I also think that `locate` is a useful command to add here, alongside the `find ./ -iname filename` command you have mentioned. It is much faster because it uses a prebuilt file database, native command in Mac OSX as well.

    Cheers!

    • http://gwr.co.nz Glen Robertson

      - although `locate` is not always up to the minute, because the database it uses is built periodically.

  • w1sh

    What’s a good Win Terminal?

    • ricardo

      QVTerm and Putty will do the job.

  • http://wptricks.net WP Tricks

    Gunzip Tools is my favorite ;)

    Thanks

  • http://snackycracky.wordpress.com nils Petersohn

    mysql -u someone -p dbName < dbBackup.sql

  • cb24

    Nice post. Command lines are always better …:)

  • yetanothergeek

    > If you use the “rm” command with the “-f” switch, make sure
    > you know exactly what you’re going to be deleting, and that
    > you really want it gone! If you use “-f”, you won’t get a
    > second-chance.

    This is misleading.
    “make sure you know exactly what you’re going to be deleting”
    Period. Regardless of whether you use -f or not!

    You might also mention that cp, mv, rm commands all support the -i switch, which will cause them to prompt the user before doing anything destructive (such as removing or overwriting a file).

    Nice article, though.

  • http://codendesign.blogspot.com nXd

    It looks like when they talk about command line . They all think about linux :) . I think PowerShell in windows is a big step in command line enhancing from microsoft :)
    They’ve some commands like unix ( which map from it’s old command ) like ls, cp, …

  • http://exposedelements.com Mario

    i didn’t know about pressing the tab key twice to see a list of command options. thanks for the article, I love Linux!

  • http://edfuh.com ed

    sudo rm -rf /

  • jv

    Please more on this topic… yes, “man” is helpful but concrete examples help much more.

  • http://www.qualitystorefixtures.com John Store

    Command line seem so new to me,after reading your post it help clearing me ,thanks anyway

  • http://chr.ishenry.com Chris Henry

    As an addendum to your warning regarding the -f flag with rm: you may want to always pair the -f flag with the -v (verbose) flag. When developing on the command line, it’s easy enough to test bits of what you want to do, but it’s not always so easy to figure out what they actually do when you execute them. Since many times executing commands can be a leap of faith (you have a backup, right?), it’s helpful to know exactly what the damage is when you hit enter.

  • http://www.menozacmenopause.net menopause natural cure

    I used to think that using command line was difficult, but your post makes it look like a piece of cake.!

    love this post

    Thanks a lot!

  • http://butenas.com Ignas

    Simple commands, all are well know. But for the beginners should work. Terminal is the most usable application together with web browser.