Tag: echo

By Rand Whitehall

damn small linuxIf you want to move a file from one place to another, use the mv, or move command. Now, the mv tool can send a file from one directory to another, but it also can rename a file. If you simply want to change the name of a file, say, from joo.txt to joe.txt, you can do that with mv also. Here are a few examples to get you going.

mv joe joe1

The file joe is simply renamed joe1

mv joe /Documents/joe

The file joe is moved to the Documents directory.

Now, what if we wanted to move joe.txt to the Documents directory and at the same time rename it to joe2?

mv joe Documents/joe2

This would move the file joe to the Documents directory and would change the name to joe2. This is similar to cp, but the original file is changed. With cp we get a new file and the original file is unchanged.

If you’d like to see the contents of a file, use the cat command. cat stands for concatenate. cat will display the contents of a file and also join, or concatenate several files.

cat joe

This command will output the contents of joe.

What if you’d like to view the contents of two or more files?

cat joe bob

Will output the contents of joe and then bob.

Ok. Now let’s play around with cat and two new commands: touch and echo.

Do this:

touch jj.txt

Which will create new text file called jj.txt.

echo “Hi there” >> jj.txt

This adds the text “Hi there!” to jj.txt.

You can append some more text to the end of jj.txt with another echo command and two greater than signs “>>” like this:

echo “How are you?” >> jj.txt

Now take a look at the contents of jj.txt via:

cat jj.txt

One thing to know when using cat, if you use only one greater than sign “>”, it will overwrite the contents of the file. Be careful!

Let’s overwrite jj.txt on purpose.

echo “See you later.” > jj.txt

Now view the contents via cat:

cat jj.txt

… and you should see only the “See you later.” line.

I hope this helped you become a little more familiar with the Linux command line. Have fun and experiment. Remember, while playing around, it’s best to create a new directory and make new files specifically to experiment with so you don’t lose any important data. Soon you’ll be using the command line like a pro!

Rand writes about web design, men’s health and latex free nitrile gloves. Please check out his new website all about Blue Nitrile Exam Gloves for info and nitrile glove knowhow! Rand’s other writings can be found here: Rand Whitehall.

Tags: , , , , ,

The Complete Steps to Create and Run a Linux Script to Run Linux Commands
By Clyde E. Boom

Creating and running a Linux script to automatically run a series of Linux commands that you commonly run is easy!

With a Linux script, you put a series of routinely run commands in a text file, and then run all of them by simply typing in the name of the file and pressing Enter.

Linux Script Example to Create a Script to Automatically Run A Series of Linux System Administration Commands2455513753_282aa586b7

Follow along with the steps in the example below to create and run your first Linux script!

1. Run a Linux text editor.

2. Put the following text at the top left of the text file (indented below for emphasis):

#!/bin/bash

This indicates that the text file is a Linux script file.

Press Enter twice to have a blank line below the line above.

3. Put the Linux command(s) in the script file.

The Linux commands below are used to provide an example. You can put any commands in a script.

The Linux commands below will: clear the screen, change into the /etc directory path, and then show the current path with the Linux pwd (path to working directory) command.

Then provide a long list of the fstab file (to show you that it’s there) and then change into your home directory (represented by the ~ symbol) and then show the path of the current directory.

The Linux echo command is not required, but has been put in the file to show the progress of the execution of the script.

Also, you don’t need to indent the commands below in the Linux script – they are just indented here for emphasis.

clear
echo The screen has been cleared

cd /etc

pwd

echo This is the etc directory

ls -l fstab

echo This is a long listing of the fstab file

cd ~

pwd echo Now in my home directory

Linux Commands Training Tips: A Linux script can contain hundreds of lines of text if necessary – and also include complex programming logic, such as if . . . then statements.

4. Save the text / script file with a meaningful name to create it and by give it a name.

For example, if you want to list files in a few directories, call the file: listdirs

5. Run the Linux chmod command to change the permissions of the file and make the Linux text file “executable”.

In our example, the file is named: listdirs

Below is a Linux chmod command example for running the chmod command to change the permissions of the Linux script file – and to make the listdirs text / script file “executable”, so that you can run the script file in the same way as you run a command.

The $ (dollar sign) below is the Linux command line prompt. Don’t type in the $ (dolar sign), type in the command that appears at the right of the $ prompt.

$ chmod u+x listdirs

The Linux command above is chmod and it is being used to assign the x (executable) permission to the u (user) of the file with: u+x and the script file name is listdirs.

Running a Linux Script to Run System Administration Commands

To run a Linux script (that is in the “current” directory), such as the listdirs script, simply type in a period (dot) and a space and then the name of the file and press Enter.

$ . listdirs

The concepts and Linux command examples shown above work in Red Hat, Ubuntu, Fedora, Slackware, and Debian Linux – and also ALL Linux distributions.

By the way…do you want to learn exactly how to use Linux and run Linux commands for Linux System Administration and get real, practical Linux training experience by running hundreds of examples of Linux commands?

Just click to download my free new Linux commands training course book and Linux audio podcast (.mp3) files here: Linux Commands Training Mini-Course

Clyde Boom says “Learn how to use Linux commands with easy, self-paced Linux training materials that show you how to run hundreds of examples of the essential Linux System Administration commands – and get that new and better job, promotion, raise – or keep your current job!”

You can get your instant access to my free Linux commands training course at:
http://www.LinuxCommandsTrainingCourse.com

Tags: , , , , , , , ,
Back to top