background preloader

Commands Bash and Scripts

Facebook Twitter

BASH Programming - Introduction HOW-TO: Variables. NextPreviousContents 5.

BASH Programming - Introduction HOW-TO: Variables

Variables You can use variables as in any programming languages. There are no data types. A variable in bash can contain a number, a character, a string of characters. You have no need to declare a variable, just assigning a value to its reference will create it. 5.1 Sample: Hello World! #! Line 2 creates a variable called STR and assigns the string "Hello World! " 5.2 Sample: A very simple backup script (little bit better) #!

HowTo: Save A File In Vim / Vi Without Root Permission. This happens lot of times.

HowTo: Save A File In Vim / Vi Without Root Permission

I login as a normal user and start to edit httpd.conf or lighttpd.conf or named.conf in vim / vi text editor. However, I'm not able to save changes due to permission issue (all config files are owned by root). How do I save file without creating a temporary file (/tmp/httpd.conf) and then move the same (mv /tmp/httpd.conf /etc/httpd) as root using vim / vi itself?

You can use the combination of tee and sudo command (assuming that sudo is configured for your account) to save a file without creating a third file in /tmp. Command Line Magic: Scripting, Part One. Creating shell scripts is the lazy (smart) system administrator's way to automate and build intelligence into repetitive tasks.

Command Line Magic: Scripting, Part One

This scripting miniseries will help you learn some basic scripting and perhaps launch you on a more productive career in Linux system administration. If you find yourself typing the same commands over and over again, do yourself a favor and write a script to do it. Smart administrators have scripts for everything. There are three things you have to remember about scripting: Don’t test your scripts on production systems, document the script’s action, and name the script descriptively. Scripting, Part Two: Looping for Fun and Profit. Crafty System Administrators who want to conserve energy need to learn the fine art of looping.

Scripting, Part Two: Looping for Fun and Profit

You energy-conserving* system administrators will enjoy learning to use loops in your scripts. Looping is a technique that allows you to repeat a process or set of commands indefintely or until the loop exhausts a particular list of items. For example, you want to copy a particular file to everyone’s home directory. How do you do it? Don’t say that you have a junior-level administrator do it. Don’t worry if you aren’t a scripting master, I’m going to take it slow through this series so that you can absorb what’s going on.

The Basics You need access to a Linux system and last week’s post, “Scripting, Part One”. The Lively Loop There’s nothing particularly special about a loop. Shell Script Check If Directory Exists - Folder - Linux - BASH - tutorial. Time-Saving Tricks on the Command Line. I remember the first time a friend of mine introduced me to Linux and showed me how I didn't need to type commands and path names fully—I could just start typing and use the Tab key to complete the rest.

Time-Saving Tricks on the Command Line

That was so cool. I think everybody loves Tab completion because it's something you use pretty much every minute you spend in the shell. Over time, I discovered many more shortcuts and time-saving tricks, many of which I have come to use almost as frequently as Tab completion. In this article, I highlight a set of tricks for common situations that make a huge difference for me: Working in screen sessions: core features that will get you a long way. While reading the article, it would be best to have a terminal window open so you can try using the tips right away. Working in Screen Sessions Screen has been covered in Linux Journal before (see Resources), but to put it simply, screen lets you have multiple "windows" within a single terminal application. Editing the configuration file. Linux - Why do you need to put #!/bin/bash at the beginning of a script file. Chmod Linux and UNIX command tutorial.

The chmod command set the permission to the file which will permit only the certain user to view the file.Chmod utility simply changes the way in which a file can be accessed by the owner of the file. the group to which the file belongs, and/or all other users.

Chmod Linux and UNIX command tutorial

Only the owner of a file or the superuser can change the permission of the file. Format chmod[option] who[operation][permission] file-list chmod[options] mode-file-list Arguments Arguments give chmod information about which file are to have their modes changed in what ways. Symbolic Before moving into command list chmod changes the permission for certain class of users field by who. Operation to be performed is defined by the following list The Access permission is defined by the following list Sticky bit is an access permission bit that cause an executable program to remain on the swap area of the disk.

Some chmod modes Chmod example: “-rw-rw-r–” shows us the permission.