background preloader

Bash/Shell Resources/CLI

Facebook Twitter

15 Linux Bash History Expansion Examples You Should Know - Nightly (Build 20110507043313) Bash history is very powerful.

15 Linux Bash History Expansion Examples You Should Know - Nightly (Build 20110507043313)

Understanding how to effectively use the bash history expansions will make you extremely productive on the Linux command line. This article explains 15 examples that uses the following bash history expansion features: Event designators – Refers to a particular command in the history. It starts with a ! Word designators – Refers to a particular word of a history entry. This article is part of our on-going Bash Tutorial Series. As you already know, to view all the history entries, use the history command. . $ history 1 tar cvf etc.tar /etc/ 2 cp /etc/passwd /backup 3 ps -ef | grep http 4 service sshd restart 5 /usr/local/apache2/bin/apachectl restart Bash History Event Designators 1. If you’ve executed a command earlier, instead of re-typing it again, you can quickly execute it by using the corresponding number of the command in the history.

For example, to execute command #4, do the following. . $ ! To execute the previous command, do any one of the following: 6 Examples to Backup Linux Using dd Command (Including Disk to Disk) - Nightly (Build 20110507043313) Data loss will be costly.

6 Examples to Backup Linux Using dd Command (Including Disk to Disk) - Nightly (Build 20110507043313)

At the very least, critical data loss will have a financial impact on companies of all sizes. In some cases, it can cost your job. I’ve seen cases where sysadmins learned this in the hard way. There are several ways to backup a Linux system, including rsync and rsnapshot that we discussed a while back. This article provides 6 practical examples on using dd command to backup the Linux system. dd is a powerful UNIX utility, which is used by the Linux kernel makefiles to make boot images. Warning: While using dd command, if you are not careful, and if you don’t know what you are doing, you will lose your data! Example 1. To backup an entire copy of a hard disk to another hard disk connected to the same system, execute the dd command as shown below. 15 Useful Bash Shell Built-in Commands (With Examples) - Nightly (Build 20110507043313) Bash has several commands that comes with the shell (i.e built inside the bash shell).

15 Useful Bash Shell Built-in Commands (With Examples) - Nightly (Build 20110507043313)

When you execute a built-in command, bash shell executes it immediately, without invoking any other program. Bash shell built-in commands are faster than external commands, because external commands usually fork a process to execute it. In this article let us review some useful bash shell builtins with examples. 1. Bash Export Command Example export command is used to export a variable or function to the environment of all the child processes running in the current shell. export varname=value.

Linux: What are some time-saving tips that every Unix user should know? - Quora - StumbleUpon - Nightly (Build 20110507043313) Fail2ban - Nightly (Build 20110507043313)

Text Editors

Function Provide Modular Options in Bash. Functions A function can help you modularize your script.

Function Provide Modular Options in Bash

Because the function is executed in the context of the same shell, it does not create a new child process, this makes functions faster as they access the information in RAM. This also will save on resources as you use functions. Functions are a script within a script which can be defined by the user and stored in memory, allowing you to reuse the function repeatedly. How to: Change / Setup bash custom prompt (PS1) Tip: Prompt magic. Enhancing the system prompt As Linux/UNIX people, we spend a lot of time working in the shell, and in many cases, this is what we have staring back at us: If you happen to be root, you're entitled to the "prestige" version of this beautiful prompt: These prompts are not exactly pretty.

Tip: Prompt magic

It's no wonder that several Linux distributions have upgraded their default prompts that add color and additional information to boot. However, even if you happen to have a modern distribution that comes with a nice, colorful prompt, it may not be perfect. Prompt basics Under bash, you can set your prompt by changing the value of the PS1 environment variable, as follows: Changes take effect immediately, and can be made permanent by placing the "export" definition in your ~/.bashrc file.

While this is, um, interesting, it's not exactly useful to have a prompt that contains lots of static text. So, there you have all of bash's special backslashed escape sequences. Colorization Color chart View image at full size. Howto: Linux write (burn) data to DVD or DVD/RW. In order to write DVD/DVD-RW from shell prompt you need to install a package called dvd+rw-tools.

Howto: Linux write (burn) data to DVD or DVD/RW

DVD is another good option for backup, archiving, data exchange etc. You can install dvd+rw-tools with following commands. Also note that this package works under *BSD, HP-UX, Solaris and other UNIX like operating systems. Learning the shell - Lesson 6: I/O Redirection. In this lesson, we will explore a powerful feature used by many command line programs called input/output redirection.

Learning the shell - Lesson 6: I/O Redirection

As we have seen, many commands such as ls print their output on the display. This does not have to be the case, however. By using some special notation we can redirect the output of many commands to files, devices, and even to the input of other commands. Standard Output Most command line programs that display their results do so by sending their results to a facility called standard output. [me@linuxbox me]$ ls > file_list.txt In this example, the ls command is executed and the results are written in a file named file_list.txt. Each time the command above is repeated, file_list.txt is overwritten (from the beginning) with the output of the command ls. [me@linuxbox me]$ ls >> file_list.txt When the results are appended, the new results are added to the end of the file, thus making the file longer each time the command is repeated. Standard Input Pipes Filters.

[shell-fu:top25. Linux Commands - A practical reference. Linux Shell Scripting Tutorial - A Beginner's handbook.