Home Home > 2014 > 07 > 08 > Command Line Tuesdays – Part Four
Sign up | Login

Command Line Tuesdays – Part Four

July 8th, 2014 by

Heya there geekos! New week, new adventure!

Today, we’ll learn how to manipulate files using four fairly simple commands. So let’s begin!

Before we start with the commands themselves, let’s take a quick stop at a section called…

…wildcards:

Copying, pasting files, creating directories etc. is probably easier using graphical tools, but, if you’d like to perform more complicated tasks, like copying only .html files from one folder to another, and only copying files that don’t exist in the destination directory, CLI just might come in handy. So, to get back to wildcards, it’s basically a shell feature, a set of special characters, that helps you pick out a set of files based on some simple rules (which characters appear in a file name, how many characters, upper/lower case characters etc.). Here’s the table (click to enlarge):

Screenshot - 08. 07. 2014 - 12:59:46And here are a few examples mr Shotts posted in a table of usage also click to enlarge: Screenshot - 08. 07. 2014 - 12:59:59If you use a command with an argument containing a filename, you can use wildcards with no problem.

cp

cp is used to copy files or directories. You can use it pretty easily: navigate to the folder you’d like to copy the files from and to, and simply do

cp file1 file2 – to copy single files,

or

cp file1 file2 … directory – to copy files from your current working directory to the directory specified. Here’s mr Shotts’ table with numerous options:

Screenshot - 08. 07. 2014 - 13:42:48

mv

mv is the second command of the day. We can use mv to rename a file or directory, or to move a file or directory. We can use it this way:

mv filename1 filename2 – if we want to rename filename1 to filename2

or

mv file directory – if we want to move file to directory.

Here’s a table of few examples of mv with options used with it:

Screenshot - 08. 07. 2014 - 13:35:15rm

The rm command removes/deletes files and directories. Usage is pretty straightforward:

rm file

or

rm -r directory

And here’s also a table with some additional options:

Screenshot - 08. 07. 2014 - 13:35:29But, do be careful when using rm as there is no undelete option, so be extra careful not to inflict unwanted damage to your system!

mkdir

mkdir is used for creating directories. It’s the most simple command of the day. Simply:

mkdir directory

Voila, directory created!

So this is it for this week, geekos. Hope to see you next tuesday! All the best and kind regards,

Both comments and pings are currently closed.

6 Responses to “Command Line Tuesdays – Part Four”

  1. In the mkdir command you could show the -p option that is very useful to create subdirectories at once.

    Anyway congratulations for the initiative.

    • jetchisel

      There is an alias for that in openSUSE, run

      type -a md

      will give you the result

      md is aliased to `mkdir -p’

      Then you can just run

      md /tmp/foo/bar/baz/more

      :-)

  2. One thing you could also have mentioned is that generally `command –help` gives a summary of options, and `man command` gives a larger overview of what the options do. There’s also `info command`, but I don’t really know why it exists, since it’s pretty similar to `man command`, just works for fewer commands…

    • Nenad Latinović

      Hey. Thanks again. Will add it (probably in the beginning of the next issue, as it is important, so people don’t skip it…)

  3. Thanks!
    Some wildcards were new to me :)

  4. Paul Parker

    Am a NON-Technical openSUSE user ;-)

    IMHO tutorial best not stray from useful towards dangerous for new and NOT so technical users !

    INTRODUCTION to terminal usage is to encourage users into using terminal commands more.

    IMHO best with simple commands easily learnt to build confidence, so later can be more adventurous.

    Exception is follow up discussion here as useful start for more adventurous options :-)